public class TypeArgInferenceUtil extends Object
Constructor and Description |
---|
TypeArgInferenceUtil() |
Modifier and Type | Method and Description |
---|---|
static AnnotatedTypeMirror |
assignedTo(AnnotatedTypeFactory atypeFactory,
TreePath path)
Returns the annotated type that the leaf of path is assigned to, if it is within an
assignment context.
|
static AnnotatedTypeMirror |
assignedToVariable(AnnotatedTypeFactory atypeFactory,
Tree assignmentContext)
If the variable's type is a type variable, return getAnnotatedTypeLhsNoTypeVarDefault(tree).
|
static void |
checkForUninferredTypes(AnnotatedTypeMirror type)
Checks that the type is not an uninferred type argument.
|
static boolean |
containsTypeParameter(AnnotatedTypeMirror type,
Collection<TypeVariable> typeVariables)
Returns true if
type contains a use of a type variable in typeVariables . |
static AnnotationMirrorMap<AnnotationMirror> |
createHierarchyMap(AnnotationMirrorSet annos,
QualifierHierarchy qualifierHierarchy)
Take a set of annotations and separate them into a mapping of (
hierarchy top ⇒
annotations in hierarchy ) |
static List<AnnotatedTypeMirror> |
getArgumentTypes(ExpressionTree methodInvocation,
AnnotatedTypeFactory typeFactory)
Returns a list of boxed annotated types corresponding to the arguments in
methodInvocation . |
static boolean |
isATarget(AnnotatedTypeMirror type,
Set<TypeVariable> targetTypeVars)
Given a set of type variables for which we are inferring a type, returns true if type is a
use of a type variable in the list of targetTypeVars.
|
static AnnotatedTypeMirror |
leastUpperBound(AnnotatedTypeFactory typeFactory,
Iterable<AnnotatedTypeMirror> types)
Successively calls least upper bound on the elements of types.
|
static Set<TypeVariable> |
methodTypeToTargets(AnnotatedTypeMirror.AnnotatedExecutableType methodType)
Given an AnnotatedExecutableType return a set of type variables that represents the generic
type parameters of that method
|
static AnnotatedTypeMirror |
substitute(Map<TypeVariable,AnnotatedTypeMirror> substitutions,
AnnotatedTypeMirror toModify)
Create a copy of toModify.
|
static AnnotatedTypeMirror |
substitute(TypeVariable typeVariable,
AnnotatedTypeMirror substitution,
AnnotatedTypeMirror toModify)
Replace all uses of typeVariable with substitution in a copy of toModify using the normal
substitution rules, (@see TypeVariableSubstitutor).Return the copy
|
public static List<AnnotatedTypeMirror> getArgumentTypes(ExpressionTree methodInvocation, AnnotatedTypeFactory typeFactory)
methodInvocation
.methodInvocation
- MethodInvocationTree
or NewClassTree
typeFactory
- type factorymethodInvocation
.public static boolean isATarget(AnnotatedTypeMirror type, Set<TypeVariable> targetTypeVars)
public static Set<TypeVariable> methodTypeToTargets(AnnotatedTypeMirror.AnnotatedExecutableType methodType)
public static AnnotatedTypeMirror assignedTo(AnnotatedTypeFactory atypeFactory, TreePath path)
public static AnnotatedTypeMirror assignedToVariable(AnnotatedTypeFactory atypeFactory, Tree assignmentContext)
For example:
<S> S bar () {...}
<T> T foo(T p) {
T local = bar();
return local;
}
During type argument inference of bar
, the assignment context is local
. If
the local variable default is used, then the type of assignment context type is
@Nullable T
and the type argument inferred for bar()
is @Nullable T
.
And an incompatible types in return error is issued.
If instead, the local variable default is not applied, then the assignment context type is
T
(with lower bound @NonNull Void
and upper bound @Nullable Object
)
and the type argument inferred for bar()
is T
. During dataflow, the type of
local
is refined to T
and the return is legal.
If the assignment context type was a declared type, for example:
<S> S bar () {...}
Object foo() {
Object local = bar();
return local;
}
The local variable default must be used or else the assignment context type is missing an
annotation. So, an incompatible types in return error is issued in the above code. We could
improve type argument inference in this case and by using the lower bound of S
instead of the local variable default.atypeFactory
- AnnotatedTypeFactoryassignmentContext
- VariableTreepublic static boolean containsTypeParameter(AnnotatedTypeMirror type, Collection<TypeVariable> typeVariables)
type
contains a use of a type variable in typeVariables
.type
- type to searchtypeVariables
- collection of type variblestype
contains a use of a type variable in typeVariables
public static AnnotationMirrorMap<AnnotationMirror> createHierarchyMap(AnnotationMirrorSet annos, QualifierHierarchy qualifierHierarchy)
hierarchy top ⇒
annotations in hierarchy
)public static void checkForUninferredTypes(AnnotatedTypeMirror type)
public static AnnotatedTypeMirror substitute(TypeVariable typeVariable, AnnotatedTypeMirror substitution, AnnotatedTypeMirror toModify)
public static AnnotatedTypeMirror substitute(Map<TypeVariable,AnnotatedTypeMirror> substitutions, AnnotatedTypeMirror toModify)
typeVariable ⇒ annotated
type
replace uses of typeVariable with the corresponding annotated type using normal
substitution rules (@see TypeVariableSubstitutor) Return the copypublic static AnnotatedTypeMirror leastUpperBound(AnnotatedTypeFactory typeFactory, Iterable<AnnotatedTypeMirror> types)