Skip to content

Commit

Permalink
Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Oct 10, 2021
1 parent c26b70e commit 9a06dc8
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
public final class UnnecessarilyFullyQualified extends BugChecker
implements CompilationUnitTreeMatcher {

private static final String JAVA_LANG = "java.lang";
private static final ImmutableSet<String> EXEMPTED_NAMES = ImmutableSet.of("Annotation");

@Override
Expand Down Expand Up @@ -169,15 +168,19 @@ public Void visitIdentifier(IdentifierTree identifierTree, Void aVoid) {
if (EXEMPTED_NAMES.contains(nameString)) {
continue;
}
TypeSymbol type = getOnlyElement(types.keySet());
List<TreePath> pathsToFix = getOnlyElement(types.values());
if (!pathsToFix.get(0).getLeaf().toString().contains(JAVA_LANG)
&& pathsToFix.stream()
.anyMatch(path -> findIdent(nameString, state.withPath(path), VAL_TYP) != null)) {
if (pathsToFix.stream()
.anyMatch(
path -> {
Symbol ident = findIdent(nameString, state.withPath(path), VAL_TYP);
return ident != null && !ident.equals(type);
})) {
continue;
}
SuggestedFix.Builder fixBuilder = SuggestedFix.builder();
String newImport = getOnlyElement(types.keySet()).getQualifiedName().toString();
if (!newImport.contains(JAVA_LANG)) {
if (!newImport.startsWith("java.lang.")) {
fixBuilder.addImport(newImport);
}
for (TreePath path : pathsToFix) {
Expand Down

0 comments on commit 9a06dc8

Please sign in to comment.