| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcheckers.types.AnnotatedTypeFactory
public class AnnotatedTypeFactory extends Object
The methods of this class take an element or AST node, and return the
 annotated type as an AnnotatedTypeMirror.  The methods are:
 
getAnnotatedType(ClassTree)getAnnotatedType(MethodTree)getAnnotatedType(Tree)getAnnotatedTypeFromTypeTree(Tree)getAnnotatedType(TypeElement)getAnnotatedType(ExecutableElement)getAnnotatedType(Element)annotateImplicit(Element, AnnotatedTypeMirror)
 and annotateImplicit(Tree, AnnotatedTypeMirror).
| Modifier and Type | Class and Description | 
|---|---|
| protected static class | AnnotatedTypeFactory.InheritedFromClassAnnotatorA singleton utility class for pulling annotations down from a class type. | 
| Modifier and Type | Field and Description | 
|---|---|
| protected  AnnotationUtils | annotationsThe factory to use for creating annotations. | 
| protected  AnnotatedTypes | atypesUtility class for manipulating annotated types. | 
| protected  Elements | elementsUtility class for working with Elements. | 
| protected  ProcessingEnvironment | envThe processing environment to use for accessing compiler internals. | 
| protected  QualifierHierarchy | qualHierarchyRepresent the annotation relations | 
| protected  CompilationUnitTree | rootoptional! The AST of the source file being operated on | 
| protected  Trees | treesThe Treesinstance to use for tree node path finding. | 
| protected  Types | typesUtility class for working with TypeMirrors. | 
| protected  VisitorState | visitorStatethe state of the visitor | 
| Constructor and Description | 
|---|
| AnnotatedTypeFactory(ProcessingEnvironment env,
                     QualifierHierarchy qualHierarchy,
                     CompilationUnitTree root) | 
| AnnotatedTypeFactory(SourceChecker checker,
                     CompilationUnitTree root)Constructs a factory from the given ProcessingEnvironmentinstance and syntax tree root. | 
| Modifier and Type | Method and Description | |
|---|---|---|
| protected  AnnotationMirror | aliasedAnnotation(AnnotationMirror a)Returns the canonical annotation for the passed annotation if it is an alias of a canonical one in the framework. | |
| protected  void | annotateImplicit(Element elt,
                 AnnotatedTypeMirror type)Adds implicit annotations to a type obtained from a Element. | |
| protected  void | annotateImplicit(Tree tree,
                 AnnotatedTypeMirror type)Adds implicit annotations to a type obtained from a Tree. | |
| protected  void | annotateInheritedFromClass(AnnotatedTypeMirror type)Adds annotations to the type based on the annotations from its class type if and only if no annotations are already present on the type. | |
|  AnnotatedTypeMirror.AnnotatedExecutableType | constructorFromUse(NewClassTree tree)Determines the AnnotatedTypeMirror.AnnotatedExecutableTypeof a constructor
 invocation. | |
| protected static
 | createLRUCache(int size)A Utility method for creating LRU cache | |
| protected  Tree | declarationFromElement(Element elt)Gets the declaration tree for the element, if the source is available. | |
|  AnnotatedTypeMirror.AnnotatedDeclaredType | fromClass(ClassTree tree)Determines the annotated type of a class from its declaration. | |
|  AnnotatedTypeMirror | fromElement(Element elt)Determines the annotated type of an element. | |
|  AnnotatedTypeMirror.AnnotatedExecutableType | fromElement(ExecutableElement elt) | |
|  AnnotatedTypeMirror.AnnotatedDeclaredType | fromElement(TypeElement elt) | |
|  AnnotatedTypeMirror | fromExpression(ExpressionTree tree)Determines the annotated type of an expression. | |
|  AnnotatedTypeMirror | fromMember(Tree tree)Determines the annotated type of a variable or method declaration. | |
|  AnnotatedTypeMirror | fromTypeTree(Tree tree)Determines the annotated type from a type in tree form. | |
|  AnnotatedTypeMirror | fromTypeTree(Tree tree,
             checkers.types.ArrayConvention conv) | |
