Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 11407fa

Browse files
committed
Fixed codacity indicated error prone code
1 parent d046161 commit 11407fa

10 files changed

Lines changed: 36 additions & 54 deletions

File tree

springfox-core/src/main/java/springfox/documentation/builders/BuilderDefaults.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
import static com.google.common.collect.Sets.*;
3737
import static springfox.documentation.schema.Enums.*;
3838

39+
/**
40+
* This is a utility class with useful methods for builders
41+
*/
3942
public class BuilderDefaults {
4043
private BuilderDefaults() {
4144
throw new UnsupportedOperationException();
@@ -124,17 +127,17 @@ public static <T> Set<T> nullToEmptySet(Set<T> newValue) {
124127
* @return most specific resolved type
125128
*/
126129
public static ResolvedType replaceIfMoreSpecific(ResolvedType replacement, ResolvedType defaultValue) {
127-
replacement = defaultIfAbsent(replacement, defaultValue);
130+
ResolvedType toReturn = defaultIfAbsent(replacement, defaultValue);
128131
if (isObject(replacement) && isNotObject(defaultValue)) {
129132
return defaultValue;
130133
}
131-
return replacement;
134+
return toReturn;
132135
}
133136

134137
/**
135138
* Returns an empty list if the newValue is null
136139
*
137-
* @param newValue - a list
140+
* @param args - a list
138141
* @param <T> - any type
139142
* @return non-null list
140143
*/
@@ -155,6 +158,12 @@ private static boolean isObject(ResolvedType replacement) {
155158
Object.class.equals(replacement.getErasedType());
156159
}
157160

161+
/**
162+
* Retains current allowable values if then new value is null
163+
* @param newValue - new value
164+
* @param current - existing values
165+
* @return the appropriate value
166+
*/
158167
public static AllowableValues emptyToNull(AllowableValues newValue, AllowableValues current) {
159168
if (newValue != null) {
160169
if (newValue instanceof AllowableListValues) {

springfox-core/src/main/java/springfox/documentation/schema/ClassSupport.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,13 @@
1818
*/
1919
package springfox.documentation.schema;
2020

21-
import com.fasterxml.classmate.ResolvedType;
2221
import com.google.common.base.Optional;
2322

2423
public class ClassSupport {
2524
private ClassSupport() {
2625
throw new UnsupportedOperationException();
2726
}
2827

29-
public static boolean isOptional(ResolvedType resolvedType) {
30-
if ("java.util.Optional".equals(resolvedType.getErasedType().getName()) ||
31-
Optional.class.equals(resolvedType.getErasedType())) {
32-
return true;
33-
}
34-
return false;
35-
}
36-
3728
public static Optional<? extends Class> classByName(String className) {
3829
try {
3930
return Optional.of(Class.forName(className));

springfox-core/src/test/groovy/springfox/documentation/schema/ClassSupportSpec.groovy

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package springfox.documentation.schema
22

3-
import com.fasterxml.classmate.TypeResolver
4-
import com.google.common.base.Optional
53
import spock.lang.Specification
64

75
import static springfox.documentation.schema.ClassSupport.*
@@ -25,16 +23,4 @@ class ClassSupportSpec extends Specification {
2523
"java.util.NonExistent" | false
2624
}
2725

28-
def "detects optional types" () {
29-
given:
30-
def resolver = new TypeResolver()
31-
def optional = isOptional(resolver.resolve(type))
32-
expect:
33-
expectedOptional == optional
34-
where:
35-
type | expectedOptional
36-
Optional | true
37-
String | false
38-
}
39-
4026
}

springfox-schema/src/main/java/springfox/documentation/schema/Collections.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,9 @@ public static ResolvedType collectionElementType(ResolvedType type) {
4444
}
4545

4646
public static boolean isContainerType(ResolvedType type) {
47-
if (List.class.isAssignableFrom(type.getErasedType()) ||
48-
Set.class.isAssignableFrom(type.getErasedType()) ||
49-
type.isArray()) {
50-
return true;
51-
}
52-
return false;
47+
return List.class.isAssignableFrom(type.getErasedType()) ||
48+
Set.class.isAssignableFrom(type.getErasedType()) ||
49+
type.isArray();
5350
}
5451

5552
public static String containerType(ResolvedType type) {

springfox-spring-web/src/main/java/springfox/documentation/spring/web/ControllerNamingUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ public static String pathRoot(String requestPattern) {
3737
Assert.notNull(requestPattern);
3838
Assert.hasText(requestPattern);
3939
log.info("Resolving path root for {}", requestPattern);
40-
requestPattern = requestPattern.startsWith("/") ? requestPattern : "/" + requestPattern;
41-
int idx = requestPattern.indexOf("/", 1);
40+
String adjustedPattern = requestPattern.startsWith("/") ? requestPattern : "/" + requestPattern;
41+
int idx = adjustedPattern.indexOf("/", 1);
4242
if (idx > -1) {
43-
return requestPattern.substring(0, idx);
43+
return adjustedPattern.substring(0, idx);
4444
}
45-
return requestPattern;
45+
return adjustedPattern;
4646
}
4747

4848
public static String pathRootEncoded(String requestPattern) {
@@ -51,7 +51,7 @@ public static String pathRootEncoded(String requestPattern) {
5151

5252
public static String encode(String path) {
5353
try {
54-
path = UriUtils.encodePath(path, ISO_8859_1);
54+
return UriUtils.encodePath(path, ISO_8859_1);
5555
} catch (UnsupportedEncodingException e) {
5656
log.error("Could not encode:" + path, e);
5757
}
@@ -60,7 +60,7 @@ public static String encode(String path) {
6060

6161
public static String decode(String path) {
6262
try {
63-
path = UriUtils.decode(path, ISO_8859_1);
63+
return UriUtils.decode(path, ISO_8859_1);
6464
} catch (Exception e) {
6565
log.error("Could not decode:" + path, e);
6666
}

springfox-spring-web/src/main/java/springfox/documentation/spring/web/plugins/DocumentationPluginsManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,11 @@ public String apply(String input) {
153153
Iterable<Function<String, String>> decorators
154154
= from(pathDecorators.getPluginsFor(context.documentationContext()))
155155
.transform(toDecorator(context));
156+
String decorated = input;
156157
for (Function<String, String> decorator : decorators) {
157-
input = decorator.apply(input);
158+
decorated = decorator.apply(decorated);
158159
}
159-
return input;
160+
return decorated;
160161
}
161162
};
162163
}

springfox-spring-web/src/main/java/springfox/documentation/spring/web/readers/parameter/ModelAttributeParameterExpander.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private Class<?> fieldType(AlternateTypeProvider alternateTypeProvider, Field fi
194194
ResolvedType resolvedType = resolver.resolve(type);
195195
ResolvedType alternativeType = alternateTypeProvider.alternateFor(resolvedType);
196196
Class<?> erasedType = alternativeType.getErasedType();
197-
if (type != erasedType) {
197+
if (!type.equals(erasedType)) {
198198
LOG.debug("Found alternative type [{}] for field: [{}-{}]", erasedType, field, type);
199199
}
200200
return erasedType;

springfox-spring-web/src/test/java/springfox/documentation/spring/web/configuration/GenericWebContextLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private MockServletContext initServletContext(String warRootDir, ResourceLoader
4848
return new MockServletContext(warRootDir, resourceLoader) {
4949
// Required for DefaultServletHttpRequestHandler...
5050
public RequestDispatcher getNamedDispatcher(String path) {
51-
return path.equals("default") ? new MockRequestDispatcher(path) : super.getNamedDispatcher(path);
51+
return "default".equals(path) ? new MockRequestDispatcher(path) : super.getNamedDispatcher(path);
5252
}
5353
};
5454
}

springfox-swagger-common/src/main/java/springfox/documentation/swagger/readers/operation/VendorExtensionsReader.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ public VendorExtension apply(String input) {
104104
}
105105

106106
private String ensurePrefixed(String name) {
107-
if (!isNullOrEmpty(name)) {
108-
if (!name.startsWith("x-")) {
109-
name = "x-" + name;
110-
}
107+
if (!isNullOrEmpty(name) && !name.startsWith("x-")) {
108+
return "x-" + name;
111109
}
112110
return name;
113111
}

springfox-swagger-common/src/main/java/springfox/documentation/swagger/schema/ApiModelProperties.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ public AllowableValues apply(ApiModelProperty annotation) {
5656

5757
public static AllowableValues allowableValueFromString(String allowableValueString) {
5858
AllowableValues allowableValues = new AllowableListValues(Lists.<String>newArrayList(), "LIST");
59-
allowableValueString = allowableValueString.trim();
60-
if (allowableValueString.startsWith("range[")) {
61-
allowableValueString = allowableValueString.replaceAll("range\\[", "").replaceAll("]", "");
62-
Iterable<String> split = Splitter.on(',').trimResults().omitEmptyStrings().split(allowableValueString);
59+
String trimmed = allowableValueString.trim();
60+
if (trimmed.startsWith("range[")) {
61+
trimmed = trimmed.replaceAll("range\\[", "").replaceAll("]", "");
62+
Iterable<String> split = Splitter.on(',').trimResults().omitEmptyStrings().split(trimmed);
6363
List<String> ranges = newArrayList(split);
6464
allowableValues = new AllowableRangeValues(ranges.get(0), ranges.get(1));
65-
} else if (allowableValueString.contains(",")) {
66-
Iterable<String> split = Splitter.on(',').trimResults().omitEmptyStrings().split(allowableValueString);
65+
} else if (trimmed.contains(",")) {
66+
Iterable<String> split = Splitter.on(',').trimResults().omitEmptyStrings().split(trimmed);
6767
allowableValues = new AllowableListValues(newArrayList(split), "LIST");
68-
} else if (hasText(allowableValueString)) {
69-
List<String> singleVal = Collections.singletonList(allowableValueString);
68+
} else if (hasText(trimmed)) {
69+
List<String> singleVal = Collections.singletonList(trimmed);
7070
allowableValues = new AllowableListValues(singleVal, "LIST");
7171
}
7272
return allowableValues;

0 commit comments

Comments
 (0)