Skip to content

Commit d6304e3

Browse files
graememorganError Prone Team
authored andcommitted
Fix some TypeToString warnings in UnusedMethod.
PiperOrigin-RevId: 848125045
1 parent 3f40f17 commit d6304e3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/UnusedMethod.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.google.errorprone.fixes.SuggestedFix;
5252
import com.google.errorprone.matchers.Description;
5353
import com.google.errorprone.suppliers.Supplier;
54+
import com.google.errorprone.suppliers.Suppliers;
5455
import com.google.errorprone.util.ASTHelpers;
5556
import com.sun.source.tree.AnnotationTree;
5657
import com.sun.source.tree.AssignmentTree;
@@ -91,10 +92,12 @@
9192
severity = WARNING,
9293
documentSuppression = false)
9394
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");
9597
private static final String EXEMPT_PREFIX = "unused";
9698
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");
98101

99102
/**
100103
* Class annotations which exempt methods within the annotated class from findings.
@@ -173,11 +176,10 @@ private boolean hasJUnitParamsParametersForMethodAnnotation(
173176
for (AnnotationTree tree : annotations) {
174177
JCAnnotation annotation = (JCAnnotation) tree;
175178
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)) {
181183
if (annotation.getArguments().isEmpty()) {
182184
// @Parameters, which uses implicit provider methods
183185
return true;
@@ -222,7 +224,8 @@ private boolean isMethodSymbolEligibleForChecking(
222224
// Ignore this method if the last parameter is a GWT JavaScriptObject.
223225
if (!tree.getParameters().isEmpty()) {
224226
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)) {
226229
return false;
227230
}
228231
}

0 commit comments

Comments
 (0)