Skip to content

Commit

Permalink
Simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Oct 12, 2021
1 parent 7f22566 commit 43d7f86
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import com.sun.tools.javac.code.Symbol.TypeSymbol;
import com.sun.tools.javac.util.Position;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
Expand All @@ -73,7 +72,6 @@ public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState s
return NO_MATCH;
}
Table<Name, TypeSymbol, List<TreePath>> table = HashBasedTable.create();
Map<Name, TypeSymbol> identifiersSeen = new HashMap<>();
new SuppressibleTreePathScanner<Void, Void>() {
@Override
public Void visitImport(ImportTree importTree, Void unused) {
Expand All @@ -88,13 +86,6 @@ public Void visitMemberSelect(MemberSelectTree memberSelectTree, Void unused) {
return super.visitMemberSelect(memberSelectTree, null);
}

@Override
public Void visitIdentifier(IdentifierTree identifierTree, Void unused) {
Symbol symbol = getSymbol(identifierTree);
identifiersSeen.put(identifierTree.getName(), symbol == null ? null : symbol.type.tsym);
return null;
}

private boolean shouldIgnore() {
// Don't report duplicate hits if we're not at the tail of a series of member selects on
// classes.
Expand Down Expand Up @@ -161,16 +152,12 @@ public Void visitIdentifier(IdentifierTree identifierTree, Void aVoid) {
if (Ascii.isLowerCase(name.charAt(0))) {
continue;
}
TypeSymbol type = getOnlyElement(types.keySet());
if (!type.equals(identifiersSeen.get(name))) {
continue;
}
String nameString = name.toString();
if (EXEMPTED_NAMES.contains(nameString)) {
continue;
}
TypeSymbol type = getOnlyElement(types.keySet());
List<TreePath> pathsToFix = getOnlyElement(types.values());
// XXX: Or it will go here.
if (pathsToFix.stream()
.anyMatch(
path -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,28 @@ public void refersToMultipleTypes() {
.doTest();
}

@Test
public void inconsistentImportUsage() {
helper
.addInputLines(
"Test.java",
"import java.util.List;",
"public class Test {",
" public java.util.List foo(List list) {",
" return list;",
" }",
"}")
.addOutputLines(
"Test.java",
"import java.util.List;",
"public class Test {",
" public List foo(List list) {",
" return list;",
" }",
"}")
.doTest();
}

@Test
public void clashesWithTypeInSuperType() {
helper
Expand Down Expand Up @@ -141,11 +163,9 @@ public void builder() {
.addInputLines(
"Test.java",
"package b;",
"import a.Foo;",
"interface Test {",
" a.Foo foo();",
" a.Foo.Builder fooBuilder();",
" Foo.Builder fooBuilder2();",
"}")
.addOutputLines(
"Test.java",
Expand All @@ -154,7 +174,6 @@ public void builder() {
"interface Test {",
" Foo foo();",
" Foo.Builder fooBuilder();",
" Foo.Builder fooBuilder2();",
"}")
.doTest();
}
Expand Down

0 comments on commit 43d7f86

Please sign in to comment.