Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make MemoizeConstantVisitorStateLookups check suppressible #3691

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}