public class GuiEffectTypeFactory extends BaseAnnotatedTypeFactory
GenericAnnotatedTypeFactory.ScanState
AnnotatedTypeFactory.ParameterizedExecutableType
Modifier and Type | Field and Description |
---|---|
protected boolean |
debugSpew |
protected Set<TypeElement> |
uiAnonClasses
Keeps track of all anonymous inner classes with inferred UIEffect.
|
protected Set<LambdaExpressionTree> |
uiLambdas
Keeps track of all lambda expressions with inferred UIEffect.
|
analysis, cfgVisualizer, defaults, dependentTypesHelper, emptyStore, exceptionalExitStores, flowByDefault, flowResult, flowResultAnalysisCaches, initializationStaticStore, initializationStore, methodInvocationStores, poly, regularExitStores, returnStatementStores, scannedClasses, transfer, treeAnnotator, typeAnnotator
artificialTreeToEnclosingElementMap, checker, elements, fromExpressionTreeCache, fromMemberTreeCache, fromTypeTreeCache, ignoreUninferredTypeArguments, loader, objectGetClass, processingEnv, qualHierarchy, qualifierUpperBounds, reflectionResolver, root, shouldCache, stubTypes, trees, typeArgumentInference, typeFormatter, typeHierarchy, types, typeVarSubstitutor, uid, visitorState
Constructor and Description |
---|
GuiEffectTypeFactory(BaseTypeChecker checker,
boolean spew) |
Modifier and Type | Method and Description |
---|---|
void |
constrainAnonymousClassToUI(TypeElement classElt)
Force the given anonymous inner class to be an @UI instantiation of its base class.
|
void |
constrainLambdaToUI(LambdaExpressionTree lambdaExpressionTree)
Force the given lambda expression to have UIEffect.
|
protected TreeAnnotator |
createTreeAnnotator()
Returns a
TreeAnnotator that adds annotations to a type based on the contents of a
tree. |
Effect.EffectRange |
findInheritedEffectRange(TypeElement declaringType,
ExecutableElement overridingMethod) |
Effect.EffectRange |
findInheritedEffectRange(TypeElement declaringType,
ExecutableElement overridingMethod,
boolean issueConflictWarning,
Tree errorNode) |
ExecutableElement |
findJavaOverride(ExecutableElement overrider,
TypeMirror parentType) |
AnnotatedTypeMirror |
getAnnotatedType(Tree tree)
Returns an AnnotatedTypeMirror representing the annotated type of
tree . |
Effect |
getComputedEffectAtCallsite(MethodInvocationTree node,
AnnotatedTypeMirror.AnnotatedDeclaredType callerReceiver,
ExecutableElement methodElt)
Get the effect of a method call at its callsite, acknowledging polymorphic instantiation
using type use annotations.
|
Effect |
getDeclaredEffect(ExecutableElement methodElt)
Calling context annotations.
|
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.
|
Effect |
getInferedEffectForLambdaExpression(LambdaExpressionTree lambdaTree)
Get the inferred effect of a lambda expression based on the type annotations of its
functional interface and the effects of the calls in its body.
|
boolean |
isDirectlyMarkedUIThroughInference(Tree tree)
Test if this tree corresponds to a lambda expression or new class marked as UI affecting by
either
constrainLambdaToUI } or constrainAnonymousClassToUI(TypeElement) . |
boolean |
isPolymorphicType(TypeElement cls) |
boolean |
isUIType(TypeElement cls) |
createFlowAnalysis
addAnnotationsFromDefaultForType, addCheckedCodeDefaults, addCheckedStandardDefaults, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotations, addDefaultAnnotations, addUncheckedStandardDefaults, analyze, applyInferredAnnotations, applyQualifierParameterDefaults, applyQualifierParameterDefaults, checkAndPerformFlowAnalysis, checkForDefaultQualifierInHierarchy, constructorFromUse, constructorFromUsePreSubstitution, createAndInitQualifierDefaults, createCFGVisualizer, createDefaultForTypeAnnotator, createDefaultForUseTypeAnnotator, createDependentTypesHelper, createFlowTransferFunction, createQualifierDefaults, createQualifierPolymorphism, createTypeAnnotator, fromNewClass, getAnnotatedTypeLhs, getAnnotatedTypeLhsNoTypeVarDefault, getAnnotatedTypeRhsUnaryAssign, getAnnotatedTypeVarargsArray, getAnnotationFromJavaExpressionString, getAnnotationFromReceiver, getAnnotationMirrorFromJavaExpressionString, getCFGVisualizer, getDependentTypesHelper, getEmptyStore, getExceptionalExitStore, getFinalLocalValues, getFirstNodeOfKindForTree, getInferredValueFor, getMethodReturnType, getMethodReturnType, getNodesForTree, getQualifierPolymorphism, getReceiverAndOffsetFromJavaExpressionString, getReceiverFromJavaExpressionString, getRegularExitStore, getResultingTypeOfConstructorMemberReference, getReturnStatementStores, getShouldDefaultTypeVarLocals, getSortedQualifierNames, getStoreAfter, getStoreAfter, getStoreAfter, getStoreBefore, getStoreBefore, getStoreBefore, getSupportedMonotonicTypeQualifiers, getTypeFactoryOfSubchecker, handleCFGViz, methodFromUse, methodFromUsePreSubstitution, performFlowAnalysis, postAnalyze, postAsMemberOf, postDirectSuperTypes, postInit, preProcessClassTree, setRoot, typeVariablesFromUse
adaptGetClassReturnTypeToReceiver, addAliasedAnnotation, addAliasedAnnotation, addAliasedAnnotation, addAliasedAnnotation, addAliasedDeclAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, applyUnboxing, areSameByClass, binaryTreeArgTypes, canonicalAnnotation, checkInvalidOptionsInferSignatures, containsSameByClass, createAnnotatedTypeFormatter, createAnnotationClassLoader, createAnnotationFormatter, createQualifierHierarchy, createQualifierHierarchyWithMultiGraphFactory, createQualifierUpperBounds, createSupportedTypeQualifiers, createTypeArgumentInference, createTypeHierarchy, createTypeVariableSubstitutor, declarationFromElement, fromElement, fromElement, fromElement, getAnnotatedNullType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFormatter, getAnnotatedTypeFromTypeTree, getAnnotationByClass, getAnnotationFormatter, getAnnotationMirror, getAnnotationWithMetaAnnotation, getBoxedType, getBundledTypeQualifiers, getCacheSize, getContext, getCurrentClassTree, getCurrentClassType, getCurrentMethodReceiver, getDeclAnnotation, getDeclAnnotationNoAliases, getDeclAnnotations, getDeclAnnotationWithMetaAnnotation, getDummyAssignedTo, getElementUtils, getEnclosingClassOrMethod, getEnclosingElementForArtificialTree, getEnclosingType, getExpressionAndOffset, getFieldInvariantAnnotationTree, getFieldInvariantDeclarationAnnotations, getFieldInvariants, getFnInterfaceFromTree, getFunctionTypeFromTree, getFunctionTypeFromTree, getImplicitReceiverType, getNarrowedPrimitive, getPath, getProcessingEnv, getQualifierHierarchy, getQualifierParameterHierarchies, getQualifierParameterHierarchies, getQualifierUpperBounds, getReceiverType, getSelfType, getStringType, getSupportedTypeQualifierNames, getSupportedTypeQualifiers, getTreeUtils, getTypeArgumentInference, getTypeDeclarationBounds, getTypeHierarchy, getTypeOfExtendsImplements, getTypeVarSubstitutor, getUnboxedType, getUninferredWildcardType, getVisitorState, getWholeProgramInference, getWidenedAnnotations, getWidenedType, hasExplicitNoQualifierParameterInHierarchy, hasExplicitQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, initializeReflectionResolution, isFromByteCode, isFromStubFile, isSupportedQualifier, isSupportedQualifier, isSupportedQualifier, isWithinConstructor, mergeStubsIntoType, methodFromUse, negateConstant, parseStubFiles, postProcessClassTree, postTypeVarSubstitution, setEnclosingElementForArtificialTree, shouldWarnIfStubRedundantWithBytecode, toAnnotatedType, toString, type, widenToUpperBound
protected final boolean debugSpew
protected final Set<LambdaExpressionTree> uiLambdas
constrainLambdaToUI
adds lambda
expressions to this set, and is called from GuiEffectVisitor whenever a lambda expression
calls a @UIEffect method. Afterwards getInferedEffectForLambdaExpression
uses this set and the type annotations of the functional
interface of the lambda to figure out if it can affect the UI or not.
protected final Set<TypeElement> uiAnonClasses
constrainAnonymousClassToUI
adds
anonymous inner classes to this set, and is called from GuiEffectVisitor whenever an
anonymous inner class calls a @UIEffect method. Afterwards isUIType
and getAnnotatedType
will treat this inner class as
if it had been annotated with @UI.
public GuiEffectTypeFactory(BaseTypeChecker checker, boolean spew)
public ExecutableElement findJavaOverride(ExecutableElement overrider, TypeMirror parentType)
public boolean isPolymorphicType(TypeElement cls)
public boolean isUIType(TypeElement cls)
public Effect getDeclaredEffect(ExecutableElement methodElt)
To make anon-inner-classes work, I need to climb the inheritance DAG, until I:
public Effect getComputedEffectAtCallsite(MethodInvocationTree node, AnnotatedTypeMirror.AnnotatedDeclaredType callerReceiver, ExecutableElement methodElt)
node
- the method invocation as an AST nodecallerReceiver
- the type of the receiver object if available. Used to resolve direct
calls like "super()"methodElt
- the element of the callee methodpublic Effect getInferedEffectForLambdaExpression(LambdaExpressionTree lambdaTree)
This relies on GuiEffectVisitor to perform the actual inference step and mark lambdas
with @PolyUIEffect functional interfaces as being explicitly UI-affecting using the constrainLambdaToUI
method.
lambdaTree
- a lambda expression's AST nodepublic boolean isDirectlyMarkedUIThroughInference(Tree tree)
constrainLambdaToUI
} or constrainAnonymousClassToUI(TypeElement)
. Only explicit markings due to inference are
considered here, for the properly computed type of the expression, use getAnnotatedType(Tree)
instead.tree
- the tree to checkpublic AnnotatedTypeMirror getAnnotatedType(Tree tree)
AnnotatedTypeFactory
tree
.getAnnotatedType
in class AnnotatedTypeFactory
tree
- the AST nodetree
public Effect.EffectRange findInheritedEffectRange(TypeElement declaringType, ExecutableElement overridingMethod)
public Effect.EffectRange findInheritedEffectRange(TypeElement declaringType, ExecutableElement overridingMethod, boolean issueConflictWarning, Tree errorNode)
protected Set<? extends AnnotationMirror> getDefaultTypeDeclarationBounds()
AnnotatedTypeFactory
This implementation returns the top qualifiers by default. Subclass may override to return different qualifiers.
getDefaultTypeDeclarationBounds
in class AnnotatedTypeFactory
protected TreeAnnotator createTreeAnnotator()
GenericAnnotatedTypeFactory
TreeAnnotator
that adds annotations to a type based on the contents of a
tree.
The default tree annotator is a ListTreeAnnotator
of the following:
PropagationTreeAnnotator
: Propagates annotations from subtrees
LiteralTreeAnnotator
: Adds annotations based on QualifierForLiterals
meta-annotations
DependentTypesTreeAnnotator
: Adapts dependent annotations based on context
Subclasses may override this method to specify additional tree annotators, for example:
new ListTreeAnnotator(super.createTreeAnnotator(), new KeyLookupTreeAnnotator(this));
createTreeAnnotator
in class GenericAnnotatedTypeFactory<CFValue,CFStore,CFTransfer,CFAnalysis>
public void constrainLambdaToUI(LambdaExpressionTree lambdaExpressionTree)
Used by GuiEffectVisitor to mark as UIEffect all lambdas that perform UIEffect calls inside their bodies.
lambdaExpressionTree
- a lambda expression's AST nodepublic void constrainAnonymousClassToUI(TypeElement classElt)
Used by GuiEffectVisitor to mark as @UI all anonymous inner classes which: inherit from a PolyUIType annotated superclass, override a PolyUIEffect method from said superclass, and perform UIEffect calls inside the body of this method.
classElt
- the TypeElement corresponding to the anonymous inner class to mark as an @UI
instantiation of an UI-polymorphic superclass.