|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object checkers.types.AnnotatedTypeFactory
public class AnnotatedTypeFactory
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)
.
Field Summary | |
---|---|
protected AnnotationUtils |
annotations
The factory to use for creating annotations. |
protected AnnotatedTypes |
atypes
Utility class for manipulating annotated types. |
protected Elements |
elements
Utility class for working with Element s. |
protected ProcessingEnvironment |
env
The processing environment to use for accessing compiler internals. |
protected QualifierHierarchy |
qualHierarchy
Represent the annotation relations |
protected CompilationUnitTree |
root
optional! The AST of the source file being operated on |
protected Trees |
trees
The Trees instance to use for tree node path finding. |
protected Types |
types
Utility class for working with TypeMirror s. |
protected VisitorState |
visitorState
the state of the visitor |
Constructor Summary | |
---|---|
AnnotatedTypeFactory(ProcessingEnvironment env,
QualifierHierarchy qualHierarchy,
CompilationUnitTree root)
|
|
AnnotatedTypeFactory(SourceChecker checker,
CompilationUnitTree root)
Constructs a factory from the given ProcessingEnvironment
instance and syntax tree root. |
Method Summary | ||
---|---|---|
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.AnnotatedExecutableType of 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 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. |
|
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 this in the current location, which can
be used if this has 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)
|
|
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.
protected final CompilationUnitTree root
protected final ProcessingEnvironment env
protected final AnnotationUtils annotations
protected final Elements elements
Element
s.
protected final Types types
TypeMirror
s.
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 for
IllegalArgumentException
- 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 element
elt
IllegalArgumentException
- 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 node
tree
UnsupportedOperationException
- if an annotated type cannot be
obtained from tree
IllegalArgumentException
- if tree
is nullfromClass(ClassTree)
,
fromMember(Tree)
,
fromExpression(ExpressionTree)
public AnnotatedTypeMirror getAnnotatedTypeFromTypeTree(Tree tree)
tree
- the type tree
public AnnotatedTypeMirror fromElement(Element elt)
elt
- the element
public AnnotatedTypeMirror.AnnotatedDeclaredType fromClass(ClassTree tree)
tree
- the class declaration
public AnnotatedTypeMirror fromMember(Tree tree)
tree
- the variable or method declaration
IllegalArgumentException
- if tree
is not a method or
variable declarationpublic AnnotatedTypeMirror fromExpression(ExpressionTree tree)
tree
- an expression
public 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 AnnotatedTypeFactoryprotected 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 methodprotected 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 tree
public 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 invocation
public AnnotatedTypeMirror.AnnotatedDeclaredType getBoxedType(AnnotatedTypeMirror.AnnotatedPrimitiveType type)
type
- the primitivate type
public AnnotatedTypeMirror.AnnotatedPrimitiveType getUnboxedType(AnnotatedTypeMirror.AnnotatedDeclaredType type) throws IllegalArgumentException
type
- the declared type
IllegalArgmentExceptionif
- the type given has no unbox conversion
IllegalArgumentException
public 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 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 type
public QualifierHierarchy getQualifierHierarchy()
protected final Tree declarationFromElement(Element elt)
elt
- an element
protected final AnnotatedTypeMirror.AnnotatedDeclaredType getCurrentClassType(Tree tree)
protected final AnnotatedTypeMirror.AnnotatedDeclaredType getCurrentMethodReceiver(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 for
node
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 |