|  AnnotatedTypeMirror.AnnotatedDeclaredType | getAnnotatedType(ClassTree tree) | |
|  AnnotatedTypeMirror | getAnnotatedType(Element elt)Determines the annotated type of an element using fromElement(Element). | |
|  AnnotatedTypeMirror.AnnotatedExecutableType | getAnnotatedType(ExecutableElement elt) | |
|  AnnotatedTypeMirror | getAnnotatedType(ExpressionTree tree) | |
|  AnnotatedTypeMirror.AnnotatedExecutableType | getAnnotatedType(MethodTree tree) | |
|  AnnotatedTypeMirror.AnnotatedArrayType | getAnnotatedType(NewArrayTree tree) | |
|  AnnotatedTypeMirror.AnnotatedDeclaredType | getAnnotatedType(NewClassTree tree) | |
|  AnnotatedTypeMirror | getAnnotatedType(Tree tree)Determines the annotated type of an AST node. | |
|  AnnotatedTypeMirror.AnnotatedDeclaredType | getAnnotatedType(TypeElement elt) | |
|  AnnotatedTypeMirror | getAnnotatedType(VariableTree tree) | |
|  AnnotatedTypeMirror | getAnnotatedTypeFromTypeTree(Tree tree)Determines the annotated type from a type in tree form. | |
|  AnnotatedTypeMirror.AnnotatedDeclaredType | getBoxedType(AnnotatedTypeMirror.AnnotatedPrimitiveType type)returns the annotated boxed type of the given primitive type. | |
| protected  AnnotatedTypeMirror.AnnotatedDeclaredType | getCurrentClassType(Tree tree)Returns the current class type being visited by the visitor. | |
| protected  AnnotatedTypeMirror.AnnotatedDeclaredType | getCurrentMethodReceiver(Tree tree)Returns the receiver type of the current method being visited, and returns null if the visited tree is not within a method. | |
|  AnnotatedTypeMirror.AnnotatedDeclaredType | getEnclosingType(TypeElement element,
                 Tree tree) | |
| protected  AnnotatedTypeMirror.AnnotatedDeclaredType | getImplicitReceiverType(Tree tree) | |
|  TreePath | getPath(Tree node)Gets the path for the given Treeunder the current root by
 checking from the visitor's current path, and only usingTrees.getPath(CompilationUnitTree, Tree)(which is much slower)
 only ifnodeis not found on the current path. | |
