Skip to content

Commit 752195c

Browse files
Fix warnings
1 parent 0d62e5c commit 752195c

File tree

4 files changed

+94
-62
lines changed

4 files changed

+94
-62
lines changed

src/main/java/org/assertj/assertions/generator/BaseAssertionGenerator.java

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151

5252
import com.google.common.reflect.TypeToken;
5353

54-
@SuppressWarnings("WeakerAccess")
5554
public class BaseAssertionGenerator implements AssertionGenerator, AssertionsEntryPointGenerator {
5655

5756
static final String TEMPLATES_DIR = "templates" + File.separator;
@@ -165,7 +164,7 @@ public class BaseAssertionGenerator implements AssertionGenerator, AssertionsEnt
165164
* @see Character#isJavaIdentifierPart
166165
*/
167166
private static final Pattern CLASS_NAME_PATTERN = Pattern
168-
.compile("(?m)^public class[\\s]+(?<CLASSNAME>\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)\\b");
167+
.compile("(?m)^public class[\\s]+(?<CLASSNAME>\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)\\b");
169168

170169
private static final Set<TypeToken<?>> EMPTY_HIERARCHY = new HashSet<>();
171170

@@ -213,7 +212,8 @@ public void setGeneratedAssertionsPackage(String generatedAssertionsPackage) {
213212
}
214213

215214
private void checkGivenPackageIsValid(String generatedAssertionsPackage) {
216-
Validate.isTrue(isNotBlank(generatedAssertionsPackage), "The given package '%s' must not be blank", generatedAssertionsPackage);
215+
Validate.isTrue(isNotBlank(generatedAssertionsPackage), "The given package '%s' must not be blank",
216+
generatedAssertionsPackage);
217217
Validate.isTrue(!containsWhitespace(generatedAssertionsPackage), "The given package '%s' must not contain blank character",
218218
generatedAssertionsPackage);
219219
}
@@ -233,7 +233,8 @@ private String getDirectoryWhereToCreateAssertFilesFor(ClassDescription classDes
233233
}
234234

235235
@Override
236-
public File[] generateHierarchicalCustomAssertionFor(ClassDescription classDescription, Set<TypeToken<?>> allClasses) throws IOException {
236+
public File[] generateHierarchicalCustomAssertionFor(ClassDescription classDescription,
237+
Set<TypeToken<?>> allClasses) throws IOException {
237238
// Assertion content
238239
String[] assertionFileContent = generateHierarchicalCustomAssertionContentFor(classDescription, allClasses);
239240
// Create the assertion file in targetBaseDirectory + either the given package or in the class to assert package
@@ -267,7 +268,8 @@ public String[] generateHierarchicalCustomAssertionContentFor(ClassDescription c
267268

268269
// return a String array with the actual generated content of the assertion class hierarchy
269270
String[] assertionClassesContent = new String[2];
270-
assertionClassesContent[0] = fillAbstractAssertClassTemplate(abstractAssertClassContentBuilder.toString(), classDescription, classes);
271+
assertionClassesContent[0] = fillAbstractAssertClassTemplate(abstractAssertClassContentBuilder.toString(), classDescription,
272+
classes);
271273
assertionClassesContent[1] = fillConcreteAssertClassTemplate(concreteAssertClassContent, classDescription);
272274
return assertionClassesContent;
273275
}
@@ -294,19 +296,19 @@ private String fillAssertClassTemplate(String template, ClassDescription classDe
294296
classesToImport.add(classDescription.getFullyQualifiedOuterClassName());
295297
if (template.contains("Assertions.")) classesToImport.add("org.assertj.core.api.Assertions");
296298
if (template.contains("Objects.")) {
297-
int totalObjects = StringUtils.countMatches( template, "Objects." );
298-
int areEqualObjects = StringUtils.countMatches( template, "Objects.deepEquals" );
299-
int areEqualArraysObjects = StringUtils.countMatches( template, "Objects.deepEqualsArrays" );
300-
301-
int totalDeprecated = areEqualObjects + areEqualArraysObjects;
302-
303-
if( totalDeprecated > 0 ) {
304-
classesToImport.add("java.util.Objects");
305-
}
306-
307-
if ( totalObjects > totalDeprecated ) {
308-
classesToImport.add( "org.assertj.core.util.Objects" );
309-
}
299+
int totalObjects = StringUtils.countMatches(template, "Objects.");
300+
int areEqualObjects = StringUtils.countMatches(template, "Objects.deepEquals");
301+
int areEqualArraysObjects = StringUtils.countMatches(template, "Objects.deepEqualsArrays");
302+
303+
int totalDeprecated = areEqualObjects + areEqualArraysObjects;
304+
305+
if (totalDeprecated > 0) {
306+
classesToImport.add("java.util.Objects");
307+
}
308+
309+
if (totalObjects > totalDeprecated) {
310+
classesToImport.add("org.assertj.core.util.Objects");
311+
}
310312
}
311313
if (template.contains("Iterables.")) classesToImport.add("org.assertj.core.internal.Iterables");
312314

@@ -319,7 +321,8 @@ private String fillAssertClassTemplate(String template, ClassDescription classDe
319321
classesToImport.add(parentAssertClassName);
320322
}
321323

322-
final String customAssertionClass = concrete ? classDescription.getAssertClassName() : classDescription.getAbstractAssertClassName();
324+
final String customAssertionClass = concrete ? classDescription.getAssertClassName()
325+
: classDescription.getAbstractAssertClassName();
323326
final String selfType = concrete ? customAssertionClass : ABSTRACT_ASSERT_SELF_TYPE;
324327
final String myself = concrete ? "this" : "myself";
325328

@@ -474,7 +477,8 @@ private String generateAssertionsEntryPointClassContent(final Set<ClassDescripti
474477
private File createAssertionsFileFor(final Set<ClassDescription> classDescriptionSet, final String fileContent,
475478
final String fileName, final String assertionsClassPackage) throws IOException {
476479
String classPackage = isEmpty(assertionsClassPackage)
477-
? determineBestEntryPointsAssertionsClassPackage(classDescriptionSet) : assertionsClassPackage;
480+
? determineBestEntryPointsAssertionsClassPackage(classDescriptionSet)
481+
: assertionsClassPackage;
478482
String assertionsDirectory = getDirectoryPathCorrespondingToPackage(classPackage);
479483
// build any needed directories
480484
buildDirectory(assertionsDirectory);
@@ -521,7 +525,7 @@ private String determineBestEntryPointsAssertionsClassPackage(final Set<ClassDes
521525
/**
522526
* Returns the target directory path where the assertions file for given classDescription will be created.
523527
*
524-
* @param packageName package name
528+
* @param packageName package name
525529
* @return the target directory path corresponding to the given package.
526530
*/
527531
private String getDirectoryPathCorrespondingToPackage(final String packageName) {
@@ -631,11 +635,12 @@ private String assertionContentForField(FieldDescription field, ClassDescription
631635

632636
private String getTypeName(DataDescription fieldOrGetter) {
633637
if (generatedAssertionsPackage != null) {
634-
// if the user has chosen to generate assertions in a given package we assume that
638+
// if the user has chosen to generate assertions in a given package we assume that
635639
return fieldOrGetter.getFullyQualifiedTypeName();
636640
}
637-
// returns a simple class name if the field or getter type is in the same package as its owning type which is the package where the
638-
// Assert class is generated.
641+
// returns a simple class name if the field or getter type is in the same package as its owning type which is the package
642+
// where the
643+
// Assert class is generated.
639644
return fieldOrGetter.getTypeName();
640645
}
641646

src/main/java/org/assertj/assertions/generator/description/ClassDescription.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,23 @@
1212
*/
1313
package org.assertj.assertions.generator.description;
1414

15-
import com.google.common.reflect.TypeToken;
15+
import static com.google.common.collect.Sets.union;
16+
import static org.apache.commons.lang3.RegExUtils.removeAll;
17+
import static org.apache.commons.lang3.StringUtils.capitalize;
18+
import static org.apache.commons.lang3.StringUtils.remove;
19+
import static org.apache.commons.lang3.StringUtils.substringBefore;
20+
import static org.assertj.assertions.generator.util.ClassUtil.PREDICATE_PREFIXES;
21+
import static org.assertj.assertions.generator.util.ClassUtil.getTypeDeclaration;
22+
import static org.assertj.assertions.generator.util.ClassUtil.getTypeNameWithoutDots;
23+
import static org.assertj.assertions.generator.util.ClassUtil.packageNameRegex;
1624

1725
import java.util.Collection;
1826
import java.util.HashSet;
1927
import java.util.Objects;
2028
import java.util.Set;
2129
import java.util.TreeSet;
2230

23-
import static com.google.common.collect.Sets.union;
24-
import static org.apache.commons.lang3.RegExUtils.removeAll;
25-
import static org.apache.commons.lang3.StringUtils.*;
26-
import static org.assertj.assertions.generator.util.ClassUtil.*;
31+
import com.google.common.reflect.TypeToken;
2732

2833
/**
2934
*
@@ -59,9 +64,9 @@ public String getFullyQualifiedClassName() {
5964
}
6065

6166
public String getFullyQualifiedOuterClassName() {
62-
// get the class part only (including all nested/inner ones): Outer.Inner.ReallyInner
67+
// get the class part only (including all nested/inner ones): Outer.Inner.ReallyInner
6368
String outerClassNameWithInner = remove(getFullyQualifiedClassName(), getPackageName() + ".");
64-
// get the outer class part only : Outer
69+
// get the outer class part only : Outer
6570
String outerClassNameOnly = substringBefore(outerClassNameWithInner, ".");
6671
return getPackageName() + "." + outerClassNameOnly;
6772
}
@@ -134,7 +139,7 @@ public TypeToken<?> getSuperType() {
134139
return superType;
135140
}
136141

137-
@SuppressWarnings("unchecked")
142+
@SuppressWarnings({ "unchecked", "rawtypes" })
138143
public void setSuperType(Class<?> superType) {
139144
// TypeToken#getSupertype(..) checks to make sure it is a super type
140145
if (superType != null) {
@@ -157,7 +162,6 @@ public String getFullyQualifiedAssertClassName() {
157162
return getPackageName() + "." + getAssertClassName();
158163
}
159164

160-
161165
public String getAbstractAssertClassName() {
162166
return abstractAssertClassNameOf(type);
163167
}
@@ -169,7 +173,7 @@ public String getAbstractAssertClassFilename() {
169173

170174
public String getFullyQualifiedParentAssertClassName() {
171175
if (superType.getRawType().equals(Object.class)) return "org.assertj.core.api.AbstractObjectAssert";
172-
else return superType.getRawType().getPackage().getName() + "." + abstractAssertClassNameOf(superType);
176+
return superType.getRawType().getPackage().getName() + "." + abstractAssertClassNameOf(superType);
173177
}
174178

175179
@Override

src/main/java/org/assertj/assertions/generator/description/converter/AnnotationConfiguration.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
*/
1313
package org.assertj.assertions.generator.description.converter;
1414

15-
import com.google.common.collect.Sets;
16-
17-
import java.util.Collections;
1815
import java.util.Set;
1916

17+
import com.google.common.collect.Sets;
18+
2019
/**
2120
* Defines which annotations to use to annotate getters method or class to generate assertions for.
2221
*

src/main/java/org/assertj/assertions/generator/util/ClassUtil.java

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,63 @@
1212
*/
1313
package org.assertj.assertions.generator.util;
1414

15-
import com.google.common.base.Strings;
16-
import com.google.common.collect.ImmutableSet;
17-
import com.google.common.reflect.ClassPath;
18-
import com.google.common.reflect.ClassPath.ClassInfo;
19-
import com.google.common.reflect.TypeToken;
20-
import org.apache.commons.lang3.ClassUtils;
21-
import org.apache.commons.lang3.StringUtils;
22-
import org.assertj.assertions.generator.description.Visibility;
15+
import static com.google.common.base.Preconditions.checkNotNull;
16+
import static com.google.common.collect.Lists.newArrayList;
17+
import static com.google.common.collect.Sets.newLinkedHashSet;
18+
import static java.lang.reflect.Modifier.isPublic;
19+
import static java.lang.reflect.Modifier.isStatic;
20+
import static java.util.Arrays.asList;
21+
import static org.apache.commons.lang3.RegExUtils.removeAll;
22+
import static org.apache.commons.lang3.StringUtils.indexOfAny;
23+
import static org.apache.commons.lang3.StringUtils.remove;
24+
import static org.apache.commons.lang3.StringUtils.removeStart;
25+
import static org.apache.commons.lang3.StringUtils.uncapitalize;
2326

2427
import java.io.File;
2528
import java.io.IOException;
2629
import java.io.UnsupportedEncodingException;
2730
import java.lang.annotation.Annotation;
28-
import java.lang.reflect.*;
31+
import java.lang.reflect.Array;
32+
import java.lang.reflect.Field;
33+
import java.lang.reflect.GenericArrayType;
34+
import java.lang.reflect.GenericDeclaration;
35+
import java.lang.reflect.Method;
36+
import java.lang.reflect.Modifier;
37+
import java.lang.reflect.ParameterizedType;
38+
import java.lang.reflect.Type;
39+
import java.lang.reflect.TypeVariable;
40+
import java.lang.reflect.WildcardType;
2941
import java.net.URL;
3042
import java.net.URLDecoder;
31-
import java.util.*;
43+
import java.util.ArrayList;
44+
import java.util.Collection;
45+
import java.util.Collections;
46+
import java.util.Comparator;
47+
import java.util.Enumeration;
48+
import java.util.HashMap;
49+
import java.util.HashSet;
50+
import java.util.LinkedHashSet;
51+
import java.util.List;
52+
import java.util.Map;
53+
import java.util.Objects;
54+
import java.util.Set;
55+
import java.util.TreeSet;
3256
import java.util.regex.Matcher;
3357
import java.util.regex.Pattern;
3458

35-
import static com.google.common.base.Preconditions.checkNotNull;
36-
import static com.google.common.collect.Lists.newArrayList;
37-
import static com.google.common.collect.Sets.newLinkedHashSet;
38-
import static java.lang.reflect.Modifier.isPublic;
39-
import static java.lang.reflect.Modifier.isStatic;
40-
import static java.util.Arrays.asList;
41-
import static org.apache.commons.lang3.RegExUtils.removeAll;
42-
import static org.apache.commons.lang3.StringUtils.*;
59+
import org.apache.commons.lang3.ClassUtils;
60+
import org.apache.commons.lang3.StringUtils;
61+
import org.assertj.assertions.generator.description.Visibility;
62+
63+
import com.google.common.base.Strings;
64+
import com.google.common.collect.ImmutableSet;
65+
import com.google.common.reflect.ClassPath;
66+
import com.google.common.reflect.ClassPath.ClassInfo;
67+
import com.google.common.reflect.TypeToken;
4368

4469
/**
4570
* Some utilities methods related to classes and packages.
4671
*/
47-
@SuppressWarnings("WeakerAccess")
4872
public class ClassUtil {
4973

5074
public static final String GET_PREFIX = "get";
@@ -56,7 +80,7 @@ public class ClassUtil {
5680
/**
5781
* Call {@link #collectClasses(ClassLoader, String...)} with <code>Thread.currentThread().getContextClassLoader()
5882
* </code>
59-
*
83+
* @param classOrPackageNames classes or packages to collect.
6084
* @return the set of {@link TypeToken}s found
6185
*/
6286
public static Set<TypeToken<?>> collectClasses(String... classOrPackageNames) {
@@ -92,7 +116,8 @@ public static Set<TypeToken<?>> collectClasses(ClassLoader classLoader, String..
92116
* @return the set of {@link Class}es found
93117
* @throws RuntimeException if any error occurs
94118
*/
95-
public static Set<TypeToken<?>> collectClasses(ClassLoader classLoader, boolean includePrivateClasses, String... classOrPackageNames) {
119+
public static Set<TypeToken<?>> collectClasses(ClassLoader classLoader, boolean includePrivateClasses,
120+
String... classOrPackageNames) {
96121
Set<TypeToken<?>> classes = newLinkedHashSet();
97122
for (String classOrPackageName : classOrPackageNames) {
98123
TypeToken<?> clazz = tryToLoadClass(classOrPackageName, classLoader);
@@ -130,7 +155,7 @@ private static Set<TypeToken<?>> getClassesInPackage(String packageName, ClassLo
130155
}
131156

132157
private static Set<TypeToken<?>> getPackageClassesFromClasspathJars(String packageName, ClassLoader classLoader)
133-
throws IOException {
158+
throws IOException {
134159
ImmutableSet<ClassInfo> classesInfo = ClassPath.from(classLoader).getTopLevelClassesRecursive(packageName);
135160
Set<TypeToken<?>> classesInPackage = new HashSet<>();
136161
for (ClassInfo classInfo : classesInfo) {
@@ -179,7 +204,7 @@ private static Set<TypeToken<?>> getPackageClassesFromClasspathFiles(String pack
179204
* @throws UnsupportedEncodingException thrown by {@link URLDecoder#decode(String, String)}
180205
*/
181206
private static Set<TypeToken<?>> getClassesInDirectory(File directory, String packageName, ClassLoader classLoader)
182-
throws UnsupportedEncodingException {
207+
throws UnsupportedEncodingException {
183208
Set<TypeToken<?>> classes = new LinkedHashSet<>();
184209

185210
// Capture all the .class files in this directory
@@ -691,9 +716,8 @@ public static String resolveTypeNameInPackage(Type type, String currentPackage)
691716
private static String resolveTypeNameInPackage(String type, String currentPackage) {
692717
if (!Strings.isNullOrEmpty(currentPackage) && type.startsWith(currentPackage)) {
693718
return type.substring(currentPackage.length() + 1, type.length());
694-
} else {
695-
return type;
696719
}
720+
return type;
697721
}
698722

699723
/**

0 commit comments

Comments
 (0)