Skip to content

Commit

Permalink
Make MemoizeConstantVisitorStateLookups check suppressible
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Jan 5, 2023
1 parent 8d518bf commit 0adb67b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.source.util.TreeScanner;
import com.sun.tools.javac.code.Symbol.MethodSymbol;
import com.sun.tools.javac.code.Symbol.TypeSymbol;
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
Expand Down Expand Up @@ -157,9 +156,9 @@ private static final class CallSite {
}
}

private static ImmutableList<CallSite> findConstantLookups(ClassTree tree, VisitorState state) {
private ImmutableList<CallSite> findConstantLookups(ClassTree tree, VisitorState state) {
ImmutableList.Builder<CallSite> result = ImmutableList.builder();
new TreeScanner<Void, Void>() {
new SuppressibleTreePathScanner<Void, Void>(state) {
@Override
public Void visitMethodInvocation(MethodInvocationTree tree, Void unused) {
if (CONSTANT_LOOKUP.matches(tree, state)) {
Expand All @@ -186,7 +185,7 @@ private void handleConstantLookup(MethodInvocationTree tree) {
}
}
}
}.scan(tree, null);
}.scan(state.getPath(), null);
return result.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,31 @@ public void negative_doesntMemoizeTwice() {
.expectUnchanged()
.doTest();
}

@Test
public void testSuppressWarnings() {
compilationTestHelper
.addSourceLines(
"Test.java",
"import com.google.errorprone.VisitorState;",
"import com.sun.tools.javac.code.Type;",
"import com.sun.tools.javac.util.Name;",
"class Test {",
" @SuppressWarnings(\"MemoizeConstantVisitorStateLookups\")",
" public Test(VisitorState state) {",
" Name className = state.getName(\"java.lang.Class\");",
" }",
" @SuppressWarnings(\"MemoizeConstantVisitorStateLookups\")",
" public void testMethod(VisitorState state) {",
" Name className = state.getName(\"java.lang.Class\");",
" }",
" @SuppressWarnings(\"MemoizeConstantVisitorStateLookups\")",
" class InnerClass {",
" void innerMethod(VisitorState state) {",
" Name className = state.getName(\"java.lang.Class\");",
" }",
" }",
"}")
.doTest();
}
}

0 comments on commit 0adb67b

Please sign in to comment.