File tree Expand file tree Collapse file tree
main/java/com/google/errorprone/bugpatterns
test/java/com/google/errorprone/bugpatterns Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4242import com .sun .source .tree .CompilationUnitTree ;
4343import com .sun .source .tree .ExpressionTree ;
4444import com .sun .source .tree .MethodInvocationTree ;
45- import com .sun .source .util .TreeScanner ;
4645import com .sun .tools .javac .code .Symbol .MethodSymbol ;
4746import com .sun .tools .javac .code .Symbol .TypeSymbol ;
4847import com .sun .tools .javac .tree .JCTree .JCFieldAccess ;
@@ -157,9 +156,9 @@ private static final class CallSite {
157156 }
158157 }
159158
160- private static ImmutableList <CallSite > findConstantLookups (ClassTree tree , VisitorState state ) {
159+ private ImmutableList <CallSite > findConstantLookups (ClassTree tree , VisitorState state ) {
161160 ImmutableList .Builder <CallSite > result = ImmutableList .builder ();
162- new TreeScanner <Void , Void >() {
161+ new SuppressibleTreePathScanner <Void , Void >(state ) {
163162 @ Override
164163 public Void visitMethodInvocation (MethodInvocationTree tree , Void unused ) {
165164 if (CONSTANT_LOOKUP .matches (tree , state )) {
@@ -186,7 +185,7 @@ private void handleConstantLookup(MethodInvocationTree tree) {
186185 }
187186 }
188187 }
189- }.scan (tree , null );
188+ }.scan (state . getPath () , null );
190189 return result .build ();
191190 }
192191
Original file line number Diff line number Diff line change @@ -162,4 +162,31 @@ public void negative_doesntMemoizeTwice() {
162162 .expectUnchanged ()
163163 .doTest ();
164164 }
165+
166+ @ Test
167+ public void testSuppressWarnings () {
168+ compilationTestHelper
169+ .addSourceLines (
170+ "Test.java" ,
171+ "import com.google.errorprone.VisitorState;" ,
172+ "import com.sun.tools.javac.code.Type;" ,
173+ "import com.sun.tools.javac.util.Name;" ,
174+ "class Test {" ,
175+ " @SuppressWarnings(\" MemoizeConstantVisitorStateLookups\" )" ,
176+ " public Test(VisitorState state) {" ,
177+ " Name className = state.getName(\" java.lang.Class\" );" ,
178+ " }" ,
179+ " @SuppressWarnings(\" MemoizeConstantVisitorStateLookups\" )" ,
180+ " public void testMethod(VisitorState state) {" ,
181+ " Name className = state.getName(\" java.lang.Class\" );" ,
182+ " }" ,
183+ " @SuppressWarnings(\" MemoizeConstantVisitorStateLookups\" )" ,
184+ " class InnerClass {" ,
185+ " void innerMethod(VisitorState state) {" ,
186+ " Name className = state.getName(\" java.lang.Class\" );" ,
187+ " }" ,
188+ " }" ,
189+ "}" )
190+ .doTest ();
191+ }
165192}
You can’t perform that action at this time.
0 commit comments