Skip to content

Commit 207530d

Browse files
author
Adrian Cole
committed
Reformats code according to Google Java Style
Files had various formatting differences, as did pull requests. Rather than create our own style, this inherits and requires the well documented Google Java Style.
1 parent 42fc476 commit 207530d

File tree

89 files changed

+3426
-2395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+3426
-2395
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Adds `Feign.Builder.build()`
88
* Opens constructor for Gson and Jackson codecs which accepts type adapters
99
* Adds EmptyTarget for interfaces who exclusively declare URI methods
10+
* Reformats code according to [Google Java Style](https://google-styleguide.googlecode.com/svn/trunk/javaguide.html)
1011

1112
### Version 7.1
1213
* Introduces feign.@Param to annotate template parameters. Users must migrate from `javax.inject.@Named` to `feign.@Param` before updating to Feign 8.0.

CONTRIBUTING.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Contributing to Feign
2+
3+
If you would like to contribute code you can do so through GitHub by forking the repository and sending a pull request (on a branch other than `master` or `gh-pages`).
4+
5+
When submitting code, please ensure you follow the [Google Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javaguide.html). For example, you can format code with Intellij using [this file](https://google-styleguide.googlecode.com/svn/trunk/intellij-java-google-style.xml).
6+
7+
## License
8+
9+
By contributing your code, you agree to license your contribution under the terms of the APLv2: https://github.com/Netflix/Feign/blob/master/LICENSE
10+
11+
All files are released with the Apache 2.0 license.
12+
13+
If you are adding a new file it should have a header like this:
14+
15+
```
16+
/**
17+
* Copyright 2013 Netflix, Inc.
18+
*
19+
* Licensed under the Apache License, Version 2.0 (the "License");
20+
* you may not use this file except in compliance with the License.
21+
* You may obtain a copy of the License at
22+
*
23+
* http://www.apache.org/licenses/LICENSE-2.0
24+
*
25+
* Unless required by applicable law or agreed to in writing, software
26+
* distributed under the License is distributed on an "AS IS" BASIS,
27+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28+
* See the License for the specific language governing permissions and
29+
* limitations under the License.
30+
*/
31+
```

core/src/main/java/feign/Body.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@
88
import static java.lang.annotation.RetentionPolicy.RUNTIME;
99

1010
/**
11-
* A possibly templated body of a PUT or POST command. variables wrapped in curly braces are expanded before the
12-
* request is submitted.
13-
* <br>
14-
* ex.
15-
* <br>
11+
* A possibly templated body of a PUT or POST command. variables wrapped in curly braces are
12+
* expanded before the request is submitted. <br> ex. <br>
1613
* <pre>
1714
* &#064;Body(&quot;&lt;v01:getResourceRecordsOfZone&gt;&lt;zoneName&gt;{zoneName}&lt;/zoneName&gt;&lt;rrType&gt;0&lt;/rrType&gt;&lt;/v01:getResourceRecordsOfZone&gt;&quot;)
1815
* List&lt;Record&gt; listByZone(&#64;Param(&quot;zoneName&quot;) String zoneName);
1916
* </pre>
20-
* <br>
21-
* Note that if you'd like curly braces literally in the body, urlencode
22-
* them first.
17+
* <br> Note that if you'd like curly braces literally in the body, urlencode them first.
2318
*
2419
* @see RequestTemplate#expand(String, Map)
2520
*/
26-
@Target(METHOD) @Retention(RUNTIME) public @interface Body {
21+
@Target(METHOD)
22+
@Retention(RUNTIME)
23+
public @interface Body {
24+
2725
String value();
2826
}

core/src/main/java/feign/Client.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@
3737
import static feign.Util.ENCODING_GZIP;
3838

3939
/**
40-
* Submits HTTP {@link Request requests}. Implementations are expected to be
41-
* thread-safe.
40+
* Submits HTTP {@link Request requests}. Implementations are expected to be thread-safe.
4241
*/
4342
public interface Client {
43+
4444
/**
45-
* Executes a request against its {@link Request#url() url} and returns a
46-
* response.
45+
* Executes a request against its {@link Request#url() url} and returns a response.
4746
*
4847
* @param request safe to replay.
4948
* @param options options to apply to this request.
@@ -53,22 +52,28 @@ public interface Client {
5352
Response execute(Request request, Options options) throws IOException;
5453

5554
public static class Default implements Client {
55+
5656
private final SSLSocketFactory sslContextFactory;
5757
private final HostnameVerifier hostnameVerifier;
5858

59-
/** Null parameters imply platform defaults. */
59+
/**
60+
* Null parameters imply platform defaults.
61+
*/
6062
public Default(SSLSocketFactory sslContextFactory, HostnameVerifier hostnameVerifier) {
6163
this.sslContextFactory = sslContextFactory;
6264
this.hostnameVerifier = hostnameVerifier;
6365
}
6466

65-
@Override public Response execute(Request request, Options options) throws IOException {
67+
@Override
68+
public Response execute(Request request, Options options) throws IOException {
6669
HttpURLConnection connection = convertAndSend(request, options);
6770
return convertResponse(connection);
6871
}
6972

7073
HttpURLConnection convertAndSend(Request request, Options options) throws IOException {
71-
final HttpURLConnection connection = (HttpURLConnection) new URL(request.url()).openConnection();
74+
final HttpURLConnection
75+
connection =
76+
(HttpURLConnection) new URL(request.url()).openConnection();
7277
if (connection instanceof HttpsURLConnection) {
7378
HttpsURLConnection sslCon = (HttpsURLConnection) connection;
7479
if (sslContextFactory != null) {
@@ -85,12 +90,16 @@ HttpURLConnection convertAndSend(Request request, Options options) throws IOExce
8590
connection.setRequestMethod(request.method());
8691

8792
Collection<String> contentEncodingValues = request.headers().get(CONTENT_ENCODING);
88-
boolean gzipEncodedRequest = contentEncodingValues != null && contentEncodingValues.contains(ENCODING_GZIP);
93+
boolean
94+
gzipEncodedRequest =
95+
contentEncodingValues != null && contentEncodingValues.contains(ENCODING_GZIP);
8996

9097
boolean hasAcceptHeader = false;
9198
Integer contentLength = null;
9299
for (String field : request.headers().keySet()) {
93-
if (field.equalsIgnoreCase("Accept")) hasAcceptHeader = true;
100+
if (field.equalsIgnoreCase("Accept")) {
101+
hasAcceptHeader = true;
102+
}
94103
for (String value : request.headers().get(field)) {
95104
if (field.equals(CONTENT_LENGTH)) {
96105
if (!gzipEncodedRequest) {
@@ -103,7 +112,9 @@ HttpURLConnection convertAndSend(Request request, Options options) throws IOExce
103112
}
104113
}
105114
// Some servers choke on the default accept string.
106-
if (!hasAcceptHeader) connection.addRequestProperty("Accept", "*/*");
115+
if (!hasAcceptHeader) {
116+
connection.addRequestProperty("Accept", "*/*");
117+
}
107118

108119
if (request.body() != null) {
109120
if (contentLength != null) {
@@ -135,13 +146,15 @@ Response convertResponse(HttpURLConnection connection) throws IOException {
135146
Map<String, Collection<String>> headers = new LinkedHashMap<String, Collection<String>>();
136147
for (Map.Entry<String, List<String>> field : connection.getHeaderFields().entrySet()) {
137148
// response message
138-
if (field.getKey() != null)
149+
if (field.getKey() != null) {
139150
headers.put(field.getKey(), field.getValue());
151+
}
140152
}
141153

142154
Integer length = connection.getContentLength();
143-
if (length == -1)
155+
if (length == -1) {
144156
length = null;
157+
}
145158
InputStream stream;
146159
if (status >= 400) {
147160
stream = connection.getErrorStream();

core/src/main/java/feign/Contract.java

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ public interface Contract {
3939

4040
abstract class BaseContract implements Contract {
4141

42-
@Override public List<MethodMetadata> parseAndValidatateMetadata(Class<?> declaring) {
42+
@Override
43+
public List<MethodMetadata> parseAndValidatateMetadata(Class<?> declaring) {
4344
List<MethodMetadata> metadata = new ArrayList<MethodMetadata>();
4445
for (Method method : declaring.getDeclaredMethods()) {
45-
if (method.getDeclaringClass() == Object.class)
46+
if (method.getDeclaringClass() == Object.class) {
4647
continue;
48+
}
4749
metadata.add(parseAndValidatateMetadata(method));
4850
}
4951
return metadata;
@@ -60,8 +62,9 @@ public MethodMetadata parseAndValidatateMetadata(Method method) {
6062
for (Annotation methodAnnotation : method.getAnnotations()) {
6163
processAnnotationOnMethod(data, methodAnnotation, method);
6264
}
63-
checkState(data.template().method() != null, "Method %s not annotated with HTTP method type (ex. GET, POST)",
64-
method.getName());
65+
checkState(data.template().method() != null,
66+
"Method %s not annotated with HTTP method type (ex. GET, POST)",
67+
method.getName());
6568
Class<?>[] parameterTypes = method.getParameterTypes();
6669

6770
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
@@ -74,7 +77,8 @@ public MethodMetadata parseAndValidatateMetadata(Method method) {
7477
if (parameterTypes[i] == URI.class) {
7578
data.urlIndex(i);
7679
} else if (!isHttpAnnotation) {
77-
checkState(data.formParams().isEmpty(), "Body parameters cannot be used with form parameters.");
80+
checkState(data.formParams().isEmpty(),
81+
"Body parameters cannot be used with form parameters.");
7882
checkState(data.bodyIndex() == null, "Method has too many Body parameters: %s", method);
7983
data.bodyIndex(i);
8084
data.bodyType(method.getGenericParameterTypes()[i]);
@@ -88,22 +92,26 @@ public MethodMetadata parseAndValidatateMetadata(Method method) {
8892
* @param annotation annotations present on the current method annotation.
8993
* @param method method currently being processed.
9094
*/
91-
protected abstract void processAnnotationOnMethod(MethodMetadata data, Annotation annotation, Method method);
95+
protected abstract void processAnnotationOnMethod(MethodMetadata data, Annotation annotation,
96+
Method method);
9297

9398
/**
9499
* @param data metadata collected so far relating to the current java method.
95100
* @param annotations annotations present on the current parameter annotation.
96-
* @param paramIndex if you find a name in {@code annotations}, call {@link #nameParam(MethodMetadata, String,
97-
* int)} with this as the last parameter.
98-
* @return true if you called {@link #nameParam(MethodMetadata, String, int)} after finding an http-relevant
99-
* annotation.
101+
* @param paramIndex if you find a name in {@code annotations}, call {@link
102+
* #nameParam(MethodMetadata, String, int)} with this as the last parameter.
103+
* @return true if you called {@link #nameParam(MethodMetadata, String, int)} after finding an
104+
* http-relevant annotation.
100105
*/
101-
protected abstract boolean processAnnotationsOnParameter(MethodMetadata data, Annotation[] annotations, int paramIndex);
106+
protected abstract boolean processAnnotationsOnParameter(MethodMetadata data,
107+
Annotation[] annotations,
108+
int paramIndex);
102109

103110

104111
protected Collection<String> addTemplatedParam(Collection<String> possiblyNull, String name) {
105-
if (possiblyNull == null)
112+
if (possiblyNull == null) {
106113
possiblyNull = new ArrayList<String>();
114+
}
107115
possiblyNull.add(String.format("{%s}", name));
108116
return possiblyNull;
109117
}
@@ -112,7 +120,9 @@ protected Collection<String> addTemplatedParam(Collection<String> possiblyNull,
112120
* links a parameter name to its index in the method signature.
113121
*/
114122
protected void nameParam(MethodMetadata data, String name, int i) {
115-
Collection<String> names = data.indexToName().containsKey(i) ? data.indexToName().get(i) : new ArrayList<String>();
123+
Collection<String>
124+
names =
125+
data.indexToName().containsKey(i) ? data.indexToName().get(i) : new ArrayList<String>();
116126
names.add(name);
117127
data.indexToName().put(i, names);
118128
}
@@ -121,11 +131,13 @@ protected void nameParam(MethodMetadata data, String name, int i) {
121131
class Default extends BaseContract {
122132

123133
@Override
124-
protected void processAnnotationOnMethod(MethodMetadata data, Annotation methodAnnotation, Method method) {
134+
protected void processAnnotationOnMethod(MethodMetadata data, Annotation methodAnnotation,
135+
Method method) {
125136
Class<? extends Annotation> annotationType = methodAnnotation.annotationType();
126137
if (annotationType == RequestLine.class) {
127138
String requestLine = RequestLine.class.cast(methodAnnotation).value();
128-
checkState(emptyToNull(requestLine) != null, "RequestLine annotation was empty on method %s.", method.getName());
139+
checkState(emptyToNull(requestLine) != null,
140+
"RequestLine annotation was empty on method %s.", method.getName());
129141
if (requestLine.indexOf(' ') == -1) {
130142
data.template().method(requestLine);
131143
return;
@@ -136,20 +148,25 @@ protected void processAnnotationOnMethod(MethodMetadata data, Annotation methodA
136148
data.template().append(requestLine.substring(requestLine.indexOf(' ') + 1));
137149
} else {
138150
// skip HTTP version
139-
data.template().append(requestLine.substring(requestLine.indexOf(' ') + 1, requestLine.lastIndexOf(' ')));
151+
data.template().append(
152+
requestLine.substring(requestLine.indexOf(' ') + 1, requestLine.lastIndexOf(' ')));
140153
}
141154
} else if (annotationType == Body.class) {
142155
String body = Body.class.cast(methodAnnotation).value();
143-
checkState(emptyToNull(body) != null, "Body annotation was empty on method %s.", method.getName());
156+
checkState(emptyToNull(body) != null, "Body annotation was empty on method %s.",
157+
method.getName());
144158
if (body.indexOf('{') == -1) {
145159
data.template().body(body);
146160
} else {
147161
data.template().bodyTemplate(body);
148162
}
149163
} else if (annotationType == Headers.class) {
150164
String[] headersToParse = Headers.class.cast(methodAnnotation).value();
151-
checkState(headersToParse.length > 0, "Headers annotation was empty on method %s.", method.getName());
152-
Map<String, Collection<String>> headers = new LinkedHashMap<String, Collection<String>>(headersToParse.length);
165+
checkState(headersToParse.length > 0, "Headers annotation was empty on method %s.",
166+
method.getName());
167+
Map<String, Collection<String>>
168+
headers =
169+
new LinkedHashMap<String, Collection<String>>(headersToParse.length);
153170
for (String header : headersToParse) {
154171
int colon = header.indexOf(':');
155172
String name = header.substring(0, colon);
@@ -163,13 +180,15 @@ protected void processAnnotationOnMethod(MethodMetadata data, Annotation methodA
163180
}
164181

165182
@Override
166-
protected boolean processAnnotationsOnParameter(MethodMetadata data, Annotation[] annotations, int paramIndex) {
183+
protected boolean processAnnotationsOnParameter(MethodMetadata data, Annotation[] annotations,
184+
int paramIndex) {
167185
boolean isHttpAnnotation = false;
168186
for (Annotation annotation : annotations) {
169187
Class<? extends Annotation> annotationType = annotation.annotationType();
170188
if (annotationType == Param.class) {
171189
String name = ((Param) annotation).value();
172-
checkState(emptyToNull(name) != null, "Param annotation was empty on param %s.", paramIndex);
190+
checkState(emptyToNull(name) != null, "Param annotation was empty on param %s.",
191+
paramIndex);
173192
nameParam(data, name, paramIndex);
174193
if (annotationType == Param.class) {
175194
Class<? extends Param.Expander> expander = ((Param) annotation).expander();
@@ -191,12 +210,14 @@ protected boolean processAnnotationsOnParameter(MethodMetadata data, Annotation[
191210

192211
private <K, V> boolean searchMapValues(Map<K, Collection<V>> map, V search) {
193212
Collection<Collection<V>> values = map.values();
194-
if (values == null)
213+
if (values == null) {
195214
return false;
215+
}
196216

197217
for (Collection<V> entry : values) {
198-
if (entry.contains(search))
218+
if (entry.contains(search)) {
199219
return true;
220+
}
200221
}
201222

202223
return false;

0 commit comments

Comments
 (0)