public class AnnotatedTypeFactory extends java.lang.Object implements AnnotationProvider
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.InheritedFromClassAnnotator
A singleton utility class for pulling annotations down from a class
type.
|
Modifier and Type | Field and Description |
---|---|
protected BaseTypeChecker |
checker
The checker to use for option handling and resource management.
|
protected javax.lang.model.util.Elements |
elements
Utility class for working with
Element s. |
protected java.util.Map<com.sun.source.tree.Tree,AnnotatedTypeMirror> |
fromTreeCache
Mapping from a Tree to its annotated type; before implicits are applied,
just what the programmer wrote.
|
protected javax.annotation.processing.ProcessingEnvironment |
processingEnv
The processing environment to use for accessing compiler internals.
|
protected QualifierHierarchy |
qualHierarchy
Represent the annotation relations.
|
protected @Nullable com.sun.source.tree.CompilationUnitTree |
root
Optional! The AST of the source file being operated on.
|
protected static boolean |
SHOULD_CACHE
Should results be cached? Disable for better debugging.
|
protected static boolean |
SHOULD_READ_CACHE
Should the cached result be used, or should it be freshly computed?
|
boolean |
shouldCache |
boolean |
shouldReadCache |
protected com.sun.source.util.Trees |
trees
The
Trees instance to use for tree node path finding. |
protected TypeHierarchy |
typeHierarchy
Represent the type relations.
|
protected javax.lang.model.util.Types |
types
Utility class for working with
TypeMirror s. |
int |
uid
Unique ID of the current object; for debugging purposes.
|
protected VisitorState |
visitorState
The state of the visitor.
|
Constructor and Description |
---|
AnnotatedTypeFactory(BaseTypeChecker checker)
Constructs a factory from the given
ProcessingEnvironment
instance and syntax tree root. |
Modifier and Type | Method and Description |
---|---|
protected void |
addAliasedAnnotation(java.lang.Class<?> alias,
javax.lang.model.element.AnnotationMirror type)
Add the annotation clazz as an alias for the annotation type.
|
protected void |
addAliasedDeclAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> alias,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
javax.lang.model.element.AnnotationMirror annotationToUse)
Add the annotation
alias as an alias for the declaration
annotation annotation , where the annotation mirror
annoationToUse will be used instead. |
@Nullable javax.lang.model.element.AnnotationMirror |
aliasedAnnotation(javax.lang.model.element.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(javax.lang.model.element.Element elt,
@Mutable AnnotatedTypeMirror type)
Adds implicit annotations to a type obtained from a
Element . |
void |
annotateImplicit(com.sun.source.tree.Tree tree,
@Mutable AnnotatedTypeMirror type)
Adds implicit annotations to a type obtained from a
Tree . |
protected void |
annotateInheritedFromClass(@Mutable 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.
|
protected void |
annotateInheritedFromClass(@Mutable AnnotatedTypeMirror type,
java.util.Set<javax.lang.model.element.AnnotationMirror> fromClass)
Callback to determine what to do with the annotations from a class declaration.
|
protected void |
buildIndexTypes()
Sets indexTypes and indexDeclAnnos by side effect, just before returning.
|
Pair<AnnotatedTypeMirror.AnnotatedExecutableType,java.util.List<AnnotatedTypeMirror>> |
constructorFromUse(com.sun.source.tree.NewClassTree tree)
Determines the
AnnotatedTypeMirror.AnnotatedExecutableType of a constructor
invocation. |
protected static <K,V> java.util.Map<K,V> |
createLRUCache(int size)
A Utility method for creating LRU cache
|
protected QualifierHierarchy |
createQualifierHierarchy()
Returns the type qualifier hierarchy graph to be used by this processor.
|
protected static QualifierHierarchy |
createQualifierHierarchy(javax.lang.model.util.Elements elements,
java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> supportedTypeQualifiers,
MultiGraphQualifierHierarchy.MultiGraphFactory factory)
Returns the type qualifier hierarchy graph for a given set of type qualifiers and a factory.
|
QualifierHierarchy |
createQualifierHierarchy(MultiGraphQualifierHierarchy.MultiGraphFactory factory)
Factory method to easily change what QualifierHierarchy is
created.
|
protected MultiGraphQualifierHierarchy.MultiGraphFactory |
createQualifierHierarchyFactory()
Factory method to easily change what Factory is used to
create a QualifierHierarchy.
|
protected java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> |
createSupportedTypeQualifiers()
If the checker class is annotated with
TypeQualifiers , return an immutable set with the same set
of classes as the annotation. |
protected TypeHierarchy |
createTypeHierarchy()
Creates the type subtyping checker using the current type qualifier
hierarchy.
|
protected com.sun.source.tree.Tree |
declarationFromElement(javax.lang.model.element.Element elt)
Gets the declaration tree for the element, if the source is available.
|
AnnotatedTypeMirror.AnnotatedDeclaredType |
fromClass(com.sun.source.tree.ClassTree tree)
Determines the annotated type of a class from its declaration.
|
AnnotatedTypeMirror |
fromElement(javax.lang.model.element.Element elt)
Determines the annotated type of an element.
|
AnnotatedTypeMirror.AnnotatedExecutableType |
fromElement(javax.lang.model.element.ExecutableElement elt) |
AnnotatedTypeMirror.AnnotatedDeclaredType |
fromElement(javax.lang.model.element.TypeElement elt) |
AnnotatedTypeMirror |
fromExpression(com.sun.source.tree.ExpressionTree tree)
Determines the annotated type of an expression.
|
AnnotatedTypeMirror |
fromMember(com.sun.source.tree.Tree tree)
Determines the annotated type of a variable or method declaration.
|
AnnotatedTypeMirror.AnnotatedDeclaredType |
fromNewClass(com.sun.source.tree.NewClassTree tree) |
AnnotatedTypeMirror |
fromTypeTree(com.sun.source.tree.Tree tree)
Determines the annotated type from a type in tree form.
|
AnnotatedTypeMirror.AnnotatedDeclaredType |
getAnnotatedType(com.sun.source.tree.ClassTree tree) |
AnnotatedTypeMirror |
getAnnotatedType(javax.lang.model.element.Element elt)
Determines the annotated type of an element using
fromElement(Element) . |
AnnotatedTypeMirror.AnnotatedExecutableType |
getAnnotatedType(javax.lang.model.element.ExecutableElement elt) |
AnnotatedTypeMirror.AnnotatedExecutableType |
getAnnotatedType(com.sun.source.tree.MethodTree tree) |
AnnotatedTypeMirror.AnnotatedArrayType |
getAnnotatedType(com.sun.source.tree.NewArrayTree tree) |
AnnotatedTypeMirror.AnnotatedDeclaredType |
getAnnotatedType(com.sun.source.tree.NewClassTree tree) |
AnnotatedTypeMirror |
getAnnotatedType(com.sun.source.tree.Tree tree)
Determines the annotated type of an AST node.
|
AnnotatedTypeMirror.AnnotatedDeclaredType |
getAnnotatedType(javax.lang.model.element.TypeElement elt) |
AnnotatedTypeMirror |
getAnnotatedTypeFromTypeTree(com.sun.source.tree.Tree tree)
Determines the annotated type from a type in tree form.
|
javax.lang.model.element.AnnotationMirror |
getAnnotationMirror(com.sun.source.tree.Tree tree,
java.lang.Class<? extends java.lang.annotation.Annotation> target)
Return the annotation on
tree that has the class
target . |
java.util.List<Pair<javax.lang.model.element.AnnotationMirror,javax.lang.model.element.AnnotationMirror>> |
getAnnotationWithMetaAnnotation(javax.lang.model.element.Element element,
java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotation)
Returns a list of all annotations used to annotate this element,
which have a meta-annotation (i.e., an annotation on that annotation)
with class
metaAnnotation . |
AnnotatedTypeMirror.AnnotatedDeclaredType |
getBoxedType(AnnotatedTypeMirror.AnnotatedPrimitiveType type)
Returns the annotated boxed type of the given primitive type.
|
protected com.sun.source.tree.ClassTree |
getCurrentClassTree(com.sun.source.tree.Tree tree)
Returns the current class type being visited by the visitor.
|
protected AnnotatedTypeMirror.AnnotatedDeclaredType |
getCurrentClassType(com.sun.source.tree.Tree tree) |
protected AnnotatedTypeMirror.AnnotatedDeclaredType |
getCurrentMethodReceiver(com.sun.source.tree.Tree tree)
Returns the receiver type of the current method being visited, and
returns null if the visited tree is not within a method.
|
javax.lang.model.element.AnnotationMirror |
getDeclAnnotation(javax.lang.model.element.Element elt,
java.lang.Class<? extends java.lang.annotation.Annotation> anno)
Returns the actual annotation mirror used to annotate this element,
whose name equals the passed annotation class, if one exists, or null otherwise.
|
java.util.Set<javax.lang.model.element.AnnotationMirror> |
getDeclAnnotations(javax.lang.model.element.Element elt)
Returns all of the actual annotation mirrors used to annotate this element
(includes stub files).
|
java.util.List<Pair<javax.lang.model.element.AnnotationMirror,javax.lang.model.element.AnnotationMirror>> |
getDeclAnnotationWithMetaAnnotation(javax.lang.model.element.Element element,
java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotation)
Returns a list of all declaration annotations used to annotate this element,
which have a meta-annotation (i.e., an annotation on that annotation)
with class
metaAnnotation . |
javax.lang.model.util.Elements |
getElementUtils()
Accessor for the element utilities.
|
javax.lang.model.element.Element |
getEnclosingMethod(com.sun.source.tree.Tree node)
Gets the
Element representing the declaration of the
method enclosing a tree node. |
AnnotatedTypeMirror.AnnotatedDeclaredType |
getEnclosingType(javax.lang.model.element.TypeElement element,
com.sun.source.tree.Tree tree)
Determine the type of the most enclosing class of the given tree that
is a subtype of the given element.
|
protected AnnotatedTypeMirror.AnnotatedDeclaredType |
getImplicitReceiverType(com.sun.source.tree.ExpressionTree tree)
Return the implicit receiver type of an expression tree.
|
AnnotatedTypeMirror |
getMethodReturnType(com.sun.source.tree.MethodTree m)
Returns the return type of the method
m . |
AnnotatedTypeMirror |
getMethodReturnType(com.sun.source.tree.MethodTree m,
com.sun.source.tree.ReturnTree r)
Returns the return type of the method
m at the return statement r . |
com.sun.source.util.TreePath |
getPath(com.sun.source.tree.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. |
javax.annotation.processing.ProcessingEnvironment |
getProcessingEnv()
Accessor for the processing environment.
|
QualifierHierarchy |
getQualifierHierarchy()
Returns the type qualifier hierarchy graph to be used by this processor.
|
AnnotatedTypeMirror |
getReceiverType(com.sun.source.tree.ExpressionTree expression)
Returns the receiver type of the expression tree, or null if it does not exist.
|
AnnotatedTypeMirror.AnnotatedDeclaredType |
getSelfType(com.sun.source.tree.Tree tree)
Returns the type of
this in the current location, which can
be used if this has a special semantics (e.g. |
java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> |
getSupportedTypeQualifiers()
Returns an immutable set of the type qualifiers supported by this
checker.
|
com.sun.source.util.Trees |
getTreeUtils()
Accessor for the tree utilities.
|
TypeHierarchy |
getTypeHierarchy() |
AnnotatedTypeMirror.AnnotatedPrimitiveType |
getUnboxedType(AnnotatedTypeMirror.AnnotatedDeclaredType type)
returns the annotated primitive type of the given declared type
if it is a boxed declared type.
|
AnnotatedTypeMirror.AnnotatedWildcardType |
getUninferredWildcardType(AnnotatedTypeMirror.AnnotatedTypeVariable typeVar)
This method is a hack to use when a method type argument
could not be inferred automatically or if a raw type is used.
|
VisitorState |
getVisitorState()
Returns the VisitorState instance used by the factory to infer types
|
AnnotatedTypeMirror.AnnotatedWildcardType |
getWildcardBoundedBy(AnnotatedTypeMirror upper) |
boolean |
isAnyEnclosingThisDeref(com.sun.source.tree.ExpressionTree tree)
Does this expression have (the innermost or an outer) "this" as receiver?
Note that the receiver can be either explicit or implicit.
|
boolean |
isFromByteCode(javax.lang.model.element.Element element)
Returns true if the element is from byte code
and the if the element did not appear in a stub file
(Currently only works for methods and constructors )
|
boolean |
isFromStubFile(javax.lang.model.element.Element element)
Returns true if the element appears in a stub file
(Currently only works for methods and constructors)
|
boolean |
isMostEnclosingThisDeref(com.sun.source.tree.ExpressionTree tree)
Determine whether the tree dereferences the most enclosing "this" object.
|
boolean |
isSupportedQualifier(@Nullable javax.lang.model.element.AnnotationMirror a)
Determines whether the given annotation is a part of the type system
under which this type factory operates.
|
protected boolean |
isWithinConstructor(com.sun.source.tree.Tree tree) |
Pair<AnnotatedTypeMirror.AnnotatedExecutableType,java.util.List<AnnotatedTypeMirror>> |
methodFromUse(com.sun.source.tree.MethodInvocationTree tree)
Determines the type of the invoked method based on the passed method
invocation tree.
|
void |
postAsMemberOf(AnnotatedTypeMirror type,
AnnotatedTypeMirror owner,
javax.lang.model.element.Element element)
A callback method for the AnnotatedTypeFactory subtypes to customize
AnnotatedTypes.asMemberOf().
|
protected void |
postDirectSuperTypes(AnnotatedTypeMirror type,
java.util.List<? extends AnnotatedTypeMirror> supertypes)
A callback method for the AnnotatedTypeFactory subtypes to customize
directSuperTypes().
|
protected void |
postInit()
Actions that logically belong in the constructor, but need to run
after the subclass constructor has completed.
|
protected void |
postProcessClassTree(com.sun.source.tree.ClassTree tree)
Called by getAnnotatedType(Tree) for each ClassTree after determining the type.
|
void |
setPathHack(com.sun.source.tree.Tree node,
javax.lang.model.element.Element enclosing) |
void |
setRoot(@Nullable com.sun.source.tree.CompilationUnitTree root) |
AnnotatedTypeMirror |
toAnnotatedType(javax.lang.model.type.TypeMirror t)
A convenience method that converts a
TypeMirror to an AnnotatedTypeMirror using AnnotatedTypeMirror.createType(javax.lang.model.type.TypeMirror, org.checkerframework.framework.type.AnnotatedTypeFactory) . |
java.lang.String |
toString() |
AnnotatedTypeMirror |
type(com.sun.source.tree.Tree node)
Determines an empty annotated type of the given tree.
|
java.util.List<AnnotatedTypeMirror.AnnotatedTypeVariable> |
typeVariablesFromUse(AnnotatedTypeMirror.AnnotatedDeclaredType type,
javax.lang.model.element.TypeElement element)
Adapt the upper bounds of the type variables of a class relative
to the type instantiation.
|
protected final com.sun.source.util.Trees trees
Trees
instance to use for tree node path finding.protected @Nullable com.sun.source.tree.CompilationUnitTree root
protected final javax.annotation.processing.ProcessingEnvironment processingEnv
protected final javax.lang.model.util.Elements elements
Element
s.protected final javax.lang.model.util.Types types
TypeMirror
s.protected final VisitorState visitorState
protected QualifierHierarchy qualHierarchy
protected TypeHierarchy typeHierarchy
protected final BaseTypeChecker checker
public final int uid
protected static boolean SHOULD_CACHE
public boolean shouldCache
protected static boolean SHOULD_READ_CACHE
public boolean shouldReadCache
protected final java.util.Map<com.sun.source.tree.Tree,AnnotatedTypeMirror> fromTreeCache
public AnnotatedTypeFactory(BaseTypeChecker checker)
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.
A subclass must call postInit at the end of its constructor.checker
- the SourceChecker
to which this factory belongsjava.lang.IllegalArgumentException
- if either argument is null
protected void postInit()
public void setRoot(@Nullable com.sun.source.tree.CompilationUnitTree root)
@SideEffectFree public java.lang.String toString()
toString
in class java.lang.Object
protected MultiGraphQualifierHierarchy.MultiGraphFactory createQualifierHierarchyFactory()
public QualifierHierarchy createQualifierHierarchy(MultiGraphQualifierHierarchy.MultiGraphFactory factory)
protected QualifierHierarchy createQualifierHierarchy()
getSupportedTypeQualifiers()
using the
meta-annotations found in them. The current implementation returns an
instance of GraphQualifierHierarchy
.
Subclasses may override this method to express any relationships that
cannot be inferred using meta-annotations (e.g. due to lack of
meta-annotations).protected static QualifierHierarchy createQualifierHierarchy(javax.lang.model.util.Elements elements, java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> supportedTypeQualifiers, MultiGraphQualifierHierarchy.MultiGraphFactory factory)
The implementation builds the type qualifier hierarchy for the
supportedTypeQualifiers
. The current implementation returns an
instance of GraphQualifierHierarchy
.
public final QualifierHierarchy getQualifierHierarchy()
QualifierHierarchy
for this checkercreateQualifierHierarchy()
protected TypeHierarchy createTypeHierarchy()
public final TypeHierarchy getTypeHierarchy()
protected java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> createSupportedTypeQualifiers()
TypeQualifiers
, return an immutable set with the same set
of classes as the annotation. If the class is not so annotated,
return an empty set.
Subclasses may override this method to return an immutable set
of their supported type qualifiers.TypeQualifiers
public final java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> getSupportedTypeQualifiers()
createSupportedTypeQualifiers()
public AnnotatedTypeMirror getAnnotatedType(javax.lang.model.element.Element elt)
fromElement(Element)
.elt
- the elementelt
java.lang.IllegalArgumentException
- if elt
is nullfromElement(Element)
public javax.lang.model.element.AnnotationMirror getAnnotationMirror(com.sun.source.tree.Tree tree, java.lang.Class<? extends java.lang.annotation.Annotation> target)
AnnotationProvider
tree
that has the class
target
. If no annotation for the given target class exists,
the result is null
getAnnotationMirror
in interface AnnotationProvider
tree
- The tree of which the annotation is returnedtarget
- The class of the annotationpublic AnnotatedTypeMirror getAnnotatedType(com.sun.source.tree.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 nodetree
fromClass(ClassTree)
,
fromMember(Tree)
,
fromExpression(ExpressionTree)
protected void postProcessClassTree(com.sun.source.tree.ClassTree tree)
public AnnotatedTypeMirror getAnnotatedTypeFromTypeTree(com.sun.source.tree.Tree tree)
tree
- the type treepublic AnnotatedTypeMirror fromElement(javax.lang.model.element.Element elt)
elt
- the elementpublic AnnotatedTypeMirror.AnnotatedDeclaredType fromClass(com.sun.source.tree.ClassTree tree)
tree
- the class declarationpublic AnnotatedTypeMirror fromMember(com.sun.source.tree.Tree tree)
tree
- the variable or method declarationjava.lang.IllegalArgumentException
- if tree
is not a method or
variable declarationpublic AnnotatedTypeMirror fromExpression(com.sun.source.tree.ExpressionTree tree)
tree
- an expressionpublic AnnotatedTypeMirror fromTypeTree(com.sun.source.tree.Tree tree)
tree
- the type treepublic void annotateImplicit(com.sun.source.tree.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(javax.lang.model.element.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, java.util.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 AnnotatedTypeFactorypublic void postAsMemberOf(AnnotatedTypeMirror type, AnnotatedTypeMirror owner, javax.lang.model.element.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 methodpublic java.util.List<AnnotatedTypeMirror.AnnotatedTypeVariable> typeVariablesFromUse(AnnotatedTypeMirror.AnnotatedDeclaredType type, javax.lang.model.element.TypeElement element)
class C<X extends @Peer Object>then the instantiation
@Rep C<@Rep Object>is legal. The upper bounds of class C have to be adapted by the main modifier.
TODO: ensure that this method is consistently used instead of directly querying the type variables.
type
- The use of the typeelement
- The corresponding elementprotected void annotateInheritedFromClass(@Mutable AnnotatedTypeMirror type)
type
- the type for which class annotations will be inherited if
there are no annotations already presentprotected void annotateInheritedFromClass(@Mutable AnnotatedTypeMirror type, java.util.Set<javax.lang.model.element.AnnotationMirror> fromClass)
protected AnnotatedTypeMirror.AnnotatedDeclaredType getImplicitReceiverType(com.sun.source.tree.ExpressionTree tree)
tree
- The expression that might have an implicit receiver.public final boolean isMostEnclosingThisDeref(com.sun.source.tree.ExpressionTree tree)
tree
- The tree to check.public final boolean isAnyEnclosingThisDeref(com.sun.source.tree.ExpressionTree tree)
tree
- The tree to test.public AnnotatedTypeMirror.AnnotatedDeclaredType getSelfType(com.sun.source.tree.Tree tree)
this
in the current location, which can
be used if this
has a special semantics (e.g. this
is non-null).
The parameter is an arbitrary tree and does not have to mention "this",
neither explicitly nor implicitly.
This method should be overridden for type-system specific behavior.
TODO: in 1.3, handle all receiver type annotations.
TODO: handle enclosing classes correctly.public AnnotatedTypeMirror.AnnotatedDeclaredType getEnclosingType(javax.lang.model.element.TypeElement element, com.sun.source.tree.Tree tree)
public final AnnotatedTypeMirror getReceiverType(com.sun.source.tree.ExpressionTree expression)
expression
- The expression for which to determine the receiver typepublic Pair<AnnotatedTypeMirror.AnnotatedExecutableType,java.util.List<AnnotatedTypeMirror>> methodFromUse(com.sun.source.tree.MethodInvocationTree tree)
AnnotatedTypes.asMemberOf(Types, AnnotatedTypeFactory, AnnotatedTypeMirror, Element)
,
and customization based on receiver type should be in accordance to its
specification.
The return type is a pair of the type of the invoked method and
the (inferred) type arguments.
Note that neither the explicitly passed nor the inferred type arguments
are guaranteed to be subtypes of the corresponding upper bounds.
See method
BaseTypeVisitor.checkTypeArguments(Tree, List, List, List)
for the checks of type argument well-formedness.
Note that "this" and "super" constructor invocations are also handled by this
method. Method constructorFromUse(NewClassTree)
is only used for a constructor
invocation in a "new" expression.tree
- the method invocation treepublic Pair<AnnotatedTypeMirror.AnnotatedExecutableType,java.util.List<AnnotatedTypeMirror>> constructorFromUse(com.sun.source.tree.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
.
TODO: Should the result of getAnnotatedType be the return type
from the AnnotatedExecutableType computed here?
Note that "this" and "super" constructor invocations are handled by
method methodFromUse(com.sun.source.tree.MethodInvocationTree)
. This method only handles constructor invocations
in a "new" expression.tree
- the constructor invocation treepublic AnnotatedTypeMirror getMethodReturnType(com.sun.source.tree.MethodTree m)
m
.public AnnotatedTypeMirror getMethodReturnType(com.sun.source.tree.MethodTree m, com.sun.source.tree.ReturnTree r)
m
at the return statement r
.public AnnotatedTypeMirror.AnnotatedDeclaredType fromNewClass(com.sun.source.tree.NewClassTree tree)
public AnnotatedTypeMirror.AnnotatedDeclaredType getBoxedType(AnnotatedTypeMirror.AnnotatedPrimitiveType type)
type
- the primitive typepublic AnnotatedTypeMirror.AnnotatedPrimitiveType getUnboxedType(AnnotatedTypeMirror.AnnotatedDeclaredType type) throws java.lang.IllegalArgumentException
type
- the declared typejava.lang.IllegalArgumentException
- if the type given has no unbox conversionpublic VisitorState getVisitorState()
public final AnnotatedTypeMirror.AnnotatedDeclaredType getAnnotatedType(com.sun.source.tree.ClassTree tree)
getAnnotatedType(Tree)
public final AnnotatedTypeMirror.AnnotatedDeclaredType getAnnotatedType(com.sun.source.tree.NewClassTree tree)
getAnnotatedType(Tree)
public final AnnotatedTypeMirror.AnnotatedArrayType getAnnotatedType(com.sun.source.tree.NewArrayTree tree)
getAnnotatedType(Tree)
public final AnnotatedTypeMirror.AnnotatedExecutableType getAnnotatedType(com.sun.source.tree.MethodTree tree)
getAnnotatedType(Tree)
public final AnnotatedTypeMirror.AnnotatedDeclaredType getAnnotatedType(javax.lang.model.element.TypeElement elt)
getAnnotatedType(Element)
public final AnnotatedTypeMirror.AnnotatedExecutableType getAnnotatedType(javax.lang.model.element.ExecutableElement elt)
getAnnotatedType(Element)
public final AnnotatedTypeMirror.AnnotatedDeclaredType fromElement(javax.lang.model.element.TypeElement elt)
getAnnotatedType(Element)
public final AnnotatedTypeMirror.AnnotatedExecutableType fromElement(javax.lang.model.element.ExecutableElement elt)
getAnnotatedType(Element)
public boolean isSupportedQualifier(@Nullable javax.lang.model.element.AnnotationMirror a)
a
- any annotationprotected void addAliasedAnnotation(java.lang.Class<?> alias, javax.lang.model.element.AnnotationMirror type)
public @Nullable javax.lang.model.element.AnnotationMirror aliasedAnnotation(javax.lang.model.element.AnnotationMirror a)
a
- the qualifier to check for an aliasprotected void addAliasedDeclAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> alias, java.lang.Class<? extends java.lang.annotation.Annotation> annotation, javax.lang.model.element.AnnotationMirror annotationToUse)
alias
as an alias for the declaration
annotation annotation
, where the annotation mirror
annoationToUse
will be used instead. If multiple calls are made
with the same annotation
, then the anontationToUse
must
be the same.public final AnnotatedTypeMirror toAnnotatedType(javax.lang.model.type.TypeMirror t)
TypeMirror
to an AnnotatedTypeMirror
using AnnotatedTypeMirror.createType(javax.lang.model.type.TypeMirror, org.checkerframework.framework.type.AnnotatedTypeFactory)
.t
- the TypeMirror
AnnotatedTypeMirror
that has t
as its
underlying typepublic AnnotatedTypeMirror type(com.sun.source.tree.Tree node)
TypeMirror
for the tree and converts that into an
AnnotatedTypeMirror
, but does not add any annotations to the
result.
Most users will want to use getAnnotatedType instead; this method
is mostly for internal use.node
- the tree to analyzenode
, without any annotationsprotected final com.sun.source.tree.Tree declarationFromElement(javax.lang.model.element.Element elt)
elt
- an elementprotected final com.sun.source.tree.ClassTree getCurrentClassTree(com.sun.source.tree.Tree tree)
protected final AnnotatedTypeMirror.AnnotatedDeclaredType getCurrentClassType(com.sun.source.tree.Tree tree)
protected final AnnotatedTypeMirror.AnnotatedDeclaredType getCurrentMethodReceiver(com.sun.source.tree.Tree tree)
protected final boolean isWithinConstructor(com.sun.source.tree.Tree tree)
public final void setPathHack(com.sun.source.tree.Tree node, javax.lang.model.element.Element enclosing)
public final com.sun.source.util.TreePath getPath(com.sun.source.tree.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.
Note that the given Tree has to be within the current compilation unit,
otherwise null will be returned.node
- the Tree
to get the path fornode
under the current rootpublic final javax.lang.model.element.Element getEnclosingMethod(com.sun.source.tree.Tree node)
Element
representing the declaration of the
method enclosing a tree node. This feature is used to record
the enclosing methods of Tree
s that are created
internally by the checker.
TODO: Find a better way to store information about enclosing
Trees.node
- the Tree
to get the enclosing method forElement
enclosing the argument, or
null if none has been recordedprotected static <K,V> java.util.Map<K,V> createLRUCache(int size)
size
- size of the cacheprotected void buildIndexTypes()
public javax.lang.model.element.AnnotationMirror getDeclAnnotation(javax.lang.model.element.Element elt, java.lang.Class<? extends java.lang.annotation.Annotation> anno)
getDeclAnnotation
in interface AnnotationProvider
anno
- annotation classpublic boolean isFromStubFile(javax.lang.model.element.Element element)
public boolean isFromByteCode(javax.lang.model.element.Element element)
public java.util.Set<javax.lang.model.element.AnnotationMirror> getDeclAnnotations(javax.lang.model.element.Element elt)
elt
- The element for which to determine annotations.public java.util.List<Pair<javax.lang.model.element.AnnotationMirror,javax.lang.model.element.AnnotationMirror>> getDeclAnnotationWithMetaAnnotation(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotation)
metaAnnotation
.element
- The element for which to determine annotations.metaAnnotation
- The meta annotation that needs to be present.(anno, metaAnno)
where anno
is
the annotation mirror at element
, and metaAnno
is
the annotation mirror used to annotate anno
.public java.util.List<Pair<javax.lang.model.element.AnnotationMirror,javax.lang.model.element.AnnotationMirror>> getAnnotationWithMetaAnnotation(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotation)
metaAnnotation
.element
- The element at which to look for annotations.metaAnnotation
- The meta annotation that needs to be present.(anno, metaAnno)
where anno
is
the annotation mirror at element
, and metaAnno
is
the annotation mirror used to annotate anno
.public AnnotatedTypeMirror.AnnotatedWildcardType getUninferredWildcardType(AnnotatedTypeMirror.AnnotatedTypeVariable typeVar)
public AnnotatedTypeMirror.AnnotatedWildcardType getWildcardBoundedBy(AnnotatedTypeMirror upper)
public javax.lang.model.util.Elements getElementUtils()
public com.sun.source.util.Trees getTreeUtils()
public javax.annotation.processing.ProcessingEnvironment getProcessingEnv()