|  QualifierHierarchy | getQualifierHierarchy() | |
|  AnnotatedTypeMirror | getReceiver(ExpressionTree expression)Returns the receiver type of the expression tree, or null if it does not exist. | |
|  AnnotatedTypeMirror.AnnotatedDeclaredType | getSelfType(Tree tree)Returns the type of thisin the current location, which can
 be used ifthishas a special semantics (e.g. | |
|  AnnotatedTypeMirror.AnnotatedPrimitiveType | getUnboxedType(AnnotatedTypeMirror.AnnotatedDeclaredType type)returns the annotated primitive type of the given declared type if it is a boxed declared type. | |
|  VisitorState | getVisitorState()Returns the VisitorState instance used by the factory to infer types | |
| protected  boolean | isMostEnclosingThisDeref(Tree tree) | |
| protected  boolean | isWithinConstructor(Tree tree) | |
|  AnnotatedTypeMirror.AnnotatedExecutableType | methodFromUse(MethodInvocationTree tree)Determines the type of the invoked method based on the passed method invocation tree. | |
| protected  void | postAsMemberOf(AnnotatedTypeMirror type,
               AnnotatedTypeMirror owner,
               Element element)A callback method for the AnnotatedTypeFactory subtypes to customize AnnotatedTypes.asMemberOf(). | |
| protected  void | postDirectSuperTypes(AnnotatedTypeMirror type,
                     List<? extends AnnotatedTypeMirror> supertypes)A callback method for the AnnotatedTypeFactory subtypes to customize directSuperTypes(). | |
| protected  Collection<AnnotationMirror> | unify(Collection<AnnotationMirror> c1,
      Collection<AnnotationMirror> c2)Returns the type qualifiers that are least upper bound for c1 and c2 qualifiers. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
|---|
protected final Trees trees
Trees instance to use for tree node path finding.
@Nullable protected final CompilationUnitTree root
protected final ProcessingEnvironment env
protected final AnnotationUtils annotations
protected final Elements elements
Elements.
protected final Types types
TypeMirrors.
protected final AnnotatedTypes atypes
protected final VisitorState visitorState
@Nullable protected final QualifierHierarchy qualHierarchy
| Constructor Detail | 
|---|
public AnnotatedTypeFactory(SourceChecker checker,
                            @Nullable
                            CompilationUnitTree root)
ProcessingEnvironment
 instance and syntax tree root. (These parameters are required so that
 the factory may conduct the appropriate annotation-gathering analyses on
 certain tree types.)
 Root can be null if the factory does not operate on trees.
checker - the SourceChecker to which this factory belongsroot - the root of the syntax tree that this factory produces
            annotated types forIllegalArgumentException - if either argument is null
public AnnotatedTypeFactory(ProcessingEnvironment env,
                            @Nullable
                            QualifierHierarchy qualHierarchy,
                            @Nullable
                            CompilationUnitTree root)
| Method Detail | 
|---|
public AnnotatedTypeMirror getAnnotatedType(Element elt)
fromElement(Element).
elt - the elementeltIllegalArgumentException - if elt is nullfromElement(Element)public AnnotatedTypeMirror getAnnotatedType(Tree tree)
The type is determined as follows:
tree is a class declaration, determine its type via
    fromClass(com.sun.source.tree.ClassTree)tree is a method or variable declaration, determine its
    type via fromMember(Tree)tree is an ExpressionTree, determine its type
    via fromExpression(ExpressionTree)UnsupportedOperationException
tree - the AST nodetreeUnsupportedOperationException - if an annotated type cannot be
         obtained from treeIllegalArgumentException - if tree is nullfromClass(ClassTree), 
fromMember(Tree), 
fromExpression(ExpressionTree)public AnnotatedTypeMirror getAnnotatedTypeFromTypeTree(Tree tree)
tree - the type treepublic AnnotatedTypeMirror fromElement(Element elt)
elt - the elementpublic AnnotatedTypeMirror.AnnotatedDeclaredType fromClass(ClassTree tree)
tree - the class declarationpublic AnnotatedTypeMirror fromMember(Tree tree)
tree - the variable or method declarationIllegalArgumentException - if tree is not a method or
 variable declarationpublic AnnotatedTypeMirror fromExpression(ExpressionTree tree)
tree - an expressionpublic AnnotatedTypeMirror fromTypeTree(Tree tree)
tree - the type tree
public AnnotatedTypeMirror fromTypeTree(Tree tree,
                                        checkers.types.ArrayConvention conv)
protected void annotateImplicit(Tree tree,
                                @Mutable
                                AnnotatedTypeMirror type)
Tree. By
 default, this method does nothing. Subclasses should use this method to
 implement implicit annotations specific to their type systems.
tree - an AST nodetype - the type obtained from tree
protected void annotateImplicit(Element elt,
                                @Mutable
                                AnnotatedTypeMirror type)
Element. By
 default, this method does nothing. Subclasses should use this method to
 implement implicit annotations specific to their type systems.
elt - an elementtype - the type obtained from elt
protected void postDirectSuperTypes(AnnotatedTypeMirror type,
                                    List<? extends AnnotatedTypeMirror> supertypes)
type annotations to
 supertypes.  This allows the type and its supertypes
 to have the qualifiers, e.g. the supertypes of an Immutable
 type are also Immutable.
type - the type whose supertypes are desiredsupertypes - the supertypes as specified by the base AnnotatedTypeFactory
protected void postAsMemberOf(AnnotatedTypeMirror type,
                              AnnotatedTypeMirror owner,
                              Element element)
type - the annotated type of the elementowner - the annotated type of the receiver of the accessing treeelement - the element of the field or method
protected void annotateInheritedFromClass(@Mutable
                                          AnnotatedTypeMirror type)
type - the type for which class annotations will be inherited if
 there are no annotations already presentprotected AnnotatedTypeMirror.AnnotatedDeclaredType getImplicitReceiverType(Tree tree)
protected final boolean isMostEnclosingThisDeref(Tree tree)
public AnnotatedTypeMirror.AnnotatedDeclaredType getSelfType(Tree tree)
this in the current location, which can
 be used if this has a special semantics (e.g. this
 is non-null)
public AnnotatedTypeMirror.AnnotatedDeclaredType getEnclosingType(TypeElement element,
                                                                  Tree tree)
public final AnnotatedTypeMirror getReceiver(ExpressionTree expression)
expression - public AnnotatedTypeMirror.AnnotatedExecutableType methodFromUse(MethodInvocationTree tree)
AnnotatedTypes.asMemberOf(AnnotatedTypeMirror, Element), and
 customization based on receiver type should be in accordance to its
 specification.
tree - the method invocation treepublic AnnotatedTypeMirror.AnnotatedExecutableType constructorFromUse(NewClassTree tree)
AnnotatedTypeMirror.AnnotatedExecutableType of a constructor
 invocation. Note that this is different than calling
 getAnnotatedType(Tree) or
 fromExpression(ExpressionTree) on the constructor invocation;
 those determine the type of the result of invoking the
 constructor, which is probably an AnnotatedTypeMirror.AnnotatedDeclaredType.
tree - a constructor invocationpublic AnnotatedTypeMirror.AnnotatedDeclaredType getBoxedType(AnnotatedTypeMirror.AnnotatedPrimitiveType type)
type - the primitivate type
public AnnotatedTypeMirror.AnnotatedPrimitiveType getUnboxedType(AnnotatedTypeMirror.AnnotatedDeclaredType type)
                                                          throws IllegalArgumentException
type - the declared typeIllegalArgmentExceptionif - the type given has no unbox conversionIllegalArgumentExceptionpublic VisitorState getVisitorState()
public final AnnotatedTypeMirror.AnnotatedDeclaredType getAnnotatedType(ClassTree tree)
getAnnotatedType(Tree)public final AnnotatedTypeMirror.AnnotatedDeclaredType getAnnotatedType(NewClassTree tree)
getAnnotatedType(Tree)public final AnnotatedTypeMirror.AnnotatedArrayType getAnnotatedType(NewArrayTree tree)
getAnnotatedType(Tree)public final AnnotatedTypeMirror.AnnotatedExecutableType getAnnotatedType(MethodTree tree)
getAnnotatedType(Tree)public final AnnotatedTypeMirror getAnnotatedType(VariableTree tree)
public final AnnotatedTypeMirror getAnnotatedType(ExpressionTree tree)
public final AnnotatedTypeMirror.AnnotatedDeclaredType getAnnotatedType(TypeElement elt)
getAnnotatedType(Element)public final AnnotatedTypeMirror.AnnotatedExecutableType getAnnotatedType(ExecutableElement elt)
getAnnotatedType(Element)public final AnnotatedTypeMirror.AnnotatedDeclaredType fromElement(TypeElement elt)
getAnnotatedType(Element)public final AnnotatedTypeMirror.AnnotatedExecutableType fromElement(ExecutableElement elt)
getAnnotatedType(Element)protected AnnotationMirror aliasedAnnotation(AnnotationMirror a)
protected Collection<AnnotationMirror> unify(Collection<AnnotationMirror> c1,
                                             Collection<AnnotationMirror> c2)
QualifierHierarchy.leastUpperBound(Collection, Collection).
c1 - type qualifiers for the first typec2 - tyep qualifiers for the second typepublic QualifierHierarchy getQualifierHierarchy()
protected final Tree declarationFromElement(Element elt)
elt - an elementprotected final AnnotatedTypeMirror.AnnotatedDeclaredType getCurrentClassType(Tree tree)
protected final AnnotatedTypeMirror.AnnotatedDeclaredType getCurrentMethodReceiver(Tree tree)
protected final boolean isWithinConstructor(Tree tree)
public final TreePath getPath(Tree node)
Tree under the current root by
 checking from the visitor's current path, and only using
 Trees.getPath(CompilationUnitTree, Tree) (which is much slower)
 only if node is not found on the current path.
node - the Tree to get the path fornode under the current rootprotected static <K,V> Map<K,V> createLRUCache(int size)
size - size of the cache| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||