|
51 | 51 | import com.google.errorprone.fixes.SuggestedFix; |
52 | 52 | import com.google.errorprone.matchers.Description; |
53 | 53 | import com.google.errorprone.suppliers.Supplier; |
| 54 | +import com.google.errorprone.suppliers.Suppliers; |
54 | 55 | import com.google.errorprone.util.ASTHelpers; |
55 | 56 | import com.sun.source.tree.AnnotationTree; |
56 | 57 | import com.sun.source.tree.AssignmentTree; |
|
91 | 92 | severity = WARNING, |
92 | 93 | documentSuppression = false) |
93 | 94 | public final class UnusedMethod extends BugChecker implements CompilationUnitTreeMatcher { |
94 | | - private static final String GWT_JAVASCRIPT_OBJECT = "com.google.gwt.core.client.JavaScriptObject"; |
| 95 | + private static final Supplier<Type> GWT_JAVASCRIPT_OBJECT = |
| 96 | + Suppliers.typeFromString("com.google.gwt.core.client.JavaScriptObject"); |
95 | 97 | private static final String EXEMPT_PREFIX = "unused"; |
96 | 98 | private static final String JUNIT_PARAMS_VALUE = "value"; |
97 | | - private static final String JUNIT_PARAMS_ANNOTATION_TYPE = "junitparams.Parameters"; |
| 99 | + private static final Supplier<Type> JUNIT_PARAMS_ANNOTATION_TYPE = |
| 100 | + Suppliers.typeFromString("junitparams.Parameters"); |
98 | 101 |
|
99 | 102 | /** |
100 | 103 | * Class annotations which exempt methods within the annotated class from findings. |
@@ -173,11 +176,10 @@ private boolean hasJUnitParamsParametersForMethodAnnotation( |
173 | 176 | for (AnnotationTree tree : annotations) { |
174 | 177 | JCAnnotation annotation = (JCAnnotation) tree; |
175 | 178 | if (annotation.getAnnotationType().type != null |
176 | | - && annotation |
177 | | - .getAnnotationType() |
178 | | - .type |
179 | | - .toString() |
180 | | - .equals(JUNIT_PARAMS_ANNOTATION_TYPE)) { |
| 179 | + && isSubtype( |
| 180 | + annotation.getAnnotationType().type, |
| 181 | + JUNIT_PARAMS_ANNOTATION_TYPE.get(state), |
| 182 | + state)) { |
181 | 183 | if (annotation.getArguments().isEmpty()) { |
182 | 184 | // @Parameters, which uses implicit provider methods |
183 | 185 | return true; |
@@ -222,7 +224,8 @@ private boolean isMethodSymbolEligibleForChecking( |
222 | 224 | // Ignore this method if the last parameter is a GWT JavaScriptObject. |
223 | 225 | if (!tree.getParameters().isEmpty()) { |
224 | 226 | Type lastParamType = getType(getLast(tree.getParameters())); |
225 | | - if (lastParamType != null && lastParamType.toString().equals(GWT_JAVASCRIPT_OBJECT)) { |
| 227 | + if (lastParamType != null |
| 228 | + && isSubtype(lastParamType, GWT_JAVASCRIPT_OBJECT.get(state), state)) { |
226 | 229 | return false; |
227 | 230 | } |
228 | 231 | } |
|
0 commit comments