public class NullnessAnnotatedTypeFactory extends BasicAnnotatedTypeFactory<NullnessSubchecker>
NonNull
annotation to a type that is:
null
literal)
DefaultQualifier
annotation and
matches its location criteria
NonNull
by flow-sensitive inference
Raw
annotation to
Additionally, the type factory will add the Nullable
annotation to a
type if the input is
AnnotatedTypeFactory.InheritedFromClassAnnotator
Modifier and Type | Field and Description |
---|---|
protected AnnotationMirror |
LAZYNONNULL
Represents the Nullness Checker qualifiers
|
protected AnnotationMirror |
NONNULL
Represents the Nullness Checker qualifiers
|
protected AnnotationMirror |
NULLABLE
Represents the Nullness Checker qualifiers
|
protected AnnotationMirror |
POLYALL
Represents the Nullness Checker qualifiers
|
protected AnnotationMirror |
POLYNULL
Represents the Nullness Checker qualifiers
|
protected AnnotationMirror |
PRIMITIVE
Represents the Nullness Checker qualifiers
|
protected AnnotationMirror |
RAW
Represents the Nullness Checker qualifiers
|
protected AnnotationMirror |
UNUSED
Represents the Nullness Checker qualifiers
|
checker, defaults, flow, FLOW_BY_DEFAULT, poly, treeAnnotator, typeAnnotator, useFlow
elements, fromTreeCache, processingEnv, qualHierarchy, root, trees, types, uid, visitorState
Constructor and Description |
---|
NullnessAnnotatedTypeFactory(NullnessSubchecker checker,
RawnessSubchecker rawnesschecker,
CompilationUnitTree root)
Creates a
NullnessAnnotatedTypeFactory . |
Modifier and Type | Method and Description |
---|---|
void |
annotateImplicit(Element elt,
AnnotatedTypeMirror type)
Adds implicit annotations to a type obtained from a
Element . |
void |
annotateImplicit(Tree tree,
AnnotatedTypeMirror type)
Adds implicit annotations to a type obtained from a
Tree . |
Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<AnnotatedTypeMirror>> |
constructorFromUse(NewClassTree tree)
Determines the
AnnotatedTypeMirror.AnnotatedExecutableType of a constructor
invocation. |
protected Flow |
createFlow(NullnessSubchecker checker,
CompilationUnitTree root,
Set<AnnotationMirror> flowQuals)
Returns a
Flow instance that performs flow sensitive analysis
to infer qualifiers on unqualified types. |
protected Set<AnnotationMirror> |
createFlowQualifiers(NullnessSubchecker checker)
Returns the set of annotations to be inferred in flow analysis
|
protected TreeAnnotator |
createTreeAnnotator(NullnessSubchecker checker)
Returns a
TreeAnnotator that adds annotations to a type based
on the contents of a tree. |
protected TypeAnnotator |
createTypeAnnotator(NullnessSubchecker checker)
Returns a
TypeAnnotator that adds annotations to a type based
on the content of the type itself. |
AnnotatedTypeMirror.AnnotatedDeclaredType |
getEnclosingType(TypeElement element,
Tree tree)
Determine the type of the most enclosing class of the given tree that
is a subtype of the given element.
|
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. |
Set<VariableElement> |
initializedAfter(MethodTree node) |
Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<AnnotatedTypeMirror>> |
methodFromUse(MethodInvocationTree tree)
Determines the type of the invoked method based on the passed method
invocation tree.
|
createQualifierDefaults, createQualifierPolymorphism, postDirectSuperTypes, postInit
addAliasedAnnotation, addAliasedDeclAnnotation, aliasedAnnotation, annotateInheritedFromClass, canHaveAnnotatedTypeParameters, createLRUCache, declarationFromElement, fromClass, fromElement, fromElement, fromElement, fromExpression, fromMember, fromNewClass, fromTypeTree, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFromTypeTree, getAnnotationWithMetaAnnotation, getBoxedType, getCurrentClassTree, getCurrentClassType, getCurrentMethodReceiver, getDeclAnnotation, getDeclAnnotations, getDeclAnnotationTree, getDeclAnnotationWithMetaAnnotation, getDefaultedAnnotatedType, getElementUtils, getImplicitReceiverType, getPath, getProcessingEnv, getQualifierHierarchy, getReceiverType, getUnboxedType, getUninferredMethodTypeArgument, getVisitorState, isAnyEnclosingThisDeref, isMostEnclosingThisDeref, isSupportedQualifier, isWithinConstructor, postAsMemberOf, toAnnotatedType, toString, type, typeVariablesFromUse
protected final AnnotationMirror NONNULL
protected final AnnotationMirror NULLABLE
protected final AnnotationMirror LAZYNONNULL
protected final AnnotationMirror RAW
protected final AnnotationMirror PRIMITIVE
protected final AnnotationMirror POLYNULL
protected final AnnotationMirror POLYALL
protected final AnnotationMirror UNUSED
public NullnessAnnotatedTypeFactory(NullnessSubchecker checker, RawnessSubchecker rawnesschecker, CompilationUnitTree root)
NullnessAnnotatedTypeFactory
.protected Flow createFlow(NullnessSubchecker checker, CompilationUnitTree root, Set<AnnotationMirror> flowQuals)
BasicAnnotatedTypeFactory
Flow
instance that performs flow sensitive analysis
to infer qualifiers on unqualified types.createFlow
in class BasicAnnotatedTypeFactory<NullnessSubchecker>
checker
- the checkerroot
- the compilation unit associated with this factoryflowQuals
- the qualifiers to inferprotected Set<AnnotationMirror> createFlowQualifiers(NullnessSubchecker checker)
BasicAnnotatedTypeFactory
createFlowQualifiers
in class BasicAnnotatedTypeFactory<NullnessSubchecker>
protected TreeAnnotator createTreeAnnotator(NullnessSubchecker checker)
BasicAnnotatedTypeFactory
TreeAnnotator
that adds annotations to a type based
on the contents of a tree.
Subclasses may override this method to specify more appriopriate
TreeAnnotator
createTreeAnnotator
in class BasicAnnotatedTypeFactory<NullnessSubchecker>
protected TypeAnnotator createTypeAnnotator(NullnessSubchecker checker)
BasicAnnotatedTypeFactory
TypeAnnotator
that adds annotations to a type based
on the content of the type itself.createTypeAnnotator
in class BasicAnnotatedTypeFactory<NullnessSubchecker>
public void annotateImplicit(Element elt, AnnotatedTypeMirror type)
AnnotatedTypeFactory
Element
. By
default, this method does nothing. Subclasses should use this method to
implement implicit annotations specific to their type systems.annotateImplicit
in class BasicAnnotatedTypeFactory<NullnessSubchecker>
elt
- an elementtype
- the type obtained from elt
public void annotateImplicit(Tree tree, AnnotatedTypeMirror type)
AnnotatedTypeFactory
Tree
. By
default, this method does nothing. Subclasses should use this method to
implement implicit annotations specific to their type systems.annotateImplicit
in class BasicAnnotatedTypeFactory<NullnessSubchecker>
tree
- an AST nodetype
- the type obtained from tree
public AnnotatedTypeMirror.AnnotatedDeclaredType getSelfType(Tree tree)
AnnotatedTypeFactory
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.getSelfType
in class AnnotatedTypeFactory
public final AnnotatedTypeMirror.AnnotatedDeclaredType getEnclosingType(TypeElement element, Tree tree)
AnnotatedTypeFactory
getEnclosingType
in class AnnotatedTypeFactory
public Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<AnnotatedTypeMirror>> methodFromUse(MethodInvocationTree tree)
AnnotatedTypeFactory
AnnotatedTypes#asMemberOf(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
is only used for a constructor invocation
in a "new" expression.methodFromUse
in class BasicAnnotatedTypeFactory<NullnessSubchecker>
tree
- the method invocation treepublic Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<AnnotatedTypeMirror>> constructorFromUse(NewClassTree tree)
AnnotatedTypeFactory
AnnotatedTypeMirror.AnnotatedExecutableType
of a constructor
invocation. Note that this is different than calling
AnnotatedTypeFactory.getAnnotatedType(Tree)
or
AnnotatedTypeFactory.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
. This method only handles constructor invocations
in a "new" expression.constructorFromUse
in class BasicAnnotatedTypeFactory<NullnessSubchecker>
tree
- the constructor invocation treepublic Set<VariableElement> initializedAfter(MethodTree node)