checkers.types
Class AnnotatedTypes

java.lang.Object
  extended by checkers.types.AnnotatedTypes

public class AnnotatedTypes
extends Object

Utility methods for operating on AnnotatedTypeMirror. This class mimics the class Types.


Constructor Summary
Constructor and Description
AnnotatedTypes(ProcessingEnvironment env, AnnotatedTypeFactory factory)
          Constructor for AnnotatedTypes
 
Method Summary
Modifier and Type Method and Description
 void annotateAsLub(AnnotatedTypeMirror lub, AnnotatedTypeMirror... types)
          Annotate the lub type as if it is the least upper bound of the rest of the types.
 boolean areSame(AnnotatedTypeMirror t1, AnnotatedTypeMirror t2)
           
 AnnotatedTypeMirror asMemberOf(AnnotatedTypeMirror t, Element elem)
          Returns the type of an element when that element is viewed as a member of, or otherwise directly contained by, a given type.
 AnnotatedTypeMirror.AnnotatedExecutableType asMemberOf(AnnotatedTypeMirror t, ExecutableElement elem)
           
 AnnotatedTypeMirror assignedTo(TreePath path)
          Returns the annotated type that the leaf of path is assigned to, if it is within an assignment context Returns the annotated type that the method invocation at the leaf is assigned to.
 AnnotatedTypeMirror asSuper(AnnotatedTypeMirror t, AnnotatedTypeMirror superType)
          Returns the most specific base type of t whose erasure type is superType.
 AnnotatedTypeMirror deepCopy(AnnotatedTypeMirror type)
          Returns a deep copy of the passed type
 List<AnnotatedTypeMirror> expandVarArgs(AnnotatedTypeMirror.AnnotatedExecutableType method, List<? extends ExpressionTree> args)
          Returns the method parameters for the invoked method, with the same number of arguments passed in the methodInvocation tree.
 Map<AnnotatedTypeMirror.AnnotatedTypeVariable,AnnotatedTypeMirror> findTypeArguments(MethodInvocationTree methodInvocation)
          Given a method method invocation, it returns a mapping of the type variables to their parameters if any exist.
 List<AnnotatedTypeMirror> getAnnotatedTypes(Iterable<? extends ExpressionTree> trees)
          Return a list of the AnnotatedTypeMirror of the passed expression trees, in the same order as the trees.
 int getArrayDepth(AnnotatedTypeMirror.AnnotatedArrayType array)
          Returns the depth of the array type of the provided array.
 AnnotatedTypeMirror getIteratedType(AnnotatedTypeMirror iterableType)
          Returns the iterated type of the passed iterable type, and throws IllegalArgumentException if the passed type is not iterable.
 Set<AnnotatedTypeMirror.AnnotatedDeclaredType> getSuperTypes(AnnotatedTypeMirror.AnnotatedDeclaredType type)
          Returns all the super types of the given declared type.
static AnnotatedTypeMirror innerMostType(AnnotatedTypeMirror t)
           
 boolean isAnonymousType(AnnotatedTypeMirror type)
          Determines if the type is for an anonymous type or not
 boolean isIntersectType(AnnotatedTypeMirror type)
          Determines if the type is for an intersect type or not
 Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> overriddenMethods(ExecutableElement method)
          A utility method that takes a Method element and returns a set of all elements that this method overrides (as ExecutableElements)
 Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> overriddenMethods(ExecutableElement method, Collection<AnnotatedTypeMirror.AnnotatedDeclaredType> supertypes)
          A utility method that takes the element for a method and the set of all supertypes of the method's containing class and returns the set of all elements that method overrides (as ExecutableElements).
 AnnotatedTypeMirror subst(AnnotatedTypeMirror t, List<? extends AnnotatedTypeMirror> from, List<? extends AnnotatedTypeMirror> to)
          Returns a new type, a copy of the passed t, with all instances of from type substituted with their correspondents in to.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AnnotatedTypes

public AnnotatedTypes(ProcessingEnvironment env,
                      AnnotatedTypeFactory factory)
Constructor for AnnotatedTypes

Parameters:
env - the processing environment for this round
Method Detail

toString

public String toString()
Overrides:
toString in class Object

asSuper

public AnnotatedTypeMirror asSuper(AnnotatedTypeMirror t,
                                   AnnotatedTypeMirror superType)
Returns the most specific base type of t whose erasure type is superType. It returns null if t is not a subtype of superType.

Parameters:
t - a type
superType - a type that is a supertype of t
Returns:
the base type of t of the given element

asMemberOf

public AnnotatedTypeMirror.AnnotatedExecutableType asMemberOf(AnnotatedTypeMirror t,
                                                              ExecutableElement elem)
See Also:
asMemberOf(AnnotatedTypeMirror, Element)

asMemberOf

public AnnotatedTypeMirror asMemberOf(AnnotatedTypeMirror t,
                                      Element elem)
Returns the type of an element when that element is viewed as a member of, or otherwise directly contained by, a given type. For example, when viewed as a member of the parameterized type Set<@NonNull String>, the Set.add method is an ExecutableType whose parameter is of type @NonNull String. The result is customized according to the type system semantics, according to AnnotatedTypeFactory.postAsMemberOf( AnnotatedTypeMirror, AnnotatedTypeMirror, Element).

