Class AbstractCollectionIncompatibleTypeMatcher
java.lang.Object
com.google.errorprone.bugpatterns.collectionincompatibletype.AbstractCollectionIncompatibleTypeMatcher
Extracts the necessary information from a
MethodInvocationTree
to check whether calls to
a method are using incompatible types and to emit a helpful error message.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Encapsulates the result of matching aCollection.contains(java.lang.Object)
-like call, including the source and target types. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static @Nullable 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
.final @Nullable AbstractCollectionIncompatibleTypeMatcher.MatchResult
matches
(com.sun.source.tree.ExpressionTree tree, VisitorState state) protected String
message
(AbstractCollectionIncompatibleTypeMatcher.MatchResult result, String sourceType, String targetType)
-
Constructor Details
-
AbstractCollectionIncompatibleTypeMatcher
public AbstractCollectionIncompatibleTypeMatcher()
-
-
Method Details
-
matches
public final @Nullable AbstractCollectionIncompatibleTypeMatcher.MatchResult matches(com.sun.source.tree.ExpressionTree tree, VisitorState state) -
extractTypeArgAsMemberOfSupertype
protected static @Nullable 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)
-