Class GuiEffectTypeFactory
- All Implemented Interfaces:
AnnotationProvider
-
Nested Class Summary
Nested classes/interfaces inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
GenericAnnotatedTypeFactory.ScanState
Nested classes/interfaces inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
AnnotatedTypeFactory.CapturedTypeVarSubstitutor, AnnotatedTypeFactory.ParameterizedExecutableType
-
Field Summary
Modifier and TypeFieldDescriptionprotected final AnnotationMirror
The @AlwaysSafe
annotation.protected final boolean
protected final AnnotationMirror
The @PolyUI
annotation.protected final AnnotationMirror
The @UI
annotation.protected final Set<TypeElement>
Keeps track of all anonymous inner classes with inferred UIEffect.protected final Set<LambdaExpressionTree>
Keeps track of all lambda expressions with inferred UIEffect.Fields inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
analysis, arraysAreRelevant, cfgVisualizer, contractsUtils, defaults, dependentTypesHelper, emptyStore, exceptionalExitStores, flowByDefault, flowResult, flowResultAnalysisCaches, formalParameterPattern, hasOrIsSubchecker, initializationStaticStore, initializationStore, methodInvocationStores, poly, regularExitStores, relevantJavaTypes, returnStatementStores, scannedClasses, shouldClearSubcheckerSharedCFGs, sideEffectsUnrefineAliases, subcheckerSharedCFG, transfer, treeAnnotator, typeAnnotator
Fields inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
ajavaTypes, annotatedForValueElement, artificialTreeToEnclosingElementMap, capturedTypeVarSubstitutor, checker, currentFileAjavaTypes, elements, ensuresQualifierExpressionElement, ensuresQualifierIfExpressionElement, ensuresQualifierIfListTM, ensuresQualifierIfListValueElement, ensuresQualifierIfResultElement, ensuresQualifierIfTM, ensuresQualifierListTM, ensuresQualifierListValueElement, ensuresQualifierTM, fieldInvariantFieldElement, fieldInvariantQualifierElement, fromExpressionTreeCache, fromMemberTreeCache, fromTypeTreeCache, hasQualifierParameterValueElement, ignoreRawTypeArguments, loader, methodValClassNameElement, methodValMethodNameElement, methodValParamsElement, noQualifierParameterValueElement, objectGetClass, processingEnv, qualHierarchy, qualifierUpperBounds, reflectionResolver, requiresQualifierExpressionElement, requiresQualifierListTM, requiresQualifierListValueElement, requiresQualifierTM, root, shouldCache, stubTypes, trees, typeArgumentInference, typeFormatter, typeHierarchy, types, typeVarSubstitutor, uid, wpiOutputFormat
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Returns aTreeAnnotator
that adds annotations to a type based on the contents of a tree.findInheritedEffectRange
(TypeElement declaringType, ExecutableElement overridingMethod) findInheritedEffectRange
(TypeElement declaringType, ExecutableElement overridingMethod, boolean issueConflictWarning, Tree errorTree) Find the greatest and least effects of methods the specified definition overrides.getAnnotatedType
(Tree tree) Returns an AnnotatedTypeMirror representing the annotated type oftree
.getComputedEffectAtCallsite
(MethodInvocationTree tree, AnnotatedTypeMirror.AnnotatedDeclaredType callerReceiver, ExecutableElement methodElt) Get the effect of a method call at its callsite, acknowledging polymorphic instantiation using type use annotations.getDeclaredEffect
(ExecutableElement methodElt) Calling context annotations.protected AnnotationMirrorSet
Returns the set of qualifiers that are the upper bound for a type use if no other bound is specified for the type.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
Test if this tree corresponds to a lambda expression or new class marked as UI affecting by eitherconstrainLambdaToUI
} orconstrainAnonymousClassToUI(TypeElement)
.boolean
Returns true if the given type is polymorphic.boolean
isUIType
(TypeElement cls) Methods inherited from class org.checkerframework.common.basetype.BaseAnnotatedTypeFactory
createFlowAnalysis
Methods inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
addAnnotationsFromDefaultForType, addCheckedCodeDefaults, addCheckedStandardDefaults, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotationsForWarnRedundant, addDefaultAnnotations, addSharedCFGForTree, addUncheckedStandardDefaults, analyze, annotationsForIrrelevantJavaType, applyInferredAnnotations, applyQualifierParameterDefaults, applyQualifierParameterDefaults, checkAndPerformFlowAnalysis, checkForDefaultQualifierInHierarchy, constructorFromUse, constructorFromUsePreSubstitution, createAndInitQualifierDefaults, createCFGVisualizer, createContractsFromMethod, createDefaultForTypeAnnotator, createDefaultForUseTypeAnnotator, createDependentTypesHelper, createFlowTransferFunction, createQualifierDefaults, createQualifierPolymorphism, createRequiresOrEnsuresQualifier, createTypeAnnotator, getAnnotatedTypeLhs, getAnnotatedTypeLhsNoTypeVarDefault, getAnnotatedTypeRhsUnaryAssign, getAnnotatedTypeVarargsArray, getAnnotationFromJavaExpression, getAnnotationFromJavaExpressionString, getAnnotationMirrorFromJavaExpressionString, getAnnotationsFromJavaExpression, getCFGVisualizer, getContractAnnotations, getContractAnnotations, getContractExpressions, getContractsFromMethod, getDefaultAnnotations, getDefaultAnnotationsForWarnRedundant, getDefaultForTypeAnnotator, getDefaultValueAnnotatedType, getDependentTypesHelper, getEmptyStore, getEnsuresQualifierIfResult, getExceptionalExitStore, getExplicitNewClassAnnos, getExplicitNewClassClassTypeArgs, getExpressionAndOffsetFromJavaExpressionString, getFinalLocalValues, getFirstNodeOfKindForTree, getInferredValueFor, getMethodReturnType, getNodesForTree, getPostconditionAnnotations, getPostconditionAnnotations, getPostconditionAnnotations, getPreconditionAnnotations, getPreconditionAnnotations, getPreconditionAnnotations, getPreOrPostconditionAnnotations, getQualifierPolymorphism, getRegularExitStore, getReturnStatementStores, getSharedCFGForTree, getShouldDefaultTypeVarLocals, getSortedQualifierNames, getStoreAfter, getStoreAfter, getStoreAfter, getStoreBefore, getStoreBefore, getStoreBefore, getSupportedMonotonicTypeQualifiers, getTypeFactoryOfSubchecker, getTypeFactoryOfSubcheckerOrNull, handleCFGViz, irrelevantExtraMessage, isIgnoredExceptionType, isRelevant, isRelevant, isRelevantImpl, isUnreachable, methodFromUse, methodFromUsePreSubstitution, parseJavaExpressionString, performFlowAnalysis, postAnalyze, postAsMemberOf, postDirectSuperTypes, postInit, preProcessClassTree, setRoot, typeVariablesFromUse
Methods inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
adaptGetClassReturnTypeToReceiver, addAliasedDeclAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, applyCaptureConversion, applyCaptureConversion, applyUnboxing, areSameByClass, binaryTreeArgTypes, binaryTreeArgTypes, canonicalAnnotation, checkInvalidOptionsInferSignatures, compoundAssignmentTreeArgTypes, constructorFromUse, constructorFromUseWithoutTypeArgInference, containsCapturedTypes, containsSameByClass, createAnnotatedTypeFormatter, createAnnotationClassLoader, createAnnotationFormatter, createQualifierHierarchy, createQualifierUpperBounds, createSupportedTypeQualifiers, createTypeArgumentInference, createTypeHierarchy, createTypeVariableSubstitutor, declarationFromElement, doesAnnotatedForApplyToThisChecker, fromElement, fromElement, fromElement, getAnnotatedNullType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFormatter, getAnnotatedTypeFromTypeTree, getAnnotationByClass, getAnnotationFormatter, getAnnotationMirror, getAnnotationWithMetaAnnotation, getBoxedType, getBundledTypeQualifiers, getCacheSize, getChecker, getCheckerNames, getContractExpressions, getContractListValues, getDeclAnnotation, getDeclAnnotationNoAliases, getDeclAnnotations, getDeclAnnotationWithMetaAnnotation, getDummyAssignedTo, getElementUtils, getEnclosingClassOrMethod, getEnclosingElementForArtificialTree, getEnclosingSubType, getEnclosingType, getEnumConstructorQualifiers, getExpressionAndOffset, getFieldInvariantAnnotationTree, getFieldInvariantDeclarationAnnotations, getFieldInvariants, getFnInterfaceFromTree, getFunctionTypeFromTree, getFunctionTypeFromTree, getImplicitReceiverType, getIterableElementType, getIterableElementType, getMethodReturnType, getNarrowedAnnotations, getNarrowedPrimitive, getPath, getProcessingEnv, getQualifierHierarchy, getQualifierParameterHierarchies, getQualifierParameterHierarchies, getQualifierUpperBounds, getReceiverType, getResultingTypeOfConstructorMemberReference, getSelfType, getStringType, getSupportedTypeQualifierNames, getSupportedTypeQualifiers, getTreeUtils, getTypeArgumentInference, getTypeDeclarationBounds, getTypeHierarchy, getTypeOfExtendsImplements, getTypeVarSubstitutor, getUnboxedType, getVisitorTreePath, getWholeProgramInference, getWidenedAnnotations, getWidenedType, getWidenedType, hasExplicitNoQualifierParameterInHierarchy, hasExplicitQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, initializeAtm, initializeReflectionResolution, isDeterministic, isFromByteCode, isFromStubFile, isImmutable, isSideEffectFree, isSupportedQualifier, isSupportedQualifier, isSupportedQualifier, isTop, isWithinConstructor, logGat, makeConditionConsistentWithOtherMethod, mergeAnnotationFileAnnosIntoType, methodFromUse, methodFromUse, methodFromUse, methodFromUseWithoutTypeArgInference, methodFromUseWithoutTypeArgInference, negateConstant, order, parseAnnotationFiles, postProcessClassTree, replaceAnnotations, replaceAnnotations, setEnclosingElementForArtificialTree, setVisitorTreePath, shouldWarnIfStubRedundantWithBytecode, toAnnotatedType, toString, type, wpiAdjustForUpdateField, wpiAdjustForUpdateNonField, wpiPrepareMethodForWriting, wpiPrepareMethodForWriting, wpiShouldInferTypesForReceivers
-
Field Details
-
debugSpew
protected final boolean debugSpew -
uiLambdas
Keeps track of all lambda expressions with inferred UIEffect.constrainLambdaToUI
adds lambda expressions to this set, and is called from GuiEffectVisitor whenever a lambda expression calls a @UIEffect method. AfterwardsgetInferedEffectForLambdaExpression
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. -
uiAnonClasses
Keeps track of all anonymous inner classes with inferred UIEffect.constrainAnonymousClassToUI
adds anonymous inner classes to this set, and is called from GuiEffectVisitor whenever an anonymous inner class calls a @UIEffect method. AfterwardsisUIType
andgetAnnotatedType
will treat this inner class as if it had been annotated with @UI. -
ALWAYSSAFE
The @AlwaysSafe
annotation. -
POLYUI
The @PolyUI
annotation. -
UI
The @UI
annotation.
-
-
Constructor Details
-
GuiEffectTypeFactory
-
-
Method Details
-
isPolymorphicType
Returns true if the given type is polymorphic.- Parameters:
cls
- the type to test- Returns:
- true if the given type is polymorphic
-
isUIType
-
getDeclaredEffect
Calling context annotations.To make anon-inner-classes work, I need to climb the inheritance DAG, until I:
- find the class/interface that declares this calling method (an anon inner class is a separate class that implements an interface)
- check whether *that* declaration specifies @UI on either the type or method
- A method is UI if annotated @UIEffect
- A method is UI if the enclosing class is annotated @UI or @UIType and the method is not annotated @AlwaysSafe
- A method is UI if the corresponding method in the super-class/interface is UI, and this
method is not annotated @AlwaysSafe, and this method resides in an anonymous inner class
(named classes still require a package/class/method annotation to make it UI, only anon
inner classes have this inheritance-by-default)
- A method must be *annotated* UI if the method it overrides is *annotated* UI
- A method must be *annotated* UI if it overrides a UI method and the enclosing class is not UI
- It is an error if a method is UI but the same method in a super-type is not UI
- It is an error if two super-types specify the same method, where one type says it's UI and one says it's not (it's possible to simply enforce the weaker (safe) effect, but this seems more principled, it's easier --- backwards-compatible --- to change our minds about this later)
-
getComputedEffectAtCallsite
public Effect getComputedEffectAtCallsite(MethodInvocationTree tree, AnnotatedTypeMirror.AnnotatedDeclaredType callerReceiver, ExecutableElement methodElt) Get the effect of a method call at its callsite, acknowledging polymorphic instantiation using type use annotations.- Parameters:
tree
- 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 method- Returns:
- the computed effect (SafeEffect or UIEffect) for the method call
-
getInferedEffectForLambdaExpression
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.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.- Parameters:
lambdaTree
- a lambda expression's AST node- Returns:
- the inferred effect of the lambda
-
isDirectlyMarkedUIThroughInference
Test if this tree corresponds to a lambda expression or new class marked as UI affecting by eitherconstrainLambdaToUI
} orconstrainAnonymousClassToUI(TypeElement)
. Only explicit markings due to inference are considered here, for the properly computed type of the expression, usegetAnnotatedType(Tree)
instead.- Parameters:
tree
- the tree to check- Returns:
- whether it is a lambda expression or new class marked as UI by inference
-
getAnnotatedType
Description copied from class:AnnotatedTypeFactory
Returns an AnnotatedTypeMirror representing the annotated type oftree
.- Overrides:
getAnnotatedType
in classAnnotatedTypeFactory
- Parameters:
tree
- the AST node- Returns:
- the annotated type of
tree
-
findInheritedEffectRange
public Effect.EffectRange findInheritedEffectRange(TypeElement declaringType, ExecutableElement overridingMethod) -
findInheritedEffectRange
public @Nullable Effect.EffectRange findInheritedEffectRange(TypeElement declaringType, ExecutableElement overridingMethod, boolean issueConflictWarning, Tree errorTree) Find the greatest and least effects of methods the specified definition overrides. This method is used for two reasons:1.
GuiEffectVisitor.visitMethod
calls this to perform an effect override check (that a method's effect is less than or equal to the effect of any method it overrides). This use passestrue
for theissueConflictWarning
in order to trigger warning messages.2.
getDeclaredEffect
in this class uses this to infer the default effect of methods in anonymous inner classes. This use passesfalse
forissueConflictWarning
, because it only needs the return value.- Parameters:
declaringType
- the type declaring the overrideoverridingMethod
- the method override itselfissueConflictWarning
- whether or not to issue warningserrorTree
- the method declaration AST node; used for reporting errors- Returns:
- the min and max inherited effects, or null if none were discovered
-
getDefaultTypeDeclarationBounds
Description copied from class:AnnotatedTypeFactory
Returns the set of qualifiers that are the upper bound for a type use if no other bound is specified for the type.This implementation returns the top qualifiers by default. Subclass may override to return different qualifiers.
- Overrides:
getDefaultTypeDeclarationBounds
in classAnnotatedTypeFactory
- Returns:
- the set of qualifiers that are the upper bound for a type use if no other bound is specified for the type
-
createTreeAnnotator
Description copied from class:GenericAnnotatedTypeFactory
Returns aTreeAnnotator
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 subtreesLiteralTreeAnnotator
: Adds annotations based onQualifierForLiterals
meta-annotationsDependentTypesTreeAnnotator
: 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));
- Overrides:
createTreeAnnotator
in classGenericAnnotatedTypeFactory<CFValue,
CFStore, CFTransfer, CFAnalysis> - Returns:
- a tree annotator
-
constrainLambdaToUI
Force the given lambda expression to have UIEffect.Used by GuiEffectVisitor to mark as UIEffect all lambdas that perform UIEffect calls inside their bodies.
- Parameters:
lambdaExpressionTree
- a lambda expression's AST node
-
constrainAnonymousClassToUI
Force the given anonymous inner class to be an @UI instantiation of its base class.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.
- Parameters:
classElt
- the TypeElement corresponding to the anonymous inner class to mark as an @UI instantiation of an UI-polymorphic superclass.
-