public class KeyForAnnotatedTypeFactory extends GenericAnnotatedTypeFactory<CFValue,CFStore,KeyForTransfer,KeyForAnalysis>
Modifier and Type | Class and Description |
---|---|
protected class |
KeyForAnnotatedTypeFactory.KeyForTypeHierarchy |
GenericAnnotatedTypeFactory.ScanState
AnnotatedTypeFactory.InheritedFromClassAnnotator
Modifier and Type | Field and Description |
---|---|
protected Class<? extends Annotation> |
checkerKeyForClass |
protected Pattern |
identifierPattern
Matches an identifier
|
protected String |
identifierRegex
Regular expression for an identifier
|
protected AnnotationMirror |
KEYFOR |
protected AnnotationMirror |
UNKNOWNKEYFOR |
analyses, cfgVisualizer, defaults, FLOW_BY_DEFAULT, flowResult, initializationStaticStore, initializationStore, methodInvocationStores, poly, regularExitStores, returnStatementStores, scannedClasses, treeAnnotator, typeAnnotator
checker, elements, fromTreeCache, loader, processingEnv, qualHierarchy, reflectionResolver, root, shouldCache, trees, typeArgumentInference, typeFormatter, typeHierarchy, types, typeVarSubstitutor, uid, visitorState
Constructor and Description |
---|
KeyForAnnotatedTypeFactory(BaseTypeChecker checker) |
Modifier and Type | Method and Description |
---|---|
void |
canonicalizeForViewpointAdaptation(ExpressionTree invocation,
AnnotatedTypeMirror type)
Immediately before AnnotatedTypes.findTypeArguments we canonicalize flow
expressions using the parameters for the current method (not the one
being invoked but the one in which it is contained) and otherwise the
flow expression context from the invocation expression.
|
Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<AnnotatedTypeMirror>> |
constructorFromUse(NewClassTree tree)
Determines the type of the invoked constructor based on the passed new
class tree.
|
AnnotationMirror |
createKeyForAnnotationMirrorWithValue(LinkedHashSet<String> values) |
AnnotationMirror |
createKeyForAnnotationMirrorWithValue(String value) |
QualifierHierarchy |
createQualifierHierarchy(MultiGraphQualifierHierarchy.MultiGraphFactory factory)
Factory method to easily change what QualifierHierarchy is
created.
|
protected Set<Class<? extends Annotation>> |
createSupportedTypeQualifiers()
Returns a mutable set of annotation classes that are supported by a checker
|
protected TreeAnnotator |
createTreeAnnotator()
Returns a
TreeAnnotator that adds annotations to a type based
on the contents of a tree. |
protected TypeArgumentInference |
createTypeArgumentInference()
TypeArgumentInference infers the method type arguments when
they are not explicitly written.
|
protected TypeHierarchy |
createTypeHierarchy()
Creates the type subtyping checker using the current type qualifier
hierarchy.
|
void |
keyForCanonicalizeValues(AnnotatedTypeMirror varType,
AnnotatedTypeMirror valueType,
TreePath path) |
boolean |
keyForValuesSubtypeCheck(AnnotationMirror varType,
AnnotatedTypeMirror valueType,
Tree t,
MethodInvocationNode node) |
Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<AnnotatedTypeMirror>> |
methodFromUse(MethodInvocationTree call)
Determines the type of the invoked method based on the passed method
invocation tree.
|
addCheckedCodeDefaults, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotations, addTypeNameImplicit, addUncheckedCodeDefaults, analyze, analyze, applyInferredAnnotations, checkAndPerformFlowAnalysis, createCFGVisualizer, createFlowAnalysis, createFlowTransferFunction, createQualifierDefaults, createQualifierPolymorphism, createTypeAnnotator, getAnnotatedTypeLhs, getAnnotatedTypeLhsNoTypeVarDefault, getCFGVisualizer, getEmptyStore, getFinalLocalValues, getInferredValueFor, getNodeForTree, getRegularExitStore, getResultingTypeOfConstructorMemberReference, getReturnStatementStores, getShouldDefaultTypeVarLocals, getSortedQualifierNames, getStoreAfter, getStoreBefore, getStoreBefore, getSupportedMonotonicTypeQualifiers, getTypeFactoryOfSubchecker, handleCFGViz, performFlowAnalysis, postDirectSuperTypes, postInit, preProcessClassTree, setRoot
adaptGetClassReturnTypeToReceiver, addAliasedAnnotation, addAliasedDeclAnnotation, addInheritedAnnotation, aliasedAnnotation, annotateInheritedFromClass, annotateInheritedFromClass, checkInvalidOptionsInferSignatures, createAnnotatedTypeFormatter, createAnnotationFormatter, createQualifierHierarchy, createQualifierHierarchy, createQualifierHierarchyFactory, createTypeVariableSubstitutor, declarationFromElement, fromElement, fromElement, fromElement, fromNewClass, getAnnotatedNullType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFromTypeTree, getAnnotationFormatter, getAnnotationMirror, getAnnotationWithMetaAnnotation, getBoxedType, getBundledTypeQualifiersWithoutPolyAll, getBundledTypeQualifiersWithPolyAll, getContext, getCurrentClassTree, getCurrentClassType, getCurrentMethodReceiver, getDeclAnnotation, getDeclAnnotationNoAliases, getDeclAnnotations, getDeclAnnotationWithMetaAnnotation, getElementUtils, getEnclosingMethod, getEnclosingType, getFnInterfaceFromTree, getFnInterfaceFromTree, getImplicitReceiverType, getMethodReturnType, getMethodReturnType, getNarrowedPrimitive, getPath, getProcessingEnv, getQualifierHierarchy, getReceiverType, getSelfType, getStringType, getSupportedTypeQualifiers, getTreeUtils, getTypeArgumentInference, getTypeHierarchy, getTypeVarSubstitutor, getUnboxedType, getUninferredWildcardType, getVisitorState, getWholeProgramInference, initilizeReflectionResolution, isAnyEnclosingThisDeref, isFromByteCode, isFromStubFile, isMostEnclosingThisDeref, isSupportedQualifier, isWithinConstructor, methodFromUse, parseStubFiles, postAsMemberOf, postProcessClassTree, postTypeVarSubstitution, setPathHack, toAnnotatedType, toString, type, typeVariablesFromUse, widenToUpperBound
protected final AnnotationMirror UNKNOWNKEYFOR
protected final AnnotationMirror KEYFOR
protected final Class<? extends Annotation> checkerKeyForClass
protected final String identifierRegex
protected final Pattern identifierPattern
public KeyForAnnotatedTypeFactory(BaseTypeChecker checker)
protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers()
AnnotatedTypeFactory
Subclasses may override this method and 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
AnnotatedTypeFactory.getSupportedTypeQualifiers()
instead.
By default, a checker supports PolyAll
, and 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.
Annotations located outside the qual subdirectory, or has other
ElementType
values must be explicitly listed in code by overriding
the
AnnotatedTypeFactory.createSupportedTypeQualifiers()
method, as shown below.
Lastly, for checkers that do not want to support PolyAll
, it must
also be explicitly written in code, as shown below.
In total, there are 5 ways to indicate annotations that are supported by a checker:
PolyAll
:
This is the default behavior. Simply place those annotations within the qual directory.
PolyAll
:
Place those annotations within the qual directory, and override
AnnotatedTypeFactory.createSupportedTypeQualifiers()
by calling
AnnotatedTypeFactory.getBundledTypeQualifiersWithPolyAll(Class...)
with no
parameters passed in. Code example:
@Override protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() {
return getBundledTypeQualifiersWithoutPolyAll();
}
PolyAll
, and a list of other annotations:
Place those annotations within the qual directory, and override
AnnotatedTypeFactory.createSupportedTypeQualifiers()
by calling
AnnotatedTypeFactory.getBundledTypeQualifiersWithPolyAll(Class...)
with a
varargs parameter list of the other annotations. Code example:
@Override protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() {
return getBundledTypeQualifiersWithPolyAll(Regex.class, PartialRegex.class, RegexBottom.class, UnknownRegex.class);
}
PolyAll
:
Place those annotations within the qual directory, and override
AnnotatedTypeFactory.createSupportedTypeQualifiers()
by calling
AnnotatedTypeFactory.getBundledTypeQualifiersWithoutPolyAll(Class...)
with a
varargs parameter list of the other annotations. Code example:
@Override protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() {
return getBundledTypeQualifiersWithoutPolyAll(UnknownFormat.class, FormatBottom.class);
}
AnnotatedTypeFactory.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
AnnotatedTypeFactory.createSupportedTypeQualifiers()
must be a fresh, mutable
set. The methods
AnnotatedTypeFactory.getBundledTypeQualifiersWithoutPolyAll(Class...)
and
AnnotatedTypeFactory.getBundledTypeQualifiersWithPolyAll(Class...)
each
must return a fresh, mutable set
createSupportedTypeQualifiers
in class AnnotatedTypeFactory
protected TypeArgumentInference createTypeArgumentInference()
AnnotatedTypeFactory
createTypeArgumentInference
in class AnnotatedTypeFactory
public Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<AnnotatedTypeMirror>> constructorFromUse(NewClassTree tree)
AnnotatedTypeFactory
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(Tree, List, List, List)
for the checks of type argument well-formedness.
Note that "this" and "super" constructor invocations are handled by
method AnnotatedTypeFactory.methodFromUse(com.sun.source.tree.MethodInvocationTree)
. This method only handles constructor invocations
in a "new" expression.
constructorFromUse
in class GenericAnnotatedTypeFactory<CFValue,CFStore,KeyForTransfer,KeyForAnalysis>
tree
- the constructor invocation treepublic Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<AnnotatedTypeMirror>> methodFromUse(MethodInvocationTree call)
AnnotatedTypeFactory
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(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 AnnotatedTypeFactory.constructorFromUse(NewClassTree)
is only used for a constructor
invocation in a "new" expression.
methodFromUse
in class GenericAnnotatedTypeFactory<CFValue,CFStore,KeyForTransfer,KeyForAnalysis>
call
- the method invocation treeprotected TypeHierarchy createTypeHierarchy()
AnnotatedTypeFactory
Subclasses may override this method to specify new type-checking rules beyond the typical java subtyping rules.
createTypeHierarchy
in class AnnotatedTypeFactory
protected TreeAnnotator createTreeAnnotator()
GenericAnnotatedTypeFactory
TreeAnnotator
that adds annotations to a type based
on the contents of a tree.
Subclasses may override this method to specify a more appropriate
TreeAnnotator
.createTreeAnnotator
in class GenericAnnotatedTypeFactory<CFValue,CFStore,KeyForTransfer,KeyForAnalysis>
public AnnotationMirror createKeyForAnnotationMirrorWithValue(LinkedHashSet<String> values)
public AnnotationMirror createKeyForAnnotationMirrorWithValue(String value)
public boolean keyForValuesSubtypeCheck(AnnotationMirror varType, AnnotatedTypeMirror valueType, Tree t, MethodInvocationNode node)
public void keyForCanonicalizeValues(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, TreePath path)
public QualifierHierarchy createQualifierHierarchy(MultiGraphQualifierHierarchy.MultiGraphFactory factory)
AnnotatedTypeFactory
createQualifierHierarchy
in class AnnotatedTypeFactory
public void canonicalizeForViewpointAdaptation(ExpressionTree invocation, AnnotatedTypeMirror type)