Apply Eclipse Mars' code formatting

This commit is contained in:
Andy Wilkinson
2016-02-12 20:57:53 +00:00
parent 811e7adf70
commit 74f9e272fd
92 changed files with 1446 additions and 1294 deletions

View File

@@ -18,4 +18,3 @@
* Classes for configuring Spring REST Docs.
*/
package org.springframework.restdocs.config;

View File

@@ -56,7 +56,8 @@ public class ConstraintDescriptions {
* @param constraintResolver the constraint resolver
*/
public ConstraintDescriptions(Class<?> clazz, ConstraintResolver constraintResolver) {
this(clazz, constraintResolver, new ResourceBundleConstraintDescriptionResolver());
this(clazz, constraintResolver,
new ResourceBundleConstraintDescriptionResolver());
}
/**
@@ -95,8 +96,8 @@ public class ConstraintDescriptions {
* @return the list of constraint descriptions
*/
public List<String> descriptionsForProperty(String property) {
List<Constraint> constraints = this.constraintResolver.resolveForProperty(
property, this.clazz);
List<Constraint> constraints = this.constraintResolver
.resolveForProperty(property, this.clazz);
List<String> descriptions = new ArrayList<>();
for (Constraint constraint : constraints) {
descriptions.add(this.descriptionResolver.resolveDescription(constraint));

View File

@@ -64,8 +64,8 @@ import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
*
* @author Andy Wilkinson
*/
public class ResourceBundleConstraintDescriptionResolver implements
ConstraintDescriptionResolver {
public class ResourceBundleConstraintDescriptionResolver
implements ConstraintDescriptionResolver {
private final PropertyPlaceholderHelper propertyPlaceholderHelper = new PropertyPlaceholderHelper(
"${", "}");
@@ -99,8 +99,8 @@ public class ResourceBundleConstraintDescriptionResolver implements
try {
return ResourceBundle.getBundle(
ResourceBundleConstraintDescriptionResolver.class.getPackage()
.getName() + "." + name, Locale.getDefault(), Thread
.currentThread().getContextClassLoader());
.getName() + "." + name,
Locale.getDefault(), Thread.currentThread().getContextClassLoader());
}
catch (MissingResourceException ex) {
return null;
@@ -126,8 +126,8 @@ public class ResourceBundleConstraintDescriptionResolver implements
return this.defaultDescriptions.getString(key);
}
private static final class ConstraintPlaceholderResolver implements
PlaceholderResolver {
private static final class ConstraintPlaceholderResolver
implements PlaceholderResolver {
private final Constraint constraint;

View File

@@ -70,10 +70,9 @@ public class ValidatorConstraintResolver implements ConstraintResolver {
if (propertyDescriptor != null) {
for (ConstraintDescriptor<?> constraintDescriptor : propertyDescriptor
.getConstraintDescriptors()) {
constraints
.add(new Constraint(constraintDescriptor.getAnnotation()
.annotationType().getName(), constraintDescriptor
.getAttributes()));
constraints.add(new Constraint(
constraintDescriptor.getAnnotation().annotationType().getName(),
constraintDescriptor.getAttributes()));
}
}
return constraints;

View File

@@ -18,4 +18,3 @@
* Documenting a RESTful API's constraints.
*/
package org.springframework.restdocs.constraints;

View File

@@ -48,6 +48,7 @@ import org.springframework.util.StringUtils;
public class CurlRequestSnippet extends TemplatedSnippet {
private static final Set<HeaderFilter> HEADER_FILTERS;
static {
Set<HeaderFilter> headerFilters = new HashSet<>();
headerFilters.add(new NamedHeaderFilter(HttpHeaders.HOST));
@@ -102,7 +103,8 @@ public class CurlRequestSnippet extends TemplatedSnippet {
writer.print("-i");
}
private void writeUserOptionIfNecessary(OperationRequest request, PrintWriter writer) {
private void writeUserOptionIfNecessary(OperationRequest request,
PrintWriter writer) {
List<String> headerValue = request.getHeaders().get(HttpHeaders.AUTHORIZATION);
if (BasicAuthHeaderFilter.isBasicAuthHeader(headerValue)) {
String credentials = BasicAuthHeaderFilter.decodeBasicAuthHeader(headerValue);
@@ -110,7 +112,8 @@ public class CurlRequestSnippet extends TemplatedSnippet {
}
}
private void writeHttpMethodIfNecessary(OperationRequest request, PrintWriter writer) {
private void writeHttpMethodIfNecessary(OperationRequest request,
PrintWriter writer) {
if (!HttpMethod.GET.equals(request.getMethod())) {
writer.print(String.format(" -X %s", request.getMethod()));
}
@@ -145,8 +148,8 @@ public class CurlRequestSnippet extends TemplatedSnippet {
writer.printf("@%s", part.getSubmittedFileName());
}
if (part.getHeaders().getContentType() != null) {
writer.append(";type=").append(
part.getHeaders().getContentType().toString());
writer.append(";type=")
.append(part.getHeaders().getContentType().toString());
}
writer.append("'");
@@ -170,7 +173,8 @@ public class CurlRequestSnippet extends TemplatedSnippet {
}
}
private void writeContentUsingParameters(OperationRequest request, PrintWriter writer) {
private void writeContentUsingParameters(OperationRequest request,
PrintWriter writer) {
Parameters uniqueParameters = getUniqueParameters(request);
String queryString = uniqueParameters.toQueryString();
if (StringUtils.hasText(queryString)) {

View File

@@ -64,8 +64,8 @@ public class QueryStringParser {
parameters.add(decode(name), decode(value));
}
else {
throw new IllegalArgumentException("The parameter '" + parameter
+ "' is malformed");
throw new IllegalArgumentException(
"The parameter '" + parameter + "' is malformed");
}
}
@@ -74,8 +74,8 @@ public class QueryStringParser {
return URLDecoder.decode(encoded, "UTF-8");
}
catch (UnsupportedEncodingException ex) {
throw new IllegalStateException("Unable to URL encode " + encoded
+ " using UTF-8", ex);
throw new IllegalStateException(
"Unable to URL encode " + encoded + " using UTF-8", ex);
}
}

View File

@@ -18,4 +18,3 @@
* Documenting the curl command required to make a request to a RESTful API.
*/
package org.springframework.restdocs.curl;

View File

@@ -66,12 +66,9 @@ public class HttpRequestSnippet extends TemplatedSnippet {
protected Map<String, Object> createModel(Operation operation) {
Map<String, Object> model = new HashMap<>();
model.put("method", operation.getRequest().getMethod());
model.put(
"path",
operation.getRequest().getUri().getRawPath()
+ (StringUtils.hasText(operation.getRequest().getUri()
.getRawQuery()) ? "?"
+ operation.getRequest().getUri().getRawQuery() : ""));
model.put("path", operation.getRequest().getUri().getRawPath()
+ (StringUtils.hasText(operation.getRequest().getUri().getRawQuery())
? "?" + operation.getRequest().getUri().getRawQuery() : ""));
model.put("headers", getHeaders(operation.getRequest()));
model.put("requestBody", getRequestBody(operation.getRequest()));
return model;
@@ -149,8 +146,8 @@ public class HttpRequestSnippet extends TemplatedSnippet {
}
private void writePart(OperationRequestPart part, PrintWriter writer) {
writePart(part.getName(), part.getContentAsString(), part.getHeaders()
.getContentType(), writer);
writePart(part.getName(), part.getContentAsString(),
part.getHeaders().getContentType(), writer);
}
private void writePart(String name, String value, MediaType contentType,

View File

@@ -19,4 +19,3 @@
* returned.
*/
package org.springframework.restdocs.http;

View File

@@ -20,10 +20,10 @@ import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.springframework.restdocs.operation.OperationResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.restdocs.operation.OperationResponse;
/**
* Abstract base class for a {@link LinkExtractor} that extracts links from JSON.
*
@@ -37,8 +37,8 @@ abstract class AbstractJsonLinkExtractor implements LinkExtractor {
@SuppressWarnings("unchecked")
public Map<String, List<Link>> extractLinks(OperationResponse response)
throws IOException {
Map<String, Object> jsonContent = this.objectMapper.readValue(
response.getContent(), Map.class);
Map<String, Object> jsonContent = this.objectMapper
.readValue(response.getContent(), Map.class);
return extractLinks(jsonContent);
}

View File

@@ -170,7 +170,7 @@ public abstract class HypermediaDocumentation {
* "href": "http://example.com/foo"
* }
* ]
* }
* }
* </pre>
*
* @return The extractor for Atom-style links

View File

@@ -88,8 +88,8 @@ public class Link {
@Override
public String toString() {
return new ToStringCreator(this).append("rel", this.rel)
.append("href", this.href).toString();
return new ToStringCreator(this).append("rel", this.rel).append("href", this.href)
.toString();
}
}

View File

@@ -56,7 +56,8 @@ public class LinksSnippet extends TemplatedSnippet {
* @param linkExtractor the link extractor
* @param descriptors the link descriptors
*/
protected LinksSnippet(LinkExtractor linkExtractor, List<LinkDescriptor> descriptors) {
protected LinksSnippet(LinkExtractor linkExtractor,
List<LinkDescriptor> descriptors) {
this(linkExtractor, descriptors, null);
}
@@ -76,9 +77,10 @@ public class LinksSnippet extends TemplatedSnippet {
for (LinkDescriptor descriptor : descriptors) {
Assert.notNull(descriptor.getRel(), "Link descriptors must have a rel");
if (!descriptor.isIgnored()) {
Assert.notNull(descriptor.getDescription(), "The descriptor for link '"
+ descriptor.getRel() + "' must either have a description or be"
+ " marked as " + "ignored");
Assert.notNull(descriptor.getDescription(),
"The descriptor for link '" + descriptor.getRel()
+ "' must either have a description or be" + " marked as "
+ "ignored");
}
this.descriptorsByRel.put(descriptor.getRel(), descriptor);
}

View File

@@ -18,4 +18,3 @@
* Documenting a RESTful API that uses hypermedia.
*/
package org.springframework.restdocs.hypermedia;

View File

@@ -49,8 +49,8 @@ abstract class AbstractOperationMessage {
public String getContentAsString() {
if (this.content.length > 0) {
Charset charset = extractCharsetFromContentTypeHeader();
return charset != null ? new String(this.content, charset) : new String(
this.content);
return charset != null ? new String(this.content, charset)
: new String(this.content);
}
return "";
}

View File

@@ -45,8 +45,8 @@ public class OperationRequestFactory {
public OperationRequest create(URI uri, HttpMethod method, byte[] content,
HttpHeaders headers, Parameters parameters,
Collection<OperationRequestPart> parts) {
return new StandardOperationRequest(uri, method, content, augmentHeaders(headers,
uri, content), parameters, parts);
return new StandardOperationRequest(uri, method, content,
augmentHeaders(headers, uri, content), parameters, parts);
}
/**
@@ -74,7 +74,8 @@ public class OperationRequestFactory {
*
* @return The new request with the new content
*/
public OperationRequest createFrom(OperationRequest original, HttpHeaders newHeaders) {
public OperationRequest createFrom(OperationRequest original,
HttpHeaders newHeaders) {
return new StandardOperationRequest(original.getUri(), original.getMethod(),
original.getContent(), newHeaders, original.getParameters(),
original.getParts());
@@ -89,8 +90,8 @@ public class OperationRequestFactory {
private HttpHeaders getUpdatedHeaders(HttpHeaders originalHeaders,
byte[] updatedContent) {
return new HttpHeadersHelper(originalHeaders).updateContentLengthHeaderIfPresent(
updatedContent).getHeaders();
return new HttpHeadersHelper(originalHeaders)
.updateContentLengthHeaderIfPresent(updatedContent).getHeaders();
}
}

View File

@@ -36,7 +36,8 @@ public class OperationResponseFactory {
* @param content the content of the request
* @return the {@code OperationResponse}
*/
public OperationResponse create(HttpStatus status, HttpHeaders headers, byte[] content) {
public OperationResponse create(HttpStatus status, HttpHeaders headers,
byte[] content) {
return new StandardOperationResponse(status, augmentHeaders(headers, content),
content);
}
@@ -53,8 +54,8 @@ public class OperationResponseFactory {
* @return The new response with the new content
*/
public OperationResponse createFrom(OperationResponse original, byte[] newContent) {
return new StandardOperationResponse(original.getStatus(), getUpdatedHeaders(
original.getHeaders(), newContent), newContent);
return new StandardOperationResponse(original.getStatus(),
getUpdatedHeaders(original.getHeaders(), newContent), newContent);
}
/**
@@ -66,7 +67,8 @@ public class OperationResponseFactory {
*
* @return The new response with the new headers
*/
public OperationResponse createFrom(OperationResponse original, HttpHeaders newHeaders) {
public OperationResponse createFrom(OperationResponse original,
HttpHeaders newHeaders) {
return new StandardOperationResponse(original.getStatus(), newHeaders,
original.getContent());
}
@@ -78,8 +80,8 @@ public class OperationResponseFactory {
private HttpHeaders getUpdatedHeaders(HttpHeaders originalHeaders,
byte[] updatedContent) {
return new HttpHeadersHelper(originalHeaders).updateContentLengthHeaderIfPresent(
updatedContent).getHeaders();
return new HttpHeadersHelper(originalHeaders)
.updateContentLengthHeaderIfPresent(updatedContent).getHeaders();
}
}

View File

@@ -28,8 +28,8 @@ import org.springframework.http.HttpMethod;
*
* @author Andy Wilkinson
*/
class StandardOperationRequest extends AbstractOperationMessage implements
OperationRequest {
class StandardOperationRequest extends AbstractOperationMessage
implements OperationRequest {
private HttpMethod method;

View File

@@ -23,8 +23,8 @@ import org.springframework.http.HttpHeaders;
*
* @author Andy Wilkinson
*/
class StandardOperationRequestPart extends AbstractOperationMessage implements
OperationRequestPart {
class StandardOperationRequestPart extends AbstractOperationMessage
implements OperationRequestPart {
private final String name;

View File

@@ -24,8 +24,8 @@ import org.springframework.http.HttpStatus;
*
* @author Andy Wilkinson
*/
class StandardOperationResponse extends AbstractOperationMessage implements
OperationResponse {
class StandardOperationResponse extends AbstractOperationMessage
implements OperationResponse {
private final HttpStatus status;

View File

@@ -15,8 +15,7 @@
*/
/**
* Operation API that describes a request that was sent and the response that was
* received when calling a RESTful API.
* Operation API that describes a request that was sent and the response that was received
* when calling a RESTful API.
*/
package org.springframework.restdocs.operation;

View File

@@ -54,8 +54,8 @@ public class ContentModifyingOperationPreprocessor implements OperationPreproces
@Override
public OperationResponse preprocess(OperationResponse response) {
byte[] modifiedContent = this.contentModifier.modifyContent(
response.getContent(), response.getHeaders().getContentType());
byte[] modifiedContent = this.contentModifier.modifyContent(response.getContent(),
response.getHeaders().getContentType());
return this.responseFactory.createFrom(response, modifiedContent);
}

View File

@@ -29,8 +29,8 @@ class LinkMaskingContentModifier implements ContentModifier {
private static final String DEFAULT_MASK = "...";
private static final Pattern LINK_HREF = Pattern.compile(
"\"href\"\\s*:\\s*\"(.*?)\"", Pattern.DOTALL);
private static final Pattern LINK_HREF = Pattern.compile("\"href\"\\s*:\\s*\"(.*?)\"",
Pattern.DOTALL);
private final ContentModifier contentModifier;

View File

@@ -90,7 +90,8 @@ public final class Preprocessors {
* @return the preprocessor
*/
public static OperationPreprocessor maskLinks() {
return new ContentModifyingOperationPreprocessor(new LinkMaskingContentModifier());
return new ContentModifyingOperationPreprocessor(
new LinkMaskingContentModifier());
}
/**
@@ -101,8 +102,8 @@ public final class Preprocessors {
* @return the preprocessor
*/
public static OperationPreprocessor maskLinks(String mask) {
return new ContentModifyingOperationPreprocessor(new LinkMaskingContentModifier(
mask));
return new ContentModifyingOperationPreprocessor(
new LinkMaskingContentModifier(mask));
}
/**
@@ -114,7 +115,8 @@ public final class Preprocessors {
* @param replacement the replacement
* @return the preprocessor
*/
public static OperationPreprocessor replacePattern(Pattern pattern, String replacement) {
public static OperationPreprocessor replacePattern(Pattern pattern,
String replacement) {
return new ContentModifyingOperationPreprocessor(
new PatternReplacingContentModifier(pattern, replacement));
}

View File

@@ -34,15 +34,15 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import org.springframework.http.MediaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.http.MediaType;
/**
* A {@link ContentModifier} that modifies the content by pretty printing it.
@@ -52,8 +52,8 @@ import com.fasterxml.jackson.databind.SerializationFeature;
public class PrettyPrintingContentModifier implements ContentModifier {
private static final List<PrettyPrinter> PRETTY_PRINTERS = Collections
.unmodifiableList(Arrays.asList(new JsonPrettyPrinter(),
new XmlPrettyPrinter()));
.unmodifiableList(
Arrays.asList(new JsonPrettyPrinter(), new XmlPrettyPrinter()));
@Override
public byte[] modifyContent(byte[] originalContent, MediaType contentType) {
@@ -98,8 +98,8 @@ public class PrettyPrintingContentModifier implements ContentModifier {
SAXParser parser = parserFactory.newSAXParser();
XMLReader xmlReader = parser.getXMLReader();
xmlReader.setErrorHandler(new SilentErrorHandler());
return new SAXSource(xmlReader, new InputSource(new ByteArrayInputStream(
original)));
return new SAXSource(xmlReader,
new InputSource(new ByteArrayInputStream(original)));
}
private static final class SilentErrorListener implements ErrorListener {
@@ -111,7 +111,8 @@ public class PrettyPrintingContentModifier implements ContentModifier {
}
@Override
public void error(TransformerException exception) throws TransformerException {
public void error(TransformerException exception)
throws TransformerException {
// Suppress
}
@@ -146,8 +147,8 @@ public class PrettyPrintingContentModifier implements ContentModifier {
@Override
public String prettyPrint(byte[] original) throws IOException {
ObjectMapper objectMapper = new ObjectMapper().configure(
SerializationFeature.INDENT_OUTPUT, true);
ObjectMapper objectMapper = new ObjectMapper()
.configure(SerializationFeature.INDENT_OUTPUT, true);
return objectMapper.writeValueAsString(objectMapper.readTree(original));
}
}

View File

@@ -18,4 +18,3 @@
* Support for preprocessing an operation prior to it being documented.
*/
package org.springframework.restdocs.operation.preprocess;

View File

@@ -18,4 +18,3 @@
* Core Spring REST Docs classes.
*/
package org.springframework.restdocs;

View File

@@ -57,9 +57,10 @@ public abstract class AbstractFieldsSnippet extends TemplatedSnippet {
for (FieldDescriptor descriptor : descriptors) {
Assert.notNull(descriptor.getPath(), "Field descriptors must have a path");
if (!descriptor.isIgnored()) {
Assert.notNull(descriptor.getDescription(), "The descriptor for field '"
+ descriptor.getPath() + "' must either have a description or"
+ " be marked as " + "ignored");
Assert.notNull(descriptor.getDescription(),
"The descriptor for field '" + descriptor.getPath()
+ "' must either have a description or" + " be marked as "
+ "ignored");
}
}

View File

@@ -44,13 +44,13 @@ class JsonContentHandler implements ContentHandler {
}
@Override
public List<FieldDescriptor> findMissingFields(List<FieldDescriptor> fieldDescriptors) {
public List<FieldDescriptor> findMissingFields(
List<FieldDescriptor> fieldDescriptors) {
List<FieldDescriptor> missingFields = new ArrayList<>();
Object payload = readContent();
for (FieldDescriptor fieldDescriptor : fieldDescriptors) {
if (!fieldDescriptor.isOptional()
&& !this.fieldProcessor.hasField(
JsonFieldPath.compile(fieldDescriptor.getPath()), payload)) {
if (!fieldDescriptor.isOptional() && !this.fieldProcessor.hasField(
JsonFieldPath.compile(fieldDescriptor.getPath()), payload)) {
missingFields.add(fieldDescriptor);
}
}

View File

@@ -87,8 +87,8 @@ final class JsonFieldPath {
List<String> segments = new ArrayList<>();
while (matcher.find()) {
if (previous != matcher.start()) {
segments.addAll(extractDotSeparatedSegments(path.substring(previous,
matcher.start())));
segments.addAll(extractDotSeparatedSegments(
path.substring(previous, matcher.start())));
}
if (matcher.group(1) != null) {
segments.add(matcher.group(1));

View File

@@ -89,26 +89,30 @@ final class JsonFieldProcessor {
}
}
private void handleListPayload(ProcessingContext context, MatchCallback matchCallback) {
private void handleListPayload(ProcessingContext context,
MatchCallback matchCallback) {
List<?> list = context.getPayload();
final Iterator<?> items = list.iterator();
if (context.isLeaf()) {
while (items.hasNext()) {
Object item = items.next();
matchCallback.foundMatch(new ListMatch(items, list, item, context
.getParentMatch()));
matchCallback.foundMatch(
new ListMatch(items, list, item, context.getParentMatch()));
}
}
else {
while (items.hasNext()) {
Object item = items.next();
traverse(context.descend(item, new ListMatch(items, list, item,
context.parent)), matchCallback);
traverse(
context.descend(item,
new ListMatch(items, list, item, context.parent)),
matchCallback);
}
}
}
private void handleMapPayload(ProcessingContext context, MatchCallback matchCallback) {
private void handleMapPayload(ProcessingContext context,
MatchCallback matchCallback) {
Map<?, ?> map = context.getPayload();
Object item = map.get(context.getSegment());
MapMatch mapMatch = new MapMatch(item, map, context.getSegment(),
@@ -238,8 +242,8 @@ final class JsonFieldProcessor {
}
private ProcessingContext descend(Object payload, Match match) {
return new ProcessingContext(payload, this.path, this.segments.subList(1,
this.segments.size()), match);
return new ProcessingContext(payload, this.path,
this.segments.subList(1, this.segments.size()), match);
}
}

View File

@@ -63,7 +63,8 @@ class XmlContentHandler implements ContentHandler {
}
@Override
public List<FieldDescriptor> findMissingFields(List<FieldDescriptor> fieldDescriptors) {
public List<FieldDescriptor> findMissingFields(
List<FieldDescriptor> fieldDescriptors) {
List<FieldDescriptor> missingFields = new ArrayList<>();
Document payload = readPayload();
for (FieldDescriptor fieldDescriptor : fieldDescriptors) {
@@ -78,7 +79,8 @@ class XmlContentHandler implements ContentHandler {
return missingFields;
}
private NodeList findMatchingNodes(FieldDescriptor fieldDescriptor, Document payload) {
private NodeList findMatchingNodes(FieldDescriptor fieldDescriptor,
Document payload) {
try {
return (NodeList) createXPath(fieldDescriptor.getPath()).evaluate(payload,
XPathConstants.NODESET);
@@ -90,15 +92,16 @@ class XmlContentHandler implements ContentHandler {
private Document readPayload() {
try {
return this.documentBuilder.parse(new InputSource(new ByteArrayInputStream(
this.rawContent)));
return this.documentBuilder
.parse(new InputSource(new ByteArrayInputStream(this.rawContent)));
}
catch (Exception ex) {
throw new PayloadHandlingException(ex);
}
}
private XPathExpression createXPath(String fieldPath) throws XPathExpressionException {
private XPathExpression createXPath(String fieldPath)
throws XPathExpressionException {
return XPathFactory.newInstance().newXPath().compile(fieldPath);
}

View File

@@ -18,4 +18,3 @@
* Documenting the payload of a RESTful API's requests and responses.
*/
package org.springframework.restdocs.payload;

View File

@@ -54,7 +54,8 @@ public abstract class AbstractParametersSnippet extends TemplatedSnippet {
List<ParameterDescriptor> descriptors, Map<String, Object> attributes) {
super(snippetName, attributes);
for (ParameterDescriptor descriptor : descriptors) {
Assert.notNull(descriptor.getName(), "Parameter descriptors must have a name");
Assert.notNull(descriptor.getName(),
"Parameter descriptors must have a name");
if (!descriptor.isIgnored()) {
Assert.notNull(descriptor.getDescription(),
"The descriptor for parameter '" + descriptor.getName()
@@ -71,7 +72,8 @@ public abstract class AbstractParametersSnippet extends TemplatedSnippet {
Map<String, Object> model = new HashMap<>();
List<Map<String, Object>> parameters = new ArrayList<>();
for (Entry<String, ParameterDescriptor> entry : this.descriptorsByName.entrySet()) {
for (Entry<String, ParameterDescriptor> entry : this.descriptorsByName
.entrySet()) {
ParameterDescriptor descriptor = entry.getValue();
if (!descriptor.isIgnored()) {
parameters.add(createModelForDescriptor(descriptor));
@@ -131,7 +133,8 @@ public abstract class AbstractParametersSnippet extends TemplatedSnippet {
* @param descriptor the descriptor
* @return the model
*/
protected Map<String, Object> createModelForDescriptor(ParameterDescriptor descriptor) {
protected Map<String, Object> createModelForDescriptor(
ParameterDescriptor descriptor) {
Map<String, Object> model = new HashMap<>();
model.put("name", descriptor.getName());
model.put("description", descriptor.getDescription());

View File

@@ -90,8 +90,8 @@ public class PathParametersSnippet extends AbstractParametersSnippet {
}
private String extractUrlTemplate(Operation operation) {
String urlTemplate = (String) operation.getAttributes().get(
"org.springframework.restdocs.urlTemplate");
String urlTemplate = (String) operation.getAttributes()
.get("org.springframework.restdocs.urlTemplate");
Assert.notNull(urlTemplate,
"urlTemplate not found. Did you use RestDocumentationRequestBuilders to "
+ "build the request?");

View File

@@ -18,4 +18,3 @@
* Documenting query and path parameters of requests sent to a RESTful API.
*/
package org.springframework.restdocs.request;

View File

@@ -22,8 +22,8 @@ package org.springframework.restdocs.snippet;
* @param <T> the type of the descriptor
* @author Andy Wilkinson
*/
public abstract class IgnorableDescriptor<T extends IgnorableDescriptor<T>> extends
AbstractDescriptor<T> {
public abstract class IgnorableDescriptor<T extends IgnorableDescriptor<T>>
extends AbstractDescriptor<T> {
private boolean ignored = false;

View File

@@ -137,8 +137,9 @@ public class RestDocumentationContextPlaceholderResolver implements PlaceholderR
Matcher matcher = CAMEL_CASE_PATTERN.matcher(string);
StringBuffer result = new StringBuffer();
while (matcher.find()) {
String replacement = (matcher.start() > 0) ? separator
+ matcher.group(1).toLowerCase() : matcher.group(1).toLowerCase();
String replacement = (matcher.start() > 0)
? separator + matcher.group(1).toLowerCase()
: matcher.group(1).toLowerCase();
matcher.appendReplacement(result, replacement);
}
matcher.appendTail(result);

View File

@@ -59,7 +59,8 @@ public final class StandardWriterResolver implements WriterResolver {
if (outputFile != null) {
createDirectoriesIfNecessary(outputFile);
return new OutputStreamWriter(new FileOutputStream(outputFile), this.encoding);
return new OutputStreamWriter(new FileOutputStream(outputFile),
this.encoding);
}
else {
return new OutputStreamWriter(System.out, this.encoding);
@@ -92,7 +93,8 @@ public final class StandardWriterResolver implements WriterResolver {
private void createDirectoriesIfNecessary(File outputFile) {
File parent = outputFile.getParentFile();
if (!parent.isDirectory() && !parent.mkdirs()) {
throw new IllegalStateException("Failed to create directory '" + parent + "'");
throw new IllegalStateException(
"Failed to create directory '" + parent + "'");
}
}
}

View File

@@ -57,10 +57,10 @@ public abstract class TemplatedSnippet implements Snippet {
public void document(Operation operation) throws IOException {
RestDocumentationContext context = (RestDocumentationContext) operation
.getAttributes().get(RestDocumentationContext.class.getName());
WriterResolver writerResolver = (WriterResolver) operation.getAttributes().get(
WriterResolver.class.getName());
try (Writer writer = writerResolver.resolve(operation.getName(),
this.snippetName, context)) {
WriterResolver writerResolver = (WriterResolver) operation.getAttributes()
.get(WriterResolver.class.getName());
try (Writer writer = writerResolver.resolve(operation.getName(), this.snippetName,
context)) {
Map<String, Object> model = createModel(operation);
model.putAll(this.attributes);
TemplateEngine templateEngine = (TemplateEngine) operation.getAttributes()

View File

@@ -18,4 +18,3 @@
* Snippet generation.
*/
package org.springframework.restdocs.snippet;

View File

@@ -38,10 +38,11 @@ public class StandardTemplateResourceResolver implements TemplateResourceResolve
"org/springframework/restdocs/templates/" + name + ".snippet");
if (!classPathResource.exists()) {
classPathResource = new ClassPathResource(
"org/springframework/restdocs/templates/default-" + name + ".snippet");
"org/springframework/restdocs/templates/default-" + name
+ ".snippet");
if (!classPathResource.exists()) {
throw new IllegalStateException("Template named '" + name
+ "' could not be resolved");
throw new IllegalStateException(
"Template named '" + name + "' could not be resolved");
}
}
return classPathResource;

View File

@@ -54,8 +54,8 @@ public class MustacheTemplateEngine implements TemplateEngine {
public Template compileTemplate(String name) throws IOException {
Resource templateResource = this.templateResourceResolver
.resolveTemplateResource(name);
return new MustacheTemplate(this.compiler.compile(new InputStreamReader(
templateResource.getInputStream())));
return new MustacheTemplate(this.compiler
.compile(new InputStreamReader(templateResource.getInputStream())));
}
}

View File

@@ -18,4 +18,3 @@
* JMustache-based implementation of the template API.
*/
package org.springframework.restdocs.templates.mustache;

View File

@@ -18,4 +18,3 @@
* Template API used to render documentation snippets.
*/
package org.springframework.restdocs.templates;