Parameters:
t - a type
elem - an element

subst

public AnnotatedTypeMirror subst(AnnotatedTypeMirror t,
                                 List<? extends AnnotatedTypeMirror> from,
                                 List<? extends AnnotatedTypeMirror> to)
Returns a new type, a copy of the passed t, with all instances of from type substituted with their correspondents in to.

Parameters:
t - the type
from - the from types
to - the to types
Returns:
the new type after substitutions

deepCopy

public AnnotatedTypeMirror deepCopy(AnnotatedTypeMirror type)
Returns a deep copy of the passed type

Parameters:
type - the annotated type to be copied
Returns:
a deep copy of the passed type

getIteratedType

public AnnotatedTypeMirror getIteratedType(AnnotatedTypeMirror iterableType)
Returns the iterated type of the passed iterable type, and throws IllegalArgumentException if the passed type is not iterable. The iterated type is the component type of an array, and the type argument of Iterable for declared types.

Parameters:
iterableType - the iterable type (either array or declared)
Returns:
the types of elements in the iterable type

getSuperTypes

public Set<AnnotatedTypeMirror.AnnotatedDeclaredType> getSuperTypes(AnnotatedTypeMirror.AnnotatedDeclaredType type)
Returns all the super types of the given declared type.

Parameters:
type - a declared type
Returns:
all the supertypes of the given type

overriddenMethods

public Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> overriddenMethods(ExecutableElement method)
A utility method that takes a Method element and returns a set of all elements that this method overrides (as ExecutableElements)

Parameters:
method - the overriding method
Returns:
an unmodifiable set of ExecutableElements representing the elements that method overrides

overriddenMethods

public Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> overriddenMethods(ExecutableElement method,
                                                                                          Collection<AnnotatedTypeMirror.AnnotatedDeclaredType> supertypes)
A utility method that takes the element for a method and the set of all supertypes of the method's containing class and returns the set of all elements that method overrides (as ExecutableElements).

Parameters:
method - the overriding method
supertypes - the set of supertypes to check for methods that are overriden by method
Returns:
an unmodified set of ExecutableElements representing the elements that method overrides among supertypes

findTypeArguments

public Map<AnnotatedTypeMirror.AnnotatedTypeVariable,AnnotatedTypeMirror> findTypeArguments(MethodInvocationTree methodInvocation)
Given a method method invocation, it returns a mapping of the type variables to their parameters if any exist. It uses the method invocation type parameters if specified, otherwise it infers them based the passed arguments or the return type context, according to JLS 15.12.2.

Parameters:
methodInvocation - the method invocation tree
Returns:
the mapping of the type variables for this method invocation

assignedTo

public AnnotatedTypeMirror assignedTo(TreePath path)
Returns the annotated type that the leaf of path is assigned to, if it is within an assignment context Returns the annotated type that the method invocation at the leaf is assigned to.

Parameters:
path -
Returns:
type that it path leaf is assigned to

isAnonymousType

public boolean isAnonymousType(AnnotatedTypeMirror type)
Determines if the type is for an anonymous type or not

Parameters:
type - type to be checked
Returns:
true iff type is an anonymous type

isIntersectType

public boolean isIntersectType(AnnotatedTypeMirror type)
Determines if the type is for an intersect type or not

Parameters:
type - type to be checked
Returns:
true iff type is an intersect type

annotateAsLub

public void annotateAsLub(AnnotatedTypeMirror lub,
                          AnnotatedTypeMirror... types)
Annotate the lub type as if it is the least upper bound of the rest of the types. This is a useful method for the finding conditional expression types. All the types need to be subtypes of lub.

Parameters:
lub - the type to be the least upper bound
types - the type arguments

getArrayDepth

public int getArrayDepth(AnnotatedTypeMirror.AnnotatedArrayType array)
Returns the depth of the array type of the provided array.

Parameters:
array - the type of the array
Returns:
the depth of the provided array

expandVarArgs

public List<AnnotatedTypeMirror> expandVarArgs(AnnotatedTypeMirror.AnnotatedExecutableType method,
                                               List<? extends ExpressionTree> args)
Returns the method parameters for the invoked method, with the same number of arguments passed in the methodInvocation tree. If the invoked method is not a vararg method or it is a vararg method but the invocation passes an array to the vararg parameter, it would simply return the method parameters. Otherwise, it would return the list of parameters as if the vararg is expanded to match the size of the passed arguments.

Parameters:
method - the method's type
args - the arguments to the method invocation
Returns:
the types that the method invocation arguments need to be subtype of

getAnnotatedTypes

public List<AnnotatedTypeMirror> getAnnotatedTypes(Iterable<? extends ExpressionTree> trees)
Return a list of the AnnotatedTypeMirror of the passed expression trees, in the same order as the trees.

Parameters:
trees - the AST nodes
Returns:
a list with the AnnotatedTypeMirror of each tree in trees.

areSame

public boolean areSame(AnnotatedTypeMirror t1,
                       AnnotatedTypeMirror t2)

innerMostType

public static AnnotatedTypeMirror innerMostType(AnnotatedTypeMirror t)