Skip to content

Commit

Permalink
Handle classes with explicit enclosing instances in `DifferentNameBut…
Browse files Browse the repository at this point in the history
…Same`

Fixes #2094

PiperOrigin-RevId: 351915750
  • Loading branch information
cushon authored and Error Prone Team committed Jan 15, 2021
1 parent 7a65117 commit a7f3413
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.sun.source.tree.ImportTree;
import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.NewClassTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.VariableTree;
import com.sun.source.util.TreePath;
Expand Down Expand Up @@ -107,6 +108,15 @@ public Void visitMemberSelect(MemberSelectTree memberSelectTree, Void unused) {

@Override
public Void visitIdentifier(IdentifierTree identifierTree, Void unused) {
Tree parent = getCurrentPath().getParentPath().getLeaf();
if (parent instanceof NewClassTree) {
NewClassTree newClassTree = (NewClassTree) parent;
if (newClassTree.getIdentifier().equals(identifierTree)
&& newClassTree.getEnclosingExpression() != null) {
// don't try to fix instantiations with explicit enclosing instances, e.g. `a.new B();`
return null;
}
}
handle(identifierTree);
return super.visitIdentifier(identifierTree, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.google.errorprone.bugpatterns;

import com.google.errorprone.BugCheckerRefactoringTestHelper;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -311,7 +310,6 @@ public void classClashesWithVariableName() {
.doTest();
}

@Ignore("b/177381438")
@Test
public void innerClassConstructor() {
BugCheckerRefactoringTestHelper.newInstance(new DifferentNameButSame(), getClass())
Expand Down

0 comments on commit a7f3413

Please sign in to comment.