Class AbstractCollectionIncompatibleTypeMatcher
- java.lang.Object
-
- com.google.errorprone.bugpatterns.collectionincompatibletype.AbstractCollectionIncompatibleTypeMatcher
-
public abstract class AbstractCollectionIncompatibleTypeMatcher extends Object
Extracts the necessary information from aMethodInvocationTree
to check whether calls to a method are using incompatible types and to emit a helpful error message.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractCollectionIncompatibleTypeMatcher.MatchResult
Encapsulates the result of matching aCollection.contains(java.lang.Object)
-like call, including the source and target types.
-
Constructor Summary
Constructors Constructor Description AbstractCollectionIncompatibleTypeMatcher()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static com.sun.tools.javac.code.Type
extractTypeArgAsMemberOfSupertype(com.sun.tools.javac.code.Type type, com.sun.tools.javac.code.Symbol superTypeSym, int typeArgIndex, com.sun.tools.javac.code.Types types)
Extracts the appropriate type argument from a specific supertype of the giventype
.AbstractCollectionIncompatibleTypeMatcher.MatchResult
matches(com.sun.source.tree.ExpressionTree tree, VisitorState state)
protected String
message(AbstractCollectionIncompatibleTypeMatcher.MatchResult result, String sourceType, String targetType)
-
-
-
Method Detail
-
matches
@Nullable public final AbstractCollectionIncompatibleTypeMatcher.MatchResult matches(com.sun.source.tree.ExpressionTree tree, VisitorState state)
-
extractTypeArgAsMemberOfSupertype
@Nullable protected static com.sun.tools.javac.code.Type extractTypeArgAsMemberOfSupertype(com.sun.tools.javac.code.Type type, com.sun.tools.javac.code.Symbol superTypeSym, int typeArgIndex, com.sun.tools.javac.code.Types types)
Extracts the appropriate type argument from a specific supertype of the giventype
. This handles the case when a subtype has different type arguments than the expected type. For example,ClassToInstanceMap<T>
implementsMap<Class<? extends T>, T>
.- Parameters:
type
- the (sub)type from which to extract the type argumentsuperTypeSym
- the symbol of the supertype on which the type parameter is definedtypeArgIndex
- the index of the type argument to extract from the supertypetypes
- theTypes
utility class from theVisitorState
- Returns:
- the type argument, if defined, or null otherwise
-
message
protected String message(AbstractCollectionIncompatibleTypeMatcher.MatchResult result, String sourceType, String targetType)
-
-