public class AnnotatedTypeFactory extends Object implements AnnotationProvider
AnnotatedTypeMirror
. The methods are:
getAnnotatedType(ClassTree)
getAnnotatedType(MethodTree)
getAnnotatedType(Tree)
getAnnotatedTypeFromTypeTree(Tree)
getAnnotatedType(TypeElement)
getAnnotatedType(ExecutableElement)
getAnnotatedType(Element)
addComputedTypeAnnotations(com.sun.source.tree.Tree, org.checkerframework.framework.type.AnnotatedTypeMirror)
to add defaults, flow-sensitive refinement, and
type-system-specific rules.
Unless otherwise indicated, each public method in this class returns a "fully annotated" type, which is one that has an annotation in all positions.
Type system checker writers may need to subclass this class, to add default qualifiers
according to the type system semantics. Subclasses should especially override addComputedTypeAnnotations(Element, AnnotatedTypeMirror)
and addComputedTypeAnnotations(Tree, AnnotatedTypeMirror)
to handle default annotations. (Also,
addDefaultAnnotations(AnnotatedTypeMirror)
adds annotations, but that method is a
workaround for Issue
979.)
Modifier and Type | Class and Description |
---|---|
static class |
AnnotatedTypeFactory.ParameterizedExecutableType
The type for an instantiated generic method or constructor.
|
Modifier and Type | Field and Description |
---|---|
AnnotationFileElementTypes |
ajavaTypes
Parses ajava files and stores annotations on public elements from ajava files.
|
protected Map<Tree,Element> |
artificialTreeToEnclosingElementMap
Mapping from CFG-generated trees to their enclosing elements.
|
protected BaseTypeChecker |
checker
The checker to use for option handling and resource management.
|
@Nullable AnnotationFileElementTypes |
currentFileAjavaTypes
If type checking a Java file, stores annotations read from an ajava file for that class if one
exists.
|
protected Elements |
elements
Utility class for working with
Element s. |
protected Map<Tree,AnnotatedTypeMirror> |
fromExpressionTreeCache
Mapping from an expression tree to its annotated type; before defaults are applied, just what
the programmer wrote.
|
protected Map<Tree,AnnotatedTypeMirror> |
fromMemberTreeCache
Mapping from a member tree to its annotated type; before defaults are applied, just what the
programmer wrote.
|
protected Map<Tree,AnnotatedTypeMirror> |
fromTypeTreeCache
Mapping from a type tree to its annotated type; before defaults are applied, just what the
programmer wrote.
|
boolean |
ignoreUninferredTypeArguments
Whether to ignore uninferred type arguments.
|
protected AnnotationClassLoader |
loader
AnnotationClassLoader used to load type annotation classes via reflective lookup.
|
ExecutableElement |
methodValClassNameElement
The MethodVal.className argument/element.
|
ExecutableElement |
methodValMethodNameElement
The MethodVal.methodName argument/element.
|
ExecutableElement |
methodValParamsElement
The MethodVal.params argument/element.
|
protected ExecutableElement |
objectGetClass
The Object.getClass method.
|
protected ProcessingEnvironment |
processingEnv
The processing environment to use for accessing compiler internals.
|
protected QualifierHierarchy |
qualHierarchy
Represent the annotation relations.
|
protected QualifierUpperBounds |
qualifierUpperBounds
Holds the qualifier upper bounds for type uses.
|
protected ReflectionResolver |
reflectionResolver
Object that is used to resolve reflective method calls, if reflection resolution is turned on.
|
protected @Nullable CompilationUnitTree |
root
Optional! The AST of the source file being operated on.
|
boolean |
shouldCache
Should results be cached? This means that ATM.deepCopy() will be called.
|
AnnotationFileElementTypes |
stubTypes
Parses stub files and stores annotations on public elements from stub files.
|
protected Trees |
trees
The
Trees instance to use for tree node path finding. |
protected TypeArgumentInference |
typeArgumentInference
Provides utility method to infer type arguments.
|
protected AnnotatedTypeFormatter |
typeFormatter
This formatter is used for converting AnnotatedTypeMirrors to Strings.
|
protected TypeHierarchy |
typeHierarchy
Represent the type relations.
|
Types |
types
Utility class for working with
TypeMirror s. |
protected TypeVariableSubstitutor |
typeVarSubstitutor
Provides utility method to substitute arguments for their type variables.
|
int |
uid
Unique ID of the current object; for debugging purposes.
|
WholeProgramInference.OutputFormat |
wpiOutputFormat
Which whole-program inference output format to use, if doing whole-program inference.
|
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 |
adaptGetClassReturnTypeToReceiver(AnnotatedTypeMirror.AnnotatedExecutableType getClassType,
AnnotatedTypeMirror receiverType,
ExpressionTree tree)
Java special-cases the return type of
getClass() . |
protected void |
addAliasedAnnotation(Class<?> aliasClass,
AnnotationMirror type)
Deprecated.
use
addAliasedTypeAnnotation |
protected void |
addAliasedAnnotation(Class<?> aliasClass,
Class<?> canonical,
boolean copyElements,
String... ignorableElements)
Deprecated.
use
addAliasedTypeAnnotation |
protected void |
addAliasedAnnotation(@FullyQualifiedName String aliasName,
AnnotationMirror canonicalAnno)
|
protected void |
addAliasedDeclAnnotation(Class<? extends Annotation> alias,
Class<? extends Annotation> annotation,
AnnotationMirror annotationToUse)
Add the annotation
alias as an alias for the declaration annotation annotation ,
where the annotation mirror annotationToUse will be used instead. |
protected void |
addAliasedTypeAnnotation(Class<?> aliasClass,
AnnotationMirror canonicalAnno)
Adds the annotation
aliasClass as an alias for the canonical annotation canonicalAnno that will be used by the Checker Framework in the alias's place. |
protected void |
addAliasedTypeAnnotation(Class<?> aliasClass,
Class<?> canonicalClass,
boolean copyElements,
String... ignorableElements)
Adds the annotation
aliasClass as an alias for the canonical annotation canonicalClass that will be used by the Checker Framework in the alias's place. |
protected void |
addAliasedTypeAnnotation(@FullyQualifiedName String aliasName,
AnnotationMirror canonicalAnno)
Adds the annotation, whose fully-qualified name is given by
aliasName , as an alias for
the canonical annotation canonicalAnno that will be used by the Checker Framework in
the alias's place. |
protected void |
addAliasedTypeAnnotation(@FullyQualifiedName String aliasName,
Class<?> canonicalAnno,
boolean copyElements,
String... ignorableElements)
Adds the annotation, whose fully-qualified name is given by
aliasName , as an alias for
the canonical annotation canonicalAnno that will be used by the Checker Framework in
the alias's place. |
protected void |
addAnnotationFromFieldInvariant(AnnotatedTypeMirror type,
AnnotatedTypeMirror accessedVia,
VariableElement field)
Adds the qualifier specified by a field invariant for
field to type . |
protected void |
addComputedTypeAnnotations(Element elt,
AnnotatedTypeMirror type)
Changes annotations on a type obtained from an
Element . |
protected void |
addComputedTypeAnnotations(Tree tree,
AnnotatedTypeMirror type)
Changes annotations on a type obtained from a
Tree . |
void |
addDefaultAnnotations(AnnotatedTypeMirror type)
Adds default annotations to
type . |
protected void |
addInheritedAnnotation(AnnotationMirror annotation)
Adds the annotation
annotation in the set of declaration annotations that should be
inherited. |
AnnotatedTypeMirror |
applyCaptureConversion(AnnotatedTypeMirror typeToCapture)
Apply capture conversion to
typeToCapture . |
AnnotatedTypeMirror |
applyCaptureConversion(AnnotatedTypeMirror type,
TypeMirror typeMirror)
Apply capture conversion to
type . |
AnnotatedTypeMirror.AnnotatedPrimitiveType |
applyUnboxing(AnnotatedTypeMirror type)
Return a primitive type: either the argument, or the result of unboxing it (which might affect
its annotations).
|
boolean |
areSameByClass(AnnotationMirror am,
Class<? extends Annotation> annoClass)
Checks that the annotation
am has the name of annoClass . |
Pair<AnnotatedTypeMirror,AnnotatedTypeMirror> |
binaryTreeArgTypes(AnnotatedTypeMirror left,
AnnotatedTypeMirror right)
Returns the types of the two arguments to a binary operation, accounting for widening and
unboxing if applicable.
|
Pair<AnnotatedTypeMirror,AnnotatedTypeMirror> |
binaryTreeArgTypes(BinaryTree node)
Returns the types of the two arguments to the BinaryTree, accounting for widening and unboxing
if applicable.
|
@Nullable AnnotationMirror |
canonicalAnnotation(AnnotationMirror a)
Returns the canonical annotation for the passed annotation.
|
protected void |
checkInvalidOptionsInferSignatures()
This method is called only when
-Ainfer is passed as an option. |
Pair<AnnotatedTypeMirror,AnnotatedTypeMirror> |
compoundAssignmentTreeArgTypes(CompoundAssignmentTree node)
Returns the types of the two arguments to the CompoundAssignmentTree, accounting for widening
and unboxing if applicable.
|
AnnotatedTypeFactory.ParameterizedExecutableType |
constructorFromUse(NewClassTree tree)
Determines the type of the invoked constructor based on the passed new class tree.
|
protected void |
constructorFromUsePreSubstitution(NewClassTree tree,
AnnotatedTypeMirror.AnnotatedExecutableType type)
A callback method for the AnnotatedTypeFactory subtypes to customize the handling of the
declared constructor type before type variable substitution.
|
boolean |
containsSameByClass(Collection<? extends AnnotationMirror> c,
Class<? extends Annotation> anno)
Checks that the collection contains the annotation.
|
boolean |
containsUninferredTypeArguments(AnnotatedTypeMirror type)
Returns whether this type or any component type is a wildcard type for which Java 7 type
inference is insufficient.
|
protected AnnotatedTypeFormatter |
createAnnotatedTypeFormatter()
Creates the AnnotatedTypeFormatter used by this type factory and all AnnotatedTypeMirrors it
creates.
|
protected AnnotationClassLoader |
createAnnotationClassLoader()
Factory method to easily change what
AnnotationClassLoader is created to load type
annotation classes. |
protected AnnotationFormatter |
createAnnotationFormatter() |
protected QualifierHierarchy |
createQualifierHierarchy()
Returns the
QualifierHierarchy to be used by this checker. |
protected QualifierUpperBounds |
createQualifierUpperBounds()
Creates
QualifierUpperBounds for this type factory. |
protected Set<Class<? extends Annotation>> |
createSupportedTypeQualifiers()
Returns a mutable set of annotation classes that are supported by a checker.
|
protected TypeArgumentInference |
createTypeArgumentInference()
TypeArgumentInference infers the method type arguments when they are not explicitly written.
|
protected TypeHierarchy |
createTypeHierarchy()
Creates the type hierarchy to be used by this factory.
|
protected TypeVariableSubstitutor |
createTypeVariableSubstitutor()
TypeVariableSubstitutor provides a method to replace type parameters with their arguments.
|
Tree |
declarationFromElement(Element elt)
Gets the declaration tree for the element, if the source is available.
|
boolean |
doesAnnotatedForApplyToThisChecker(AnnotationMirror annotatedForAnno)
Does
anno , which is an AnnotatedFor
annotation, apply to this checker? |
AnnotatedTypeMirror |
fromElement(Element elt)
Creates an AnnotatedTypeMirror for
elt that includes: annotations explicitly written on
the element and annotations from stub files. |
AnnotatedTypeMirror.AnnotatedExecutableType |
fromElement(ExecutableElement elt)
See
fromElement(Element) . |
AnnotatedTypeMirror.AnnotatedDeclaredType |
fromElement(TypeElement elt)
See
fromElement(Element) . |
AnnotatedTypeMirror.AnnotatedDeclaredType |
fromNewClass(NewClassTree newClassTree)
Deprecated.
|
AnnotatedTypeMirror.AnnotatedNullType |
getAnnotatedNullType(Set<? extends AnnotationMirror> annotations)
Creates and returns an AnnotatedNullType qualified with
annotations . |
AnnotatedTypeMirror |
getAnnotatedType(Class<?> clazz)
Returns an AnnotatedTypeMirror representing the annotated type of
clazz . |
AnnotatedTypeMirror.AnnotatedDeclaredType |
getAnnotatedType(ClassTree tree)
|
AnnotatedTypeMirror |
getAnnotatedType(Element elt)
Returns an AnnotatedTypeMirror representing the annotated type of
elt . |
AnnotatedTypeMirror.AnnotatedExecutableType |
getAnnotatedType(ExecutableElement elt)
|
AnnotatedTypeMirror.AnnotatedExecutableType |
getAnnotatedType(MethodTree tree)
|
AnnotatedTypeMirror.AnnotatedArrayType |
getAnnotatedType(NewArrayTree tree)
|
AnnotatedTypeMirror.AnnotatedDeclaredType |
getAnnotatedType(NewClassTree tree)
|
AnnotatedTypeMirror |
getAnnotatedType(Tree tree)
Returns an AnnotatedTypeMirror representing the annotated type of
tree . |
AnnotatedTypeMirror.AnnotatedDeclaredType |
getAnnotatedType(TypeElement elt)
|
AnnotatedTypeFormatter |
getAnnotatedTypeFormatter() |
AnnotatedTypeMirror |
getAnnotatedTypeFromTypeTree(Tree tree)
Determines the annotated type from a type in tree form.
|
@Nullable AnnotationMirror |
getAnnotationByClass(Collection<? extends AnnotationMirror> c,
Class<? extends Annotation> anno)
Returns the AnnotationMirror in
c that has the same class as anno . |
AnnotationFormatter |
getAnnotationFormatter() |
@Nullable AnnotationMirror |
getAnnotationMirror(Tree tree,
Class<? extends Annotation> target)
Return the annotation on
tree that is in the hierarchy that contains the qualifier
target . |
List<Pair<AnnotationMirror,AnnotationMirror>> |
getAnnotationWithMetaAnnotation(Element element,
Class<? extends Annotation> metaAnnotationClass)
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
metaAnnotationClass . |
AnnotatedTypeMirror.AnnotatedDeclaredType |
getBoxedType(AnnotatedTypeMirror.AnnotatedPrimitiveType type)
Returns the annotated boxed type of the given primitive type.
|
protected Set<Class<? extends Annotation>> |
getBundledTypeQualifiers(Class<? extends Annotation>... explicitlyListedAnnotations)
Loads all annotations contained in the qual directory of a checker via reflection; if a
polymorphic type qualifier exists, and an explicit array of annotations to the set of
annotation classes.
|
protected int |
getCacheSize()
Returns the size for LRU caches.
|
BaseTypeChecker |
getChecker()
Returns the checker associated with this factory.
|
String[] |
getCheckerNames()
Returns the names of the annotation processors that are being run.
|
List<String> |
getContractExpressions(AnnotationMirror contractAnno)
Get the
expression field/element of the given contract annotation. |
List<AnnotationMirror> |
getContractListValues(AnnotationMirror contractListAnno)
Get the
value field/element of the given contract list annotation. |
protected ClassTree |
getCurrentClassTree(Tree tree)
Deprecated.
Use
TreePathUtil.enclosingClass(getPath(tree)) instead. |
protected @Nullable AnnotatedTypeMirror.AnnotatedDeclaredType |
getCurrentMethodReceiver(Tree tree)
Deprecated.
Use
getSelfType(Tree) instead. |
AnnotationMirror |
getDeclAnnotation(Element elt,
Class<? extends Annotation> anno)
Returns all of the declaration annotations whose name equals the passed annotation class (or is
an alias for it) including annotations:
on the element
written in stubfiles
inherited from overriden methods, (see
InheritedAnnotation )
inherited from superclasses or super interfaces (see Inherited )
|
AnnotationMirror |
getDeclAnnotationNoAliases(Element elt,
Class<? extends Annotation> anno)
Returns the actual annotation mirror used to annotate this element, whose name equals the
passed annotation class.
|
Set<AnnotationMirror> |
getDeclAnnotations(Element elt)
Returns all of the declaration annotations on this element including annotations:
on the element
written in stubfiles
inherited from overriden methods, (see
InheritedAnnotation )
inherited from superclasses or super interfaces (see Inherited )
|
List<Pair<AnnotationMirror,AnnotationMirror>> |
getDeclAnnotationWithMetaAnnotation(Element element,
Class<? extends Annotation> metaAnnotationClass)
Returns a list of all declaration annotations used to annotate the element, which have a
meta-annotation (i.e., an annotation on that annotation) with class
metaAnnotationClass . |
protected Set<? extends AnnotationMirror> |
getDefaultTypeDeclarationBounds()
Returns the set of qualifiers that are the upper bound for a type use if no other bound is
specified for the type.
|
@Nullable AnnotatedTypeMirror |
getDummyAssignedTo(ExpressionTree expressionTree)
Returns
null or an annotated type mirror that type argument inference should assume
expressionTree is assigned to. |
Elements |
getElementUtils()
Accessor for the element utilities.
|
@Nullable Tree |
getEnclosingClassOrMethod(Tree tree)
Returns the innermost enclosing method or class tree of
tree . |
Element |
getEnclosingElementForArtificialTree(Tree node)
Gets the
Element representing the declaration of the method enclosing a tree node. |
AnnotatedTypeMirror.AnnotatedDeclaredType |
getEnclosingType(TypeElement typeElement,
Tree tree)
Returns the
AnnotatedTypeMirror of the enclosing type at the location of tree
that is the same type as typeElement . |
Set<AnnotationMirror> |
getExplicitNewClassAnnos(NewClassTree newClassTree)
Returns the annotations explicitly written on a NewClassTree.
|
protected List<AnnotatedTypeMirror> |
getExplicitNewClassClassTypeArgs(NewClassTree newClass)
Returns the partially-annotated explicit class type arguments of the new class tree.
|
static Pair<String,String> |
getExpressionAndOffset(String expression)
Given an expression, split it into a subexpression and a constant offset.
|
AnnotationTree |
getFieldInvariantAnnotationTree(List<? extends AnnotationTree> annoTrees)
Returns the AnnotationTree which is a use of one of the field invariant annotations (as
specified via
getFieldInvariantDeclarationAnnotations() . |
protected Set<Class<? extends Annotation>> |
getFieldInvariantDeclarationAnnotations()
Returns the set of classes of field invariant annotations.
|
FieldInvariants |
getFieldInvariants(TypeElement element)
Returns the field invariants for the given class, as expressed by the user in
@FieldInvariant method annotations. |
Pair<AnnotatedTypeMirror,AnnotatedTypeMirror.AnnotatedExecutableType> |
getFnInterfaceFromTree(Tree tree)
Returns the functional interface and the function type that this lambda or member references
targets.
|
AnnotatedTypeMirror.AnnotatedExecutableType |
getFunctionTypeFromTree(LambdaExpressionTree tree)
Returns the function type that this lambda targets.
|
AnnotatedTypeMirror.AnnotatedExecutableType |
getFunctionTypeFromTree(MemberReferenceTree tree)
Returns the function type that this member reference targets.
|
protected @Nullable AnnotatedTypeMirror.AnnotatedDeclaredType |
getImplicitReceiverType(ExpressionTree tree)
Return the implicit receiver type of an expression tree.
|
AnnotatedTypeMirror |
getIterableElementType(ExpressionTree expression)
Return the element type of
expression . |
protected AnnotatedTypeMirror |
getIterableElementType(ExpressionTree expression,
AnnotatedTypeMirror iterableType)
Return the element type of
iterableType . |
AnnotatedTypeMirror |
getMethodReturnType(MethodTree m)
Returns the return type of the method
m . |
AnnotatedTypeMirror |
getMethodReturnType(MethodTree m,
ReturnTree r)
Returns the return type of the method
m at the return statement r . |
Set<AnnotationMirror> |
getNarrowedAnnotations(Set<AnnotationMirror> annos,
TypeKind typeKind,
TypeKind narrowedTypeKind)
Returns annotations applicable to type
narrowedTypeKind , that are copied or adapted
from annos . |
AnnotatedTypeMirror.AnnotatedPrimitiveType |
getNarrowedPrimitive(AnnotatedTypeMirror.AnnotatedPrimitiveType type,
TypeMirror narrowedTypeMirror)
Returns AnnotatedPrimitiveType with underlying type
narrowedTypeMirror and with
annotations copied or adapted from type . |
@Nullable TreePath |
getPath(Tree node)
Gets the path for the given
Tree under the current root by checking from the visitor's
current path, and using Trees.getPath(CompilationUnitTree, Tree) (which is much slower)
only if node is not found on the current path. |
ProcessingEnvironment |
getProcessingEnv()
Accessor for the processing environment.
|
QualifierHierarchy |
getQualifierHierarchy()
Returns the type qualifier hierarchy graph to be used by this processor.
|
Set<AnnotationMirror> |
getQualifierParameterHierarchies(AnnotatedTypeMirror annotatedType)
Returns the set of top annotations representing all the hierarchies for which this type has a
qualifier parameter.
|
Set<AnnotationMirror> |
getQualifierParameterHierarchies(Element element)
Returns the set of top annotations representing all the hierarchies for which this element has
a qualifier parameter.
|
QualifierUpperBounds |
getQualifierUpperBounds()
Return
QualifierUpperBounds for this type factory. |
AnnotatedTypeMirror |
getReceiverType(ExpressionTree expression)
Returns the receiver type of the expression tree, which might be the type of an implicit
this . |
@Nullable AnnotatedTypeMirror.AnnotatedDeclaredType |
getSelfType(Tree tree)
Returns the type of
this at the location of tree . |
AnnotatedTypeMirror.AnnotatedDeclaredType |
getStringType(AnnotatedTypeMirror type)
Returns AnnotatedDeclaredType with underlying type String and annotations copied from type.
|
Set<String> |
getSupportedTypeQualifierNames()
Returns an immutable set of the fully qualified names of the type qualifiers supported by this
checker.
|
Set<Class<? extends Annotation>> |
getSupportedTypeQualifiers()
Returns an immutable set of the classes corresponding to the type qualifiers supported by this
checker.
|
Trees |
getTreeUtils()
Accessor for the tree utilities.
|
TypeArgumentInference |
getTypeArgumentInference() |
Set<AnnotationMirror> |
getTypeDeclarationBounds(TypeMirror type)
Returns the set of qualifiers that are the upper bounds for a use of the type.
|
TypeHierarchy |
getTypeHierarchy() |
AnnotatedTypeMirror |
getTypeOfExtendsImplements(Tree clause)
Returns the type of the extends or implements clause.
|
TypeVariableSubstitutor |
getTypeVarSubstitutor() |
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)
Returns a wildcard type to be used as a type argument when the correct type could not be
inferred.
|
@Nullable TreePath |
getVisitorTreePath()
Returns the path to the tree that an external "visitor" is visiting.
|
WholeProgramInference |
getWholeProgramInference()
Returns the WholeProgramInference instance (may be null).
|
Set<AnnotationMirror> |
getWidenedAnnotations(Set<AnnotationMirror> annos,
TypeKind typeKind,
TypeKind widenedTypeKind)
Returns annotations applicable to type
widenedTypeKind , that are copied or adapted from
annos . |
AnnotatedTypeMirror |
getWidenedType(AnnotatedTypeMirror exprType,
AnnotatedTypeMirror widenedType)
Returns a widened type if applicable, otherwise returns its first argument.
|
AnnotatedTypeMirror |
getWidenedType(Set<AnnotationMirror> exprAnnos,
TypeMirror exprTypeMirror,
AnnotatedTypeMirror widenedType)
Applies widening if applicable, otherwise returns its first argument.
|
boolean |
hasExplicitNoQualifierParameterInHierarchy(Element element,
AnnotationMirror top)
Returns whether the
NoQualifierParameter annotation was explicitly written on element for the hierarchy given by top . |
boolean |
hasExplicitQualifierParameterInHierarchy(Element element,
AnnotationMirror top)
Returns whether the
HasQualifierParameter annotation was explicitly written on element for the hierarchy given by top . |
boolean |
hasQualifierParameterInHierarchy(AnnotatedTypeMirror annotatedTypeMirror,
AnnotationMirror top)
Whether or not the
annotatedTypeMirror has a qualifier parameter. |
boolean |
hasQualifierParameterInHierarchy(@Nullable Element element,
AnnotationMirror top)
Whether or not the
element has a qualifier parameter. |
void |
initializeAtm(AnnotatedTypeMirror type)
Initializes all fields of
type . |
protected void |
initializeReflectionResolution() |
boolean |
isFromByteCode(Element element)
Returns true if the element is from bytecode and the if the element did not appear in a stub
file.
|
boolean |
isFromStubFile(Element element)
Returns true if the element appears in a stub file (Currently only works for methods,
constructors, and fields).
|
boolean |
isImmutable(TypeMirror type)
Returns true if the type is immutable.
|
boolean |
isSupportedQualifier(@Nullable AnnotationMirror a)
Determines whether the given annotation is a part of the type system under which this type
factory operates.
|
boolean |
isSupportedQualifier(Class<? extends Annotation> clazz)
Determines whether the given class is a part of the type system under which this type factory
operates.
|
boolean |
isSupportedQualifier(String className)
Determines whether the given class name is a part of the type system under which this type
factory operates.
|
protected boolean |
isWithinConstructor(Tree tree)
Returns true if
tree is within a constructor. |
protected AnnotatedTypeMirror |
mergeAnnotationFileAnnosIntoType(@Nullable AnnotatedTypeMirror type,
Element elt,
AnnotationFileElementTypes source)
Merges types from annotation files for
elt into type by taking the greatest
lower bound of the annotations in both. |
AnnotatedTypeFactory.ParameterizedExecutableType |
methodFromUse(ExpressionTree tree,
ExecutableElement methodElt,
AnnotatedTypeMirror receiverType)
Determines the type of the invoked method based on the passed expression tree, executable
element, and receiver type.
|
AnnotatedTypeFactory.ParameterizedExecutableType |
methodFromUse(MethodInvocationTree tree)
Determines the type of the invoked method based on the passed method invocation tree.
|
protected void |
methodFromUsePreSubstitution(ExpressionTree tree,
AnnotatedTypeMirror.AnnotatedExecutableType type)
A callback method for the AnnotatedTypeFactory subtypes to customize the handling of the
declared method type before type variable substitution.
|
static String |
negateConstant(String constantExpression)
Given an expression string, returns its negation.
|
List<AnnotatedTypeMirror.AnnotatedTypeVariable> |
order(Collection<AnnotatedTypeMirror.AnnotatedTypeVariable> collection)
Returns the list of type variables such that a type variable in the list only references type
variables at a lower index than itself.
|
protected void |
parseAnnotationFiles()
Parses all annotation files in the following order:
jdk.astub in the same directory as the checker, if it exists and ignorejdkastub option is
not supplied
jdkN.astub, where N is the Java version in the same directory as the checker, if it exists and ignorejdkastub option is not supplied Stub files listed in @StubFiles annotation on the checker; must be in same directory as the checker Stub files provided via -Astubs compiler option Ajava files provided via -Aajava compiler option |
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 void |
postInit()
Actions that logically belong in the constructor, but need to run after the subclass
constructor has completed.
|
void |
postProcessClassTree(ClassTree tree)
Called by
BaseTypeVisitor.visitClass(ClassTree, Void) after the ClassTree has been type
checked. |
void |
prepareMethodForWriting(scenelib.annotations.el.AMethod methodAnnos)
Side-effects the method or constructor annotations to make any desired changes before writing
to an annotation file.
|
void |
prepareMethodForWriting(WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos methodAnnos)
Side-effects the method or constructor annotations to make any desired changes before writing
to an ajava file.
|
void |
preProcessClassTree(ClassTree classTree)
Called by
BaseTypeVisitor.visitClass(ClassTree, Void) before the classTree is type
checked. |
void |
replaceAnnotations(AnnotatedTypeMirror from,
AnnotatedTypeMirror to)
Replaces or adds all annotations from
from to to . |
void |
replaceAnnotations(AnnotatedTypeMirror from,
AnnotatedTypeMirror to,
AnnotationMirror top)
Replaces or adds annotations in
top 's hierarchy from from to to . |
void |
setEnclosingElementForArtificialTree(Tree tree,
Element enclosing)
Adds the given mapping from a synthetic (generated) tree to its enclosing element.
|
void |
setRoot(@Nullable CompilationUnitTree root)
Set the CompilationUnitTree that should be used.
|
void |
setVisitorTreePath(@Nullable TreePath visitorTreePath)
Sets the path to the tree that an external "visitor" is visiting.
|
boolean |
shouldWarnIfStubRedundantWithBytecode()
Returns true if redundancy between a stub file and bytecode should be reported.
|
protected AnnotatedTypeMirror |
toAnnotatedType(TypeMirror t,
boolean declaration)
A convenience method that converts a
TypeMirror to an empty AnnotatedTypeMirror
using AnnotatedTypeMirror.createType(javax.lang.model.type.TypeMirror, org.checkerframework.framework.type.AnnotatedTypeFactory, boolean) . |
String |
toString() |
protected AnnotatedTypeMirror |
type(Tree node)
Determines an empty annotated type of the given tree.
|
List<AnnotatedTypeParameterBounds> |
typeVariablesFromUse(AnnotatedTypeMirror.AnnotatedDeclaredType type,
TypeElement element)
Adapt the upper bounds of the type variables of a class relative to the type instantiation.
|
void |
wpiAdjustForUpdateField(Tree lhsTree,
Element element,
String fieldName,
AnnotatedTypeMirror rhsATM)
Changes the type of
rhsATM when being assigned to a field, for use by whole-program
inference. |
void |
wpiAdjustForUpdateNonField(AnnotatedTypeMirror rhsATM)
Changes the type of
rhsATM when being assigned to anything other than a field, for use
by whole-program inference. |
protected @Nullable CompilationUnitTree root
protected final ProcessingEnvironment processingEnv
public final Types types
TypeMirror
s.public final ExecutableElement methodValClassNameElement
public final ExecutableElement methodValMethodNameElement
public final ExecutableElement methodValParamsElement
protected QualifierHierarchy qualHierarchy
protected TypeHierarchy typeHierarchy
protected final AnnotatedTypeFormatter typeFormatter
protected QualifierUpperBounds qualifierUpperBounds
protected TypeVariableSubstitutor typeVarSubstitutor
protected TypeArgumentInference typeArgumentInference
public final AnnotationFileElementTypes stubTypes
public final AnnotationFileElementTypes ajavaTypes
public @Nullable AnnotationFileElementTypes currentFileAjavaTypes
ajavaTypes
, which only stores annotations on public elements, this
stores annotations on all element locations such as in anonymous class bodies.protected final BaseTypeChecker checker
public final int uid
protected ReflectionResolver reflectionResolver
protected AnnotationClassLoader loader
public WholeProgramInference.OutputFormat wpiOutputFormat
public boolean shouldCache
protected final Map<Tree,AnnotatedTypeMirror> fromExpressionTreeCache
protected final Map<Tree,AnnotatedTypeMirror> fromMemberTreeCache
protected final Map<Tree,AnnotatedTypeMirror> fromTypeTreeCache
protected final Map<Tree,Element> artificialTreeToEnclosingElementMap
public final boolean ignoreUninferredTypeArguments
protected final ExecutableElement objectGetClass
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. postInit must be the last call in the constructor or else types from stub files may not be created as expected.
checker
- the SourceChecker
to which this factory belongsIllegalArgumentException
- if either argument is null
public void initializeAtm(AnnotatedTypeMirror type)
type
.type
- annotated type mirrorprotected void checkInvalidOptionsInferSignatures()
-Ainfer
is passed as an option. It checks if another
option that should not occur simultaneously with the whole-program inference is also passed as
argument, and aborts the process if that is the case. For example, the whole-program inference
process was not designed to work with conservative defaults.
Subclasses may override this method to add more options.
protected void postInit()
public BaseTypeChecker getChecker()
public String[] getCheckerNames()
protected QualifierUpperBounds createQualifierUpperBounds()
QualifierUpperBounds
for this type factory.QualifierUpperBounds
for this type factorypublic QualifierUpperBounds getQualifierUpperBounds()
QualifierUpperBounds
for this type factory.QualifierUpperBounds
for this type factorypublic WholeProgramInference getWholeProgramInference()
protected void initializeReflectionResolution()
public void setRoot(@Nullable CompilationUnitTree root)
root
- the new compilation unit to use@SideEffectFree public String toString()
protected QualifierHierarchy createQualifierHierarchy()
QualifierHierarchy
to be used by this checker.
The implementation builds the type qualifier hierarchy for the getSupportedTypeQualifiers()
using the meta-annotations found in them. The current
implementation returns an instance of NoElementQualifierHierarchy
.
Subclasses must override this method if their qualifiers have elements; the method must
return an implementation of QualifierHierarchy
, such as ElementQualifierHierarchy
.
public final QualifierHierarchy getQualifierHierarchy()
QualifierHierarchy
for this checkercreateQualifierHierarchy()
protected TypeHierarchy createTypeHierarchy()
Subclasses may override this method to specify new type-checking rules beyond the typical Java subtyping rules.
public final TypeHierarchy getTypeHierarchy()
protected TypeVariableSubstitutor createTypeVariableSubstitutor()
public TypeVariableSubstitutor getTypeVarSubstitutor()
protected TypeArgumentInference createTypeArgumentInference()
public TypeArgumentInference getTypeArgumentInference()
protected AnnotationClassLoader createAnnotationClassLoader()
AnnotationClassLoader
is created to load type
annotation classes. Subclasses can override this method and return a custom
AnnotationClassLoader subclass to customize loading logic.protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers()
Subclasses may override this method to return a mutable set of their supported type qualifiers through one of the 5 approaches shown below.
Subclasses should not call this method; they should call getSupportedTypeQualifiers()
instead.
By default, a checker supports all annotations located in a subdirectory called qual that's located in the same directory as the checker. Note that only annotations defined
with the @Target({ElementType.TYPE_USE})
meta-annotation (and optionally with the
additional value of ElementType.TYPE_PARAMETER
, but no other ElementType
values) are automatically considered as supported annotations.
To support a different set of annotations than those in the qual subdirectory, or
that have other ElementType
values, see examples below.
In total, there are 5 ways to indicate annotations that are supported by a checker:
This is the default behavior. Simply place those annotations within the qual directory.
Place those annotations within the qual directory, and override createSupportedTypeQualifiers()
by calling getBundledTypeQualifiers(Class...)
with a varargs parameter list of the other annotations. Code example:
@Override protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() {
return getBundledTypeQualifiers(Regex.class, PartialRegex.class, RegexBottom.class, UnknownRegex.class);
}
createSupportedTypeQualifiers()
and return a mutable set of the supported annotations.
Code example:
@Override protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() {
return new HashSet<Class<? extends Annotation>>(
Arrays.asList(A.class, B.class));
}
The set of qualifiers returned by createSupportedTypeQualifiers()
must be a
fresh, mutable set. The methods getBundledTypeQualifiers(Class...)
must return a
fresh, mutable set
@SafeVarargs protected final Set<Class<? extends Annotation>> getBundledTypeQualifiers(Class<? extends Annotation>... explicitlyListedAnnotations)
This method can be called in the overridden versions of createSupportedTypeQualifiers()
in each checker.
explicitlyListedAnnotations
- a varargs array of explicitly listed annotation classes to
be added to the returned set. For example, it is used frequently to add Bottom qualifiers.protected AnnotatedTypeFormatter createAnnotatedTypeFormatter()
public AnnotatedTypeFormatter getAnnotatedTypeFormatter()
protected AnnotationFormatter createAnnotationFormatter()
public AnnotationFormatter getAnnotationFormatter()
public final Set<Class<? extends Annotation>> getSupportedTypeQualifiers()
Subclasses cannot override this method; they should override createSupportedTypeQualifiers
instead.
createSupportedTypeQualifiers()
public final Set<String> getSupportedTypeQualifierNames()
Subclasses cannot override this method; they should override createSupportedTypeQualifiers
instead.
createSupportedTypeQualifiers()
protected int getCacheSize()
-AatfCacheSize
option or the default cache size.public AnnotatedTypeMirror getAnnotatedType(Element elt)
elt
.elt
- the elementelt
public AnnotatedTypeMirror getAnnotatedType(Class<?> clazz)
clazz
.clazz
- a classclazz
public @Nullable AnnotationMirror getAnnotationMirror(Tree tree, Class<? extends Annotation> target)
AnnotationProvider
tree
that is in the hierarchy that contains the qualifier
target
. Returns null if none exists.getAnnotationMirror
in interface AnnotationProvider
tree
- the tree of which the annotation is returnedtarget
- the class of the annotationtree
that has the class target
, or nullpublic AnnotatedTypeMirror getAnnotatedType(Tree tree)
tree
.tree
- the AST nodetree
public void preProcessClassTree(ClassTree classTree)
BaseTypeVisitor.visitClass(ClassTree, Void)
before the classTree is type
checked.classTree
- ClassTree on which to perform preprocessingpublic void postProcessClassTree(ClassTree tree)
BaseTypeVisitor.visitClass(ClassTree, Void)
after the ClassTree has been type
checked.
The default implementation uses this to store the defaulted AnnotatedTypeMirrors and inherited declaration annotations back into the corresponding Elements. Subclasses might want to override this method if storing defaulted types is not desirable.
public AnnotatedTypeMirror getAnnotatedTypeFromTypeTree(Tree tree)
Note that we cannot decide from a Tree whether it is a type use or an expression. TreeUtils.isTypeTree is only an under-approximation. For example, an identifier can be either a type or an expression.
tree
- the type treepublic Set<AnnotationMirror> getTypeDeclarationBounds(TypeMirror type)
type
- a type whose upper bounds to obtainprotected Set<? extends AnnotationMirror> getDefaultTypeDeclarationBounds()
This implementation returns the top qualifiers by default. Subclass may override to return different qualifiers.
public AnnotatedTypeMirror getTypeOfExtendsImplements(Tree clause)
The primary qualifier is either an explicit annotation on clause
, or it is the
qualifier upper bounds for uses of the type of the clause.
clause
- tree that represents an extends or implements clausepublic AnnotatedTypeMirror fromElement(Element elt)
elt
that includes: annotations explicitly written on
the element and annotations from stub files.
Does not include default qualifiers. To obtain them, use getAnnotatedType(Element)
.
Does not include fake overrides from the stub file.
elt
- the elementprotected AnnotatedTypeMirror mergeAnnotationFileAnnosIntoType(@Nullable AnnotatedTypeMirror type, Element elt, AnnotationFileElementTypes source)
elt
into type
by taking the greatest
lower bound of the annotations in both.type
- the type to apply annotation file types toelt
- the element from which to read annotation file typessource
- storage for current annotation file annotationsprotected void addComputedTypeAnnotations(Tree tree, AnnotatedTypeMirror type)
Tree
. By default, this method does
nothing. GenericAnnotatedTypeFactory uses this method to implement defaulting and inference
(flow-sensitive type refinement). Its subclasses usually override it only to customize default
annotations.
Subclasses that override this method should also override addComputedTypeAnnotations(Element, AnnotatedTypeMirror)
.
In classes that extend GenericAnnotatedTypeFactory
, override GenericAnnotatedTypeFactory.addComputedTypeAnnotations(Tree, AnnotatedTypeMirror, boolean)
instead of this method.
tree
- an AST nodetype
- the type obtained from tree
protected void addComputedTypeAnnotations(Element elt, AnnotatedTypeMirror type)
Element
. By default, this method does
nothing. GenericAnnotatedTypeFactory uses this method to implement defaulting.
Subclasses that override this method should also override addComputedTypeAnnotations(Tree, AnnotatedTypeMirror)
.
elt
- an elementtype
- the type obtained from elt
public void addDefaultAnnotations(AnnotatedTypeMirror type)
type
. This method should only be used in places where the
correct annotations cannot be computed because of uninferred type arguments. (See AnnotatedTypeMirror.AnnotatedWildcardType.isUninferredTypeArgument()
.)type
- annotated type to which default annotations are addedprotected void postDirectSuperTypes(AnnotatedTypeMirror type, List<? extends AnnotatedTypeMirror> supertypes)
The default provided implementation adds type
annotations to supertypes
.
This allows the type
and its supertypes to have the qualifiers.
type
- the type whose supertypes are desiredsupertypes
- the supertypes as specified by the base AnnotatedTypeFactorypublic 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 addAnnotationFromFieldInvariant(AnnotatedTypeMirror type, AnnotatedTypeMirror accessedVia, VariableElement field)
field
to type
.type
- annotated type to which the annotation is addedaccessedVia
- the annotated type of the receiver of the accessing tree. (Only used to get
the type element of the underling type.)field
- element representing the fieldpublic FieldInvariants getFieldInvariants(TypeElement element)
@FieldInvariant
method annotations.
Subclasses may implement their own field invariant annotations if @FieldInvariant
is not expressive enough. They must override this method to
properly create AnnotationMirror and also override getFieldInvariantDeclarationAnnotations()
to return their field invariants.
element
- class for which to get invariantselement
public AnnotationTree getFieldInvariantAnnotationTree(List<? extends AnnotationTree> annoTrees)
getFieldInvariantDeclarationAnnotations()
. If one isn't found, null is
returned.annoTrees
- list of trees to search; the result is one of the list elements, or nullprotected Set<Class<? extends Annotation>> getFieldInvariantDeclarationAnnotations()
public List<AnnotatedTypeParameterBounds> typeVariablesFromUse(AnnotatedTypeMirror.AnnotatedDeclaredType type, 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.
An example of an adaptation follows. Suppose, I have a declaration:
class MyClass<E extends List<E>>
And an instantiation:
new MyClass<@NonNull String>()
The upper bound of E adapted to the argument String, would be List<@NonNull String>
and the lower bound would be an AnnotatedNullType.
TODO: ensure that this method is consistently used instead of directly querying the type variables.
type
- the use of the typeelement
- the corresponding elementpublic AnnotatedTypeMirror.AnnotatedNullType getAnnotatedNullType(Set<? extends AnnotationMirror> annotations)
annotations
.annotations
- set of AnnotationMirrors to qualify the returned type withannotations
protected @Nullable AnnotatedTypeMirror.AnnotatedDeclaredType getImplicitReceiverType(ExpressionTree tree)
The result is null for expressions that don't have a receiver, e.g. for a local variable or method parameter access. The result is also null for expressions that have an explicit receiver.
Clients should generally call getReceiverType(com.sun.source.tree.ExpressionTree)
.
tree
- the expression that might have an implicit receiverpublic @Nullable AnnotatedTypeMirror.AnnotatedDeclaredType getSelfType(Tree tree)
this
at the location of tree
. Returns null
if
tree
is in a location where this
has no meaning, such as the body of a static
method.
The parameter is an arbitrary tree and does not have to mention "this", neither explicitly nor implicitly. This method can be overridden for type-system specific behavior.
tree
- location used to decide the type of this
this
at the location of tree
public @Nullable Tree getEnclosingClassOrMethod(Tree tree)
tree
. If tree
is
artificial (that is, created by dataflow), then artificialTreeToEnclosingElementMap
is
used to find the enclosing tree.
If the tree is inside an annotation, then null
is returned.
tree
- tree to whose innermost enclosing method or class to returntree
, or null
if tree
is inside an annotationpublic AnnotatedTypeMirror.AnnotatedDeclaredType getEnclosingType(TypeElement typeElement, Tree tree)
AnnotatedTypeMirror
of the enclosing type at the location of tree
that is the same type as typeElement
.typeElement
- type of the enclosing type to returntree
- location to usetree
that is the same type as typeElement
public final AnnotatedTypeMirror getReceiverType(ExpressionTree expression)
this
. Returns null if the expression has no explicit or implicit receiver.expression
- the expression for which to determine the receiver typepublic AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(MethodInvocationTree tree)
The returned method type has all type variables resolved, whether based on receiver type, passed type parameters if any, and method invocation parameter.
Subclasses may override this method to customize inference of types or qualifiers based on method invocation parameters.
As an implementation detail, this method depends on 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(com.sun.source.tree.Tree, java.util.List<? extends org.checkerframework.framework.type.AnnotatedTypeParameterBounds>, java.util.List<? extends org.checkerframework.framework.type.AnnotatedTypeMirror>, java.util.List<? extends com.sun.source.tree.Tree>, java.lang.CharSequence, java.util.List<?>)
for the checks of type
argument well-formedness.
Note that "this" and "super" constructor invocations are also handled by this method
(explicit or implicit ones, at the beginning of a constructor). Method constructorFromUse(NewClassTree)
is only used for a constructor invocation in a "new"
expression.
tree
- the method invocation treepublic AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(ExpressionTree tree, ExecutableElement methodElt, AnnotatedTypeMirror receiverType)
tree
- either a MethodInvocationTree or a MemberReferenceTreemethodElt
- the element of the referenced methodreceiverType
- the type of the receivermethodFromUse(MethodInvocationTree)
protected void methodFromUsePreSubstitution(ExpressionTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type)
tree
- either a method invocation or a member reference treetype
- declared method type before type variable substitutionprotected void adaptGetClassReturnTypeToReceiver(AnnotatedTypeMirror.AnnotatedExecutableType getClassType, AnnotatedTypeMirror receiverType, ExpressionTree tree)
getClass()
. Though the
method has a return type of Class<?>
, the compiler special cases this return-type and
changes the bound of the type argument to the erasure of the receiver type. For example:
x.getClass()
has the type Class< ? extends erasure_of_x >
someInteger.getClass()
has the type Class< ? extends Integer >
getClassType
- this must be a type representing a call to Object.getClass otherwise a
runtime exception will be thrown. It is modified by side effect.receiverType
- the receiver type of the method invocation (not the declared receiver type)tree
- getClass method invocation treepublic AnnotatedTypeMirror getIterableElementType(ExpressionTree expression)
expression
. This is usually the type of expression.itertor().next()
. If expression
is an array, it is the component type of
the array.expression
- an expression whose type is an array or implements Iterable
expression.itertor().next()
or if expression
is an array,
the component type of the array.protected AnnotatedTypeMirror getIterableElementType(ExpressionTree expression, AnnotatedTypeMirror iterableType)
iterableType
. This is usually the type of expression.itertor().next()
. If expression
is an array, it is the component type of
the array.expression
- an expression whose type is an array or implements Iterable
iterableType
- the type of the expressionexpression.itertor().next()
or if expression
is an array,
the component type of the array.public AnnotatedTypeFactory.ParameterizedExecutableType constructorFromUse(NewClassTree tree)
The returned method type has all type variables resolved, whether based on receiver type, passed type parameters if any, and constructor invocation parameter.
Subclasses may override this method to customize inference of types or qualifiers based on constructor invocation parameters.
As an implementation detail, this method depends on AnnotatedTypes.asMemberOf(Types,
AnnotatedTypeFactory, AnnotatedTypeMirror, Element)
, and customization based on receiver type
should be in accordance with its specification.
The return type is a pair of the type of the invoked constructor 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(com.sun.source.tree.Tree, java.util.List<? extends org.checkerframework.framework.type.AnnotatedTypeParameterBounds>, java.util.List<? extends org.checkerframework.framework.type.AnnotatedTypeMirror>, java.util.List<? extends com.sun.source.tree.Tree>, java.lang.CharSequence, java.util.List<?>)
for the checks of type
argument well-formedness.
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 tree@Deprecated public AnnotatedTypeMirror.AnnotatedDeclaredType fromNewClass(NewClassTree newClassTree)
getExplicitNewClassAnnos(NewClassTree)
, getExplicitNewClassClassTypeArgs(NewClassTree)
, or getAnnotatedType(ClassTree)
instead.(Subclass beside GenericAnnotatedTypeFactory
should not override this method.)
newClassTree
- NewClassTreepublic Set<AnnotationMirror> getExplicitNewClassAnnos(NewClassTree newClassTree)
new @HERE Class()
newClassTree
- a constructor invocationprotected List<AnnotatedTypeMirror> getExplicitNewClassClassTypeArgs(NewClassTree newClass)
AnnotatedTypeMirror
only include the annotations explicitly written on the explict type
arguments. (If newClass
use a diamond operator, this method returns the empty list.)
For example, when called with new MyClass<@HERE String>()
this method would return a
list containing @HERE String
.newClass
- a new class treeAnnotatedTypeMirror
s for the (explicit) class type
arguments of the new class treeprotected void constructorFromUsePreSubstitution(NewClassTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type)
tree
- a NewClassTree from constructorFromUse()type
- declared method type before type variable substitutionpublic AnnotatedTypeMirror getMethodReturnType(MethodTree m)
m
.m
- tree of a method declarationpublic AnnotatedTypeMirror getMethodReturnType(MethodTree m, ReturnTree r)
m
at the return statement r
. This
implementation just calls getMethodReturnType(MethodTree)
, but subclasses may override
this method to change the type based on the return statement.m
- tree of a method declarationr
- a return statement within method m
m
at the return statement r
public AnnotatedTypeMirror.AnnotatedDeclaredType getBoxedType(AnnotatedTypeMirror.AnnotatedPrimitiveType type)
Subclasses may override this method safely to override this behavior.
type
- the primitive typepublic final AnnotatedTypeMirror.AnnotatedPrimitiveType applyUnboxing(AnnotatedTypeMirror type)
Subclasses should override getUnboxedType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType)
rather than this method.
type
- a type: a primitive or boxed primitivepublic AnnotatedTypeMirror.AnnotatedPrimitiveType getUnboxedType(AnnotatedTypeMirror.AnnotatedDeclaredType type) throws IllegalArgumentException
In the AnnotatedTypeFactory
implementation, the returned type has the same primary
annotations as the given type. Subclasses may override this behavior.
type
- the declared typeIllegalArgumentException
- if the type given has no unbox conversionpublic AnnotatedTypeMirror.AnnotatedDeclaredType getStringType(AnnotatedTypeMirror type)
type
- type to convert to Stringpublic final AnnotatedTypeMirror getWidenedType(AnnotatedTypeMirror exprType, AnnotatedTypeMirror widenedType)
Subclasses should override getWidenedAnnotations(java.util.Set<javax.lang.model.element.AnnotationMirror>, javax.lang.model.type.TypeKind, javax.lang.model.type.TypeKind)
rather than this method.
exprType
- type to possibly widenwidenedType
- type to possibly widen to; its annotations are ignoredtype
to the underlying type
of widenedType
; otherwise type
public final AnnotatedTypeMirror getWidenedType(Set<AnnotationMirror> exprAnnos, TypeMirror exprTypeMirror, AnnotatedTypeMirror widenedType)
Subclasses should override getWidenedAnnotations(java.util.Set<javax.lang.model.element.AnnotationMirror>, javax.lang.model.type.TypeKind, javax.lang.model.type.TypeKind)
rather than this method.
exprAnnos
- annotations to possibly widenexprTypeMirror
- type to possibly widenwidenedType
- type to possibly widen to; its annotations are ignoredtype
to the underlying type
of widenedType
; otherwise type
public Set<AnnotationMirror> getNarrowedAnnotations(Set<AnnotationMirror> annos, TypeKind typeKind, TypeKind narrowedTypeKind)
narrowedTypeKind
, that are copied or adapted
from annos
.annos
- annotations to narrow, from a primitive or boxed primitivetypeKind
- primitive type to narrownarrowedTypeKind
- target for the returned annotations; a primitive type that is narrower
than typeKind
(in the sense of JLS 5.1.3).annos
from typeKind
to narrowedTypeKind
public Set<AnnotationMirror> getWidenedAnnotations(Set<AnnotationMirror> annos, TypeKind typeKind, TypeKind widenedTypeKind)
widenedTypeKind
, that are copied or adapted from
annos
.annos
- annotations to widen, from a primitive or boxed primitivetypeKind
- primitive type to widenwidenedTypeKind
- target for the returned annotations; a primitive type that is wider than
typeKind
(in the sense of JLS 5.1.2)annos
from typeKind
to widenedTypeKind
public Pair<AnnotatedTypeMirror,AnnotatedTypeMirror> binaryTreeArgTypes(BinaryTree node)
node
- a binary treepublic Pair<AnnotatedTypeMirror,AnnotatedTypeMirror> compoundAssignmentTreeArgTypes(CompoundAssignmentTree node)
node
- a compound assignment treepublic Pair<AnnotatedTypeMirror,AnnotatedTypeMirror> binaryTreeArgTypes(AnnotatedTypeMirror left, AnnotatedTypeMirror right)
left
- the type of the left argument of a binary operationright
- the type of the right argument of a binary operationpublic AnnotatedTypeMirror.AnnotatedPrimitiveType getNarrowedPrimitive(AnnotatedTypeMirror.AnnotatedPrimitiveType type, TypeMirror narrowedTypeMirror)
narrowedTypeMirror
and with
annotations copied or adapted from type
.
Currently this method is called only for primitives that are narrowed at assignments from
literal ints, for example, byte b = 1;
. All other narrowing conversions happen at
typecasts.
type
- type to narrownarrowedTypeMirror
- underlying type for the returned type mirrortype
to narrowedTypeMirror
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.AnnotatedDeclaredType getAnnotatedType(TypeElement elt)
getAnnotatedType(Element)
public final AnnotatedTypeMirror.AnnotatedExecutableType getAnnotatedType(ExecutableElement elt)
getAnnotatedType(Element)
public final AnnotatedTypeMirror.AnnotatedDeclaredType fromElement(TypeElement elt)
fromElement(Element)
.fromElement(Element)
public final AnnotatedTypeMirror.AnnotatedExecutableType fromElement(ExecutableElement elt)
fromElement(Element)
.fromElement(Element)
public boolean isSupportedQualifier(@Nullable AnnotationMirror a)
a
- any annotationpublic boolean isSupportedQualifier(Class<? extends Annotation> clazz)
clazz
- annotation classpublic boolean isSupportedQualifier(String className)
className
- fully-qualified annotation class name@Deprecated protected void addAliasedAnnotation(Class<?> aliasClass, AnnotationMirror type)
addAliasedTypeAnnotation
aliasClass
as an alias for the canonical annotation type
that will be used by the Checker Framework in the alias's place.
By specifying the alias/canonical relationship using this method, the elements of the alias
are not preserved when the canonical annotation to use is constructed from the alias. If you
want the elements to be copied over as well, use addAliasedTypeAnnotation(Class, Class,
boolean, String...)
.
aliasClass
- the class of the aliased annotationtype
- the canonical annotationprotected void addAliasedTypeAnnotation(Class<?> aliasClass, AnnotationMirror canonicalAnno)
aliasClass
as an alias for the canonical annotation canonicalAnno
that will be used by the Checker Framework in the alias's place.
By specifying the alias/canonical relationship using this method, the elements of the alias
are not preserved when the canonical annotation to use is constructed from the alias. If you
want the elements to be copied over as well, use addAliasedTypeAnnotation(Class, Class,
boolean, String...)
.
aliasClass
- the class of the aliased annotationcanonicalAnno
- the canonical annotation@Deprecated protected void addAliasedAnnotation(@FullyQualifiedName String aliasName, AnnotationMirror canonicalAnno)
addAliasedTypeAnnotation(java.lang.Class<?>, javax.lang.model.element.AnnotationMirror)
aliasName
, as an alias for
the canonical annotation canonicalAnno
that will be used by the Checker Framework in
the alias's place.
Use this method if the alias class is not necessarily on the classpath at Checker Framework
compile and run time. Otherwise, use addAliasedTypeAnnotation(Class, AnnotationMirror)
which prevents the possibility of a typo in the class name.
aliasName
- the canonical name of the aliased annotationcanonicalAnno
- the canonical annotationprotected void addAliasedTypeAnnotation(@FullyQualifiedName String aliasName, AnnotationMirror canonicalAnno)
aliasName
, as an alias for
the canonical annotation canonicalAnno
that will be used by the Checker Framework in
the alias's place.
Use this method if the alias class is not necessarily on the classpath at Checker Framework
compile and run time. Otherwise, use addAliasedTypeAnnotation(Class, AnnotationMirror)
which prevents the possibility of a typo in the class name.
aliasName
- the canonical name of the aliased annotationcanonicalAnno
- the canonical annotation@Deprecated protected void addAliasedAnnotation(Class<?> aliasClass, Class<?> canonical, boolean copyElements, String... ignorableElements)
addAliasedTypeAnnotation
aliasClass
as an alias for the canonical annotation canonicalAnno
that will be used by the Checker Framework in the alias's place.
You may specify the copyElements flag to indicate whether you want the elements of the alias
to be copied over when the canonical annotation is constructed as a copy of canonicalAnno
. Be careful that the framework will try to copy the elements by name matching,
so make sure that names and types of the elements to be copied over are exactly the same as the
ones in the canonical annotation. Otherwise, an 'Couldn't find element in annotation' error is
raised.
To facilitate the cases where some of the elements are ignored on purpose when constructing
the canonical annotation, this method also provides a varargs ignorableElements
for you
to explicitly specify the ignoring rules. For example, org.checkerframework.checker.index.qual.IndexFor
is an alias of org.checkerframework.checker.index.qual.NonNegative
, but the element "value" of
@IndexFor
should be ignored when constructing @NonNegative
. In the cases where
all elements are ignored, we can simply use addAliasedTypeAnnotation(Class,
AnnotationMirror)
instead.
aliasClass
- the class of the aliased annotationcanonical
- the canonical annotationcopyElements
- a flag that indicates whether you want to copy the elements over when
getting the alias from the canonical annotationignorableElements
- a list of elements that can be safely dropped when the elements are
being copied overprotected void addAliasedTypeAnnotation(Class<?> aliasClass, Class<?> canonicalClass, boolean copyElements, String... ignorableElements)
aliasClass
as an alias for the canonical annotation canonicalClass
that will be used by the Checker Framework in the alias's place.
You may specify the copyElements flag to indicate whether you want the elements of the alias
to be copied over when the canonical annotation is constructed as a copy of canonicalClass
. Be careful that the framework will try to copy the elements by name matching,
so make sure that names and types of the elements to be copied over are exactly the same as the
ones in the canonical annotation. Otherwise, an 'Couldn't find element in annotation' error is
raised.
To facilitate the cases where some of the elements are ignored on purpose when constructing
the canonical annotation, this method also provides a varargs ignorableElements
for you
to explicitly specify the ignoring rules. For example, org.checkerframework.checker.index.qual.IndexFor
is an alias of org.checkerframework.checker.index.qual.NonNegative
, but the element "value" of
@IndexFor
should be ignored when constructing @NonNegative
. In the cases where
all elements are ignored, we can simply use addAliasedTypeAnnotation(Class,
AnnotationMirror)
instead.
aliasClass
- the class of the aliased annotationcanonicalClass
- the class of the canonical annotationcopyElements
- a flag that indicates whether you want to copy the elements over when
getting the alias from the canonical annotationignorableElements
- a list of elements that can be safely dropped when the elements are
being copied overprotected void addAliasedTypeAnnotation(@FullyQualifiedName String aliasName, Class<?> canonicalAnno, boolean copyElements, String... ignorableElements)
aliasName
, as an alias for
the canonical annotation canonicalAnno
that will be used by the Checker Framework in
the alias's place.
Use this method if the alias class is not necessarily on the classpath at Checker Framework
compile and run time. Otherwise, use addAliasedTypeAnnotation(Class, Class, boolean,
String[])
which prevents the possibility of a typo in the class name.
aliasName
- the canonical name of the aliased classcanonicalAnno
- the canonical annotationcopyElements
- a flag that indicates whether we want to copy the elements over when
getting the alias from the canonical annotationignorableElements
- a list of elements that can be safely dropped when the elements are
being copied overpublic @Nullable AnnotationMirror canonicalAnnotation(AnnotationMirror a)
A canonical annotation is the internal annotation that will be used by the Checker Framework in the aliased annotation's place.
a
- the qualifier to check for an aliasprotected void addAliasedDeclAnnotation(Class<? extends Annotation> alias, Class<? extends Annotation> annotation, AnnotationMirror annotationToUse)
alias
as an alias for the declaration annotation annotation
,
where the annotation mirror annotationToUse
will be used instead. If multiple calls are
made with the same annotation
, then the annotationToUse
must be the same.
The point of annotationToUse
is that it may include elements/fields.
protected void addInheritedAnnotation(AnnotationMirror annotation)
annotation
in the set of declaration annotations that should be
inherited. A declaration annotation will be inherited if it is in this list, or if it has the
meta-annotation @InheritedAnnotation. The meta-annotation @InheritedAnnotation should be used
instead of this method, if possible.protected final AnnotatedTypeMirror toAnnotatedType(TypeMirror t, boolean declaration)
TypeMirror
to an empty AnnotatedTypeMirror
using AnnotatedTypeMirror.createType(javax.lang.model.type.TypeMirror, org.checkerframework.framework.type.AnnotatedTypeFactory, boolean)
.t
- the TypeMirror
declaration
- true if the result should be marked as a type declarationAnnotatedTypeMirror
that has t
as its underlying typeprotected final AnnotatedTypeMirror type(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(Tree)
instead; this method is mostly
for internal use.
node
- the tree to analyzenode
, without any annotationspublic final Tree declarationFromElement(Element elt)
TODO: would be nice to move this to InternalUtils/TreeUtils.
elt
- an element@Deprecated protected final ClassTree getCurrentClassTree(Tree tree)
TreePathUtil.enclosingClass(getPath(tree))
instead.tree
.tree
- the tree whose enclosing class is returnedtree
@Deprecated protected final @Nullable AnnotatedTypeMirror.AnnotatedDeclaredType getCurrentMethodReceiver(Tree tree)
getSelfType(Tree)
instead.tree
.
The method uses the parameter only if the most enclosing method cannot be found directly.
tree
- the tree used to find the enclosing method.protected final boolean isWithinConstructor(Tree tree)
tree
is within a constructor.tree
- the tree that might be within a constructor.tree
is within a constructorpublic void setVisitorTreePath(@Nullable TreePath visitorTreePath)
BaseTypeVisitor
or CFAbstractTransfer
.visitorTreePath
- path to the current tree that an external "visitor" is visitingpublic @Nullable TreePath getVisitorTreePath()
getPath(Tree)
instead.
This method is used to save the previous tree path and to give a hint to getPath(Tree)
on where to look for a tree rather than searching starting at the root.
public final @Nullable TreePath getPath(@FindDistinct Tree node)
Tree
under the current root by checking from the visitor's
current path, and 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 root. Returns null if node
is not
within the current compilation unit.public final Element getEnclosingElementForArtificialTree(Tree node)
public final void setEnclosingElementForArtificialTree(Tree tree, Element enclosing)
See org.checkerframework.framework.flow.CFCFGBuilder.CFCFGTranslationPhaseOne.handleArtificialTree(Tree)
.
tree
- artifical treeenclosing
- element that encloses tree
protected void parseAnnotationFiles()
If a type is annotated with a qualifier from the same hierarchy in more than one stub file, the qualifier in the last stub file is applied.
The annotations are stored by side-effecting stubTypes
and ajavaTypes
.
public final AnnotationMirror getDeclAnnotation(Element elt, Class<? extends Annotation> anno)
InheritedAnnotation
)
Inherited
)
getDeclAnnotation
in interface AnnotationProvider
elt
- the element to retrieve the declaration annotation fromanno
- annotation classgetDeclAnnotationNoAliases(javax.lang.model.element.Element, java.lang.Class<? extends java.lang.annotation.Annotation>)
public final AnnotationMirror getDeclAnnotationNoAliases(Element elt, Class<? extends Annotation> anno)
Call this method from a checker that needs to alias annotations for one purpose and not for
another. For example, in the Lock Checker, @LockingFree
and @ReleasesNoLocks
are both aliases of @SideEffectFree
since they are all considered side-effect-free with
regard to the set of locks held before and after the method call. However, a synchronized
block is permitted inside a @ReleasesNoLocks
method but not inside a
@LockingFree
or @SideEffectFree
method.
elt
- the element to retrieve the declaration annotation fromanno
- annotation classgetDeclAnnotation(javax.lang.model.element.Element, java.lang.Class<? extends java.lang.annotation.Annotation>)
public boolean isFromStubFile(Element element)
public boolean isFromByteCode(Element element)
public boolean shouldWarnIfStubRedundantWithBytecode()
For most type systems the default behavior of returning true is correct. For subcheckers, redundancy in one of the type hierarchies can be ok. Such implementations should return false.
public Set<AnnotationMirror> getDeclAnnotations(Element elt)
InheritedAnnotation
)
Inherited
)
This method returns the actual annotations not their aliases. getDeclAnnotation(Element, Class)
returns aliases.
elt
- the element for which to determine annotationspublic List<Pair<AnnotationMirror,AnnotationMirror>> getDeclAnnotationWithMetaAnnotation(Element element, Class<? extends Annotation> metaAnnotationClass)
metaAnnotationClass
.element
- the element for which to determine annotationsmetaAnnotationClass
- the class of the meta-annotation that needs to be present(anno, metaAnno)
where anno
is the annotation mirror at
element
, and metaAnno
is the annotation mirror (of type metaAnnotationClass
) used to meta-annotate the declaration of anno
public List<Pair<AnnotationMirror,AnnotationMirror>> getAnnotationWithMetaAnnotation(Element element, Class<? extends Annotation> metaAnnotationClass)
metaAnnotationClass
.element
- the element at which to look for annotationsmetaAnnotationClass
- the class of 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 boolean hasQualifierParameterInHierarchy(AnnotatedTypeMirror annotatedTypeMirror, AnnotationMirror top)
annotatedTypeMirror
has a qualifier parameter.annotatedTypeMirror
- AnnotatedTypeMirror to checktop
- the top of the hierarchy to checkpublic boolean hasQualifierParameterInHierarchy(@Nullable Element element, AnnotationMirror top)
element
has a qualifier parameter.element
- element to checktop
- the top of the hierarchy to checkpublic boolean hasExplicitQualifierParameterInHierarchy(Element element, AnnotationMirror top)
HasQualifierParameter
annotation was explicitly written on element
for the hierarchy given by top
.element
- the Element to checktop
- the top qualifier for the hierarchy to checkelement
has been explicitly annotated with HasQualifierParameter
for the given hierarchypublic boolean hasExplicitNoQualifierParameterInHierarchy(Element element, AnnotationMirror top)
NoQualifierParameter
annotation was explicitly written on element
for the hierarchy given by top
.element
- the Element to checktop
- the top qualifier for the hierarchy to checkelement
has been explicitly annotated with NoQualifierParameter
for the given hierarchypublic Set<AnnotationMirror> getQualifierParameterHierarchies(AnnotatedTypeMirror annotatedType)
annotatedType
- AnnotatedTypeMirror to checkpublic Set<AnnotationMirror> getQualifierParameterHierarchies(Element element)
element
- the Element to checkpublic void replaceAnnotations(AnnotatedTypeMirror from, AnnotatedTypeMirror to)
from
to to
. Annotations from from
will be used everywhere they exist, but annotations in to
will be kept anywhere that
from
is unannotated.from
- the annotated type mirror from which to take new annotationsto
- the annotated type mirror to which the annotations will be addedpublic void replaceAnnotations(AnnotatedTypeMirror from, AnnotatedTypeMirror to, AnnotationMirror top)
top
's hierarchy from from
to to
.
Annotations from from
will be used everywhere they exist, but annotations in to
will be kept anywhere that from
is unannotated.from
- the annotated type mirror from which to take new annotationsto
- the annotated type mirror to which the annotations will be addedtop
- the top type of the hierarchy whose annotations will be addedpublic boolean containsUninferredTypeArguments(AnnotatedTypeMirror type)
type
- type to checkpublic AnnotatedTypeMirror.AnnotatedWildcardType getUninferredWildcardType(AnnotatedTypeMirror.AnnotatedTypeVariable typeVar)
AnnotatedTypeMirror.AnnotatedWildcardType.isUninferredTypeArgument()
returns true.
This method should only be used by type argument inference. org.checkerframework.framework.util.AnnotatedTypes.inferTypeArguments(ProcessingEnvironment, AnnotatedTypeFactory, ExpressionTree, ExecutableElement)
typeVar
- TypeVariable which could not be inferredpublic AnnotatedTypeMirror.AnnotatedExecutableType getFunctionTypeFromTree(MemberReferenceTree tree)
The function type is the type of the single method declared in the functional interface adapted as if it were invoked using the functional interface as the receiver expression.
The target type of a member reference is the type to which it is assigned or casted.
tree
- member reference treepublic AnnotatedTypeMirror.AnnotatedExecutableType getFunctionTypeFromTree(LambdaExpressionTree tree)
The function type is the type of the single method declared in the functional interface adapted as if it were invoked using the functional interface as the receiver expression.
The target type of a lambda is the type to which it is assigned or casted.
tree
- lambda expression treepublic Pair<AnnotatedTypeMirror,AnnotatedTypeMirror.AnnotatedExecutableType> getFnInterfaceFromTree(Tree tree)
The function type is the type of the single method declared in the functional interface adapted as if it were invoked using the functional interface as the receiver expression.
The target type of a lambda or a method reference is the type to which it is assigned or casted.
tree
- lambda expression tree or member reference treepublic AnnotatedTypeMirror applyCaptureConversion(AnnotatedTypeMirror typeToCapture)
typeToCapture
.
Capture conversion is the process of converting wildcards in a parameterized type to fresh type variables. See JLS 5.1.10 for details.
If type
is not a declared type or if it does not have any wildcard type arguments,
this method returns type
.
typeToCapture
- type to capturetypeToCapture
public AnnotatedTypeMirror applyCaptureConversion(AnnotatedTypeMirror type, TypeMirror typeMirror)
type
.
Capture conversion is the process of converting wildcards in a parameterized type to fresh type variables. See JLS 5.1.10 for details.
If type
is not a declared type or if it does not have any wildcard type arguments,
this method returns type
.
type
- type to capturetypeMirror
- the result of applying capture conversion to the underlying type of type
; it is used as the underlying type of the returned typetype
public List<AnnotatedTypeMirror.AnnotatedTypeVariable> order(Collection<AnnotatedTypeMirror.AnnotatedTypeVariable> collection)
collection
- a collection of type variablespublic Elements getElementUtils()
public Trees getTreeUtils()
public ProcessingEnvironment getProcessingEnv()
public static Pair<String,String> getExpressionAndOffset(String expression)
"a" => <"a", "0">
"a + 5" => <"a", "5">
"a + -5" => <"a", "-5">
"a - 5" => <"a", "-5">
There are methods that can only take as input an expression that represents a JavaExpression.
The purpose of this is to pre-process expressions to make those methods more likely to succeed.expression
- an expression to remove a constant offset frompublic static String negateConstant(String constantExpression)
constantExpression
- a string representing an integer constantpublic @Nullable AnnotatedTypeMirror getDummyAssignedTo(ExpressionTree expressionTree)
null
or an annotated type mirror that type argument inference should assume
expressionTree
is assigned to.
If null
is returned, inference proceeds normally.
If a type is returned, then inference assumes that expressionTree
was asigned to it.
This biases the inference algorithm toward the annotations in the returned type. In particular,
if the annotations on type variables in invariant positions are a super type of the annotations
inferred, the super type annotations are chosen.
This implementation returns null, but subclasses may override this method to return a type.
expressionTree
- an expression which has no assignment context and for which type
arguments need to be inferrednull
or an annotated type mirror that inferrence should pretend expressionTree
is assigned topublic boolean areSameByClass(AnnotationMirror am, Class<? extends Annotation> annoClass)
am
has the name of annoClass
. Values are ignored.
This method is faster than AnnotationUtils.areSameByClass(AnnotationMirror, Class)
because it caches the name of the class rather than computing it each time.
am
- the AnnotationMirror whose class to compareannoClass
- the class to comparepublic boolean containsSameByClass(Collection<? extends AnnotationMirror> c, Class<? extends Annotation> anno)
This method is faster than AnnotationUtils.containsSameByClass(Collection, Class)
because is caches the name of the class rather than computing it each time.
c
- a collection of AnnotationMirrorsanno
- the annotation class to search for in cpublic @Nullable AnnotationMirror getAnnotationByClass(Collection<? extends AnnotationMirror> c, Class<? extends Annotation> anno)
c
that has the same class as anno
.
This method is faster than AnnotationUtils.getAnnotationByClass(Collection, Class)
because is caches the name of the class rather than computing it each time.
c
- a collection of AnnotationMirrorsanno
- the class to search for in canno
iff c contains anno, according to
areSameByClass; otherwise, null
public void wpiAdjustForUpdateField(Tree lhsTree, Element element, String fieldName, AnnotatedTypeMirror rhsATM)
rhsATM
when being assigned to a field, for use by whole-program
inference. The default implementation does nothing.lhsTree
- the tree for the field whose type will be changedelement
- the element for the field whose type will be changedfieldName
- the name of the field whose type will be changedrhsATM
- the type of the expression being assigned to the field, which is side-effected by
this methodpublic void wpiAdjustForUpdateNonField(AnnotatedTypeMirror rhsATM)
rhsATM
when being assigned to anything other than a field, for use
by whole-program inference. The default implementation does nothing.rhsATM
- the type of the rhs of the pseudo-assignment, which is side-effected by this
methodpublic void prepareMethodForWriting(scenelib.annotations.el.AMethod methodAnnos)
methodAnnos
- the method or constructor annotations to modifypublic void prepareMethodForWriting(WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos methodAnnos)
methodAnnos
- the method or constructor annotations to modifypublic boolean doesAnnotatedForApplyToThisChecker(AnnotationMirror annotatedForAnno)
anno
, which is an AnnotatedFor
annotation, apply to this checker?annotatedForAnno
- an AnnotatedFor
annotationanno
applies to this checkerpublic List<String> getContractExpressions(AnnotationMirror contractAnno)
expression
field/element of the given contract annotation.contractAnno
- a RequiresQualifier
, EnsuresQualifier
, or EnsuresQualifier
expression
field/element of the given annotationpublic List<AnnotationMirror> getContractListValues(AnnotationMirror contractListAnno)
value
field/element of the given contract list annotation.contractListAnno
- a RequiresQualifier.List
, EnsuresQualifier.List
, or
EnsuresQualifier.List
value
field/element of the given annotationpublic boolean isImmutable(TypeMirror type)
type
- type to test.