File tree 2 files changed +30
-4
lines changed
main/java/com/google/errorprone/bugpatterns
test/java/com/google/errorprone/bugpatterns 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 42
42
import com .sun .source .tree .CompilationUnitTree ;
43
43
import com .sun .source .tree .ExpressionTree ;
44
44
import com .sun .source .tree .MethodInvocationTree ;
45
- import com .sun .source .util .TreeScanner ;
46
45
import com .sun .tools .javac .code .Symbol .MethodSymbol ;
47
46
import com .sun .tools .javac .code .Symbol .TypeSymbol ;
48
47
import com .sun .tools .javac .tree .JCTree .JCFieldAccess ;
@@ -157,9 +156,9 @@ private static final class CallSite {
157
156
}
158
157
}
159
158
160
- private static ImmutableList <CallSite > findConstantLookups (ClassTree tree , VisitorState state ) {
159
+ private ImmutableList <CallSite > findConstantLookups (ClassTree tree , VisitorState state ) {
161
160
ImmutableList .Builder <CallSite > result = ImmutableList .builder ();
162
- new TreeScanner <Void , Void >() {
161
+ new SuppressibleTreePathScanner <Void , Void >(state ) {
163
162
@ Override
164
163
public Void visitMethodInvocation (MethodInvocationTree tree , Void unused ) {
165
164
if (CONSTANT_LOOKUP .matches (tree , state )) {
@@ -186,7 +185,7 @@ private void handleConstantLookup(MethodInvocationTree tree) {
186
185
}
187
186
}
188
187
}
189
- }.scan (tree , null );
188
+ }.scan (state . getPath () , null );
190
189
return result .build ();
191
190
}
192
191
Original file line number Diff line number Diff line change @@ -162,4 +162,31 @@ public void negative_doesntMemoizeTwice() {
162
162
.expectUnchanged ()
163
163
.doTest ();
164
164
}
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
+ }
165
192
}
You can’t perform that action at this time.
0 commit comments