From 82ee5e6b049ac6cd601f7493e66805751fb1aec1 Mon Sep 17 00:00:00 2001 From: Eddie Aftandilian Date: Fri, 7 Sep 2012 15:19:48 -0700 Subject: [PATCH] Done with getType -- create arbitrary Types for matchers --- .../main/java/com/google/errorprone/VisitorState.java | 9 +++++---- .../com/google/errorprone/bugpatterns/ArrayEquals.java | 6 ++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/google/errorprone/VisitorState.java b/core/src/main/java/com/google/errorprone/VisitorState.java index 6f84fe9df2b..91a1036be8b 100644 --- a/core/src/main/java/com/google/errorprone/VisitorState.java +++ b/core/src/main/java/com/google/errorprone/VisitorState.java @@ -154,6 +154,11 @@ public Name getName(String nameStr) { * Given the string representation of a simple (non-array, non-generic) type, return the * matching Type. * + *

If this method returns null, the compiler has not seen this type yet, which means that if + * you are comparing other types to this for equality or the subtype relation, your result would + * always be false even if it could create the type. Thus it might be best to bail out early in + * your matcher if this method returns null on your type of interest. + * * @param typeStr The canonical string representation of a simple type (e.g., "java.lang.Object") * @return The Type that corresponds to the string, or null if it cannot be found */ @@ -258,8 +263,4 @@ private static boolean isPrimitiveType(String typeStr) { private interface NameLookupStrategy { Name fromString(Context context, String nameStr); } - - public class TypeBuilder { - - } } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ArrayEquals.java b/core/src/main/java/com/google/errorprone/bugpatterns/ArrayEquals.java index c5d947b4aed..d21df52885d 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/ArrayEquals.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/ArrayEquals.java @@ -33,8 +33,6 @@ import static com.google.errorprone.matchers.Matchers.*; /** - * TODO(eaftan): tests -- more positive cases, start negative cases - * * @author eaftan@google.com (Eddie Aftandilian) */ @BugPattern(name = "ArrayEquals", @@ -75,11 +73,11 @@ public Description describe(MethodInvocationTree t, VisitorState state) { } public static class Scanner extends com.google.errorprone.Scanner { - public DescribingMatcher matcher = new ArrayEquals(); + public DescribingMatcher scannerMatcher = new ArrayEquals(); @Override public Void visitMethodInvocation(MethodInvocationTree node, VisitorState visitorState) { - evaluateMatch(node, visitorState, matcher); + evaluateMatch(node, visitorState, scannerMatcher); return super.visitMethodInvocation(node, visitorState); } }