Class GuiEffectVisitor
- java.lang.Object
-
- com.sun.source.util.TreeScanner<R,P>
-
- com.sun.source.util.TreePathScanner<R,P>
-
- org.checkerframework.framework.source.SourceVisitor<java.lang.Void,java.lang.Void>
-
- org.checkerframework.common.basetype.BaseTypeVisitor<GuiEffectTypeFactory>
-
- org.checkerframework.checker.guieffect.GuiEffectVisitor
-
- All Implemented Interfaces:
com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
public class GuiEffectVisitor extends BaseTypeVisitor<GuiEffectTypeFactory>
Require that only UI code invokes code with the UI effect.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
GuiEffectVisitor.GuiEffectOverrideChecker
-
Nested classes/interfaces inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
BaseTypeVisitor.FoundRequired, BaseTypeVisitor.OverrideChecker
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayDeque<com.sun.source.tree.MethodTree>
currentMethods
protected boolean
debugSpew
Whether or not to display debugging information.protected java.util.ArrayDeque<Effect>
effStack
-
Fields inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
atypeFactory, checker, DETERMINISTIC, ignoreTargetLocations, IMPURE, methodTree, positions, PURE, qualAllowedLocations, qualHierarchy, showchecks, SIDE_EFFECT_FREE, TARGET, targetValueElement, typeHierarchy, typeValidator, unusedWhenElement
-
Fields inherited from class org.checkerframework.framework.source.SourceVisitor
elements, root, trees, treesWithSuppressWarnings, types
-
-
Constructor Summary
Constructors Constructor Description GuiEffectVisitor(BaseTypeChecker checker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, javax.lang.model.element.ExecutableElement constructorElement)
Issue a warning if the result type of the constructor declaration is not top.protected void
checkExtendsAndImplements(com.sun.source.tree.ClassTree classTree)
In@A class X extends @B Y implements @C Z {}
, enforce that@A
must be a subtype of@B
and@C
.protected void
checkForPolymorphicQualifiers(com.sun.source.tree.ClassTree classTree)
Issues an "invalid.polymorphic.qualifier" error for all polymorphic annotations written on the class declaration.protected void
checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method, com.sun.source.tree.MethodInvocationTree tree)
Tests whether the method can be invoked using the receiver of the 'tree' method invocation, and issues a "method.invocation.invalid" if the invocation is invalid.protected BaseTypeVisitor.OverrideChecker
createOverrideChecker(com.sun.source.tree.Tree overriderTree, AnnotatedTypeMirror.AnnotatedExecutableType overrider, AnnotatedTypeMirror overridingType, AnnotatedTypeMirror overridingReturnType, AnnotatedTypeMirror.AnnotatedExecutableType overridden, AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType, AnnotatedTypeMirror overriddenReturnType)
Create an OverrideChecker.protected GuiEffectTypeFactory
createTypeFactory()
Constructs an instance of the appropriate type factory for the implemented type system.protected AnnotationMirrorSet
getExceptionParameterLowerBoundAnnotations()
Returns a set of AnnotationMirrors that is a lower bound for exception parameters.boolean
isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType, AnnotatedTypeMirror.AnnotatedDeclaredType useType, com.sun.source.tree.Tree tree)
Tests that the qualifiers present onuseType
are valid qualifiers, given the qualifiers on the declaration of the type,declarationType
.void
processClassTree(com.sun.source.tree.ClassTree classTree)
Type-check classTree.java.lang.Void
visitLambdaExpression(com.sun.source.tree.LambdaExpressionTree tree, java.lang.Void p)
java.lang.Void
visitMethod(com.sun.source.tree.MethodTree tree, java.lang.Void p)
Checks that the method obeys override and subtype rules to all overridden methods.java.lang.Void
visitMethodInvocation(com.sun.source.tree.MethodInvocationTree tree, java.lang.Void p)
Performs a method invocation check.java.lang.Void
visitNewClass(com.sun.source.tree.NewClassTree tree, java.lang.Void p)
Performs a new class invocation check.-
Methods inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
checkAccess, checkAccessAllowed, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkConstructorInvocation, checkContract, checkDefaultConstructor, checkEnclosingExpr, checkExceptionParameter, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsOrImplements, checkFieldInvariantDeclarations, checkForPolymorphicQualifiers, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurity, checkQualifierParameter, checkSuperConstructorCall, checkThisConstructorCall, checkThisOrSuperConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, createQualAllowedLocations, createTypeFactoryPublic, createTypeValidator, enclosingMemberSelect, enclosingStatement, getThrowUpperBoundAnnotations, getTypeFactory, isTypeCastSafe, isValidUse, isValidUse, reportCommonAssignmentError, reportMethodInvocabilityError, reportPurityErrors, scan, setRoot, shouldSkipUses, shouldWarnAboutIrrelevantJavaTypes, skipReceiverSubtypeCheck, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateTargetLocation, validateType, validateTypeOf, validateVariablesTargetLocation, visitAnnotatedType, visitAnnotatedType, visitAnnotation, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitMemberReference, visitNewArray, visitReturn, visitSwitchExpression17, visitThrow, visitTypeCast, visitTypeParameter, visitUnary, visitVariable, warnAboutIrrelevantJavaTypes, warnRedundantAnnotations
-
Methods inherited from class org.checkerframework.framework.source.SourceVisitor
visit
-
Methods inherited from class com.sun.source.util.TreeScanner
reduce, scan, visitArrayAccess, visitArrayType, visitAssert, visitBinary, visitBlock, visitBreak, visitCase, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitModule, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitPrimitiveType, visitProvides, visitRequires, visitSwitch, visitSynchronized, visitTry, visitUnionType, visitUses, visitWhileLoop, visitWildcard
-
-
-
-
Field Detail
-
debugSpew
protected final boolean debugSpew
Whether or not to display debugging information.
-
effStack
protected final java.util.ArrayDeque<Effect> effStack
-
currentMethods
protected final java.util.ArrayDeque<com.sun.source.tree.MethodTree> currentMethods
-
-
Constructor Detail
-
GuiEffectVisitor
public GuiEffectVisitor(BaseTypeChecker checker)
-
-
Method Detail
-
createTypeFactory
protected GuiEffectTypeFactory createTypeFactory()
Description copied from class:BaseTypeVisitor
Constructs an instance of the appropriate type factory for the implemented type system.The default implementation uses the checker naming convention to create the appropriate type factory. If no factory is found, it returns
BaseAnnotatedTypeFactory
. It reflectively invokes the constructor that accepts this checker and compilation unit tree (in that order) as arguments.Subclasses have to override this method to create the appropriate visitor if they do not follow the checker naming convention.
- Overrides:
createTypeFactory
in classBaseTypeVisitor<GuiEffectTypeFactory>
- Returns:
- the appropriate type factory
-
checkMethodInvocability
protected void checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method, com.sun.source.tree.MethodInvocationTree tree)
Description copied from class:BaseTypeVisitor
Tests whether the method can be invoked using the receiver of the 'tree' method invocation, and issues a "method.invocation.invalid" if the invocation is invalid.This implementation tests whether the receiver in the method invocation is a subtype of the method receiver type. This behavior can be specialized by overriding skipReceiverSubtypeCheck.
- Overrides:
checkMethodInvocability
in classBaseTypeVisitor<GuiEffectTypeFactory>
- Parameters:
method
- the type of the invoked methodtree
- the method invocation tree
-
createOverrideChecker
protected BaseTypeVisitor.OverrideChecker createOverrideChecker(com.sun.source.tree.Tree overriderTree, AnnotatedTypeMirror.AnnotatedExecutableType overrider, AnnotatedTypeMirror overridingType, AnnotatedTypeMirror overridingReturnType, AnnotatedTypeMirror.AnnotatedExecutableType overridden, AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType, AnnotatedTypeMirror overriddenReturnType)
Description copied from class:BaseTypeVisitor
Create an OverrideChecker.This exists so that subclasses can subclass OverrideChecker and use their subclass instead of using OverrideChecker itself.
- Overrides:
createOverrideChecker
in classBaseTypeVisitor<GuiEffectTypeFactory>
- Parameters:
overriderTree
- the AST node of the overriding method or method referenceoverrider
- the type of the overriding methodoverridingType
- the type enclosing the overrider method, usually an AnnotatedDeclaredType; for Method References may be something elseoverridingReturnType
- the return type of the overriding methodoverridden
- the type of the overridden methodoverriddenType
- the declared type enclosing the overridden methodoverriddenReturnType
- the return type of the overridden method- Returns:
- an OverrideChecker
-
getExceptionParameterLowerBoundAnnotations
protected AnnotationMirrorSet getExceptionParameterLowerBoundAnnotations()
Description copied from class:BaseTypeVisitor
Returns a set of AnnotationMirrors that is a lower bound for exception parameters.This implementation returns top; subclasses can change this behavior.
Note: by default this method is called by
BaseTypeVisitor.getThrowUpperBoundAnnotations()
, so that this annotation is enforced.- Overrides:
getExceptionParameterLowerBoundAnnotations
in classBaseTypeVisitor<GuiEffectTypeFactory>
- Returns:
- set of annotation mirrors, one per hierarchy, that form a lower bound of annotations that can be written on an exception parameter
-
isValidUse
public boolean isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType, AnnotatedTypeMirror.AnnotatedDeclaredType useType, com.sun.source.tree.Tree tree)
Description copied from class:BaseTypeVisitor
Tests that the qualifiers present onuseType
are valid qualifiers, given the qualifiers on the declaration of the type,declarationType
.The check is shallow, as it does not descend into generic or array types (i.e. only performing the validity check on the raw type or outermost array dimension).
BaseTypeVisitor.validateTypeOf(Tree)
would call this for each type argument or array dimension separately.In most cases,
useType
simply needs to be a subtype ofdeclarationType
. If a type system makes exceptions to this rule, its implementation should override this method.This method is not called if
BaseTypeValidator.shouldCheckTopLevelDeclaredOrPrimitiveType(AnnotatedTypeMirror, Tree)
returns false -- by default, it is not called on the top level for locals and expressions. To enforce a type validity property everywhere, override methods such asBaseTypeValidator.visitDeclared(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType, com.sun.source.tree.Tree)
rather than this method.- Overrides:
isValidUse
in classBaseTypeVisitor<GuiEffectTypeFactory>
- Parameters:
declarationType
- the type of the class (TypeElement)useType
- the use of the class (instance type)tree
- the tree where the type is used- Returns:
- true if the useType is a valid use of elemType
-
visitLambdaExpression
public java.lang.Void visitLambdaExpression(com.sun.source.tree.LambdaExpressionTree tree, java.lang.Void p)
- Specified by:
visitLambdaExpression
in interfacecom.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
- Overrides:
visitLambdaExpression
in classBaseTypeVisitor<GuiEffectTypeFactory>
-
checkExtendsAndImplements
protected void checkExtendsAndImplements(com.sun.source.tree.ClassTree classTree)
Description copied from class:BaseTypeVisitor
In@A class X extends @B Y implements @C Z {}
, enforce that@A
must be a subtype of@B
and@C
.Also validate the types of the extends and implements clauses.
- Overrides:
checkExtendsAndImplements
in classBaseTypeVisitor<GuiEffectTypeFactory>
- Parameters:
classTree
- class tree to check
-
checkConstructorResult
protected void checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, javax.lang.model.element.ExecutableElement constructorElement)
Description copied from class:BaseTypeVisitor
Issue a warning if the result type of the constructor declaration is not top. If it is a supertype of the class, then a type.invalid.conflicting.annos error will also be issued byBaseTypeVisitor.isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType,AnnotatedTypeMirror.AnnotatedDeclaredType,Tree)
.- Overrides:
checkConstructorResult
in classBaseTypeVisitor<GuiEffectTypeFactory>
- Parameters:
constructorType
- the AnnotatedExecutableType for the constructorconstructorElement
- the element that declares the constructor
-
checkForPolymorphicQualifiers
protected void checkForPolymorphicQualifiers(com.sun.source.tree.ClassTree classTree)
Description copied from class:BaseTypeVisitor
Issues an "invalid.polymorphic.qualifier" error for all polymorphic annotations written on the class declaration.- Overrides:
checkForPolymorphicQualifiers
in classBaseTypeVisitor<GuiEffectTypeFactory>
- Parameters:
classTree
- the class to check
-
visitMethodInvocation
public java.lang.Void visitMethodInvocation(com.sun.source.tree.MethodInvocationTree tree, java.lang.Void p)
Description copied from class:BaseTypeVisitor
Performs a method invocation check.An invocation of a method, m, on the receiver, r is valid only if:
- passed arguments are subtypes of corresponding m parameters
- r is a subtype of m receiver type
- if m is generic, passed type arguments are subtypes of m type variables
- Specified by:
visitMethodInvocation
in interfacecom.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
- Overrides:
visitMethodInvocation
in classBaseTypeVisitor<GuiEffectTypeFactory>
-
visitMethod
public java.lang.Void visitMethod(com.sun.source.tree.MethodTree tree, java.lang.Void p)
Description copied from class:BaseTypeVisitor
Checks that the method obeys override and subtype rules to all overridden methods. (Uses the pseudo-assignment logic to do so.)The override rule specifies that a method, m1, may override a method m2 only if:
- m1 return type is a subtype of m2
- m1 receiver type is a supertype of m2
- m1 parameters are supertypes of corresponding m2 parameters
- Specified by:
visitMethod
in interfacecom.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
- Overrides:
visitMethod
in classBaseTypeVisitor<GuiEffectTypeFactory>
-
visitNewClass
public java.lang.Void visitNewClass(com.sun.source.tree.NewClassTree tree, java.lang.Void p)
Description copied from class:BaseTypeVisitor
Performs a new class invocation check.An invocation of a constructor, c, is valid only if:
- passed arguments are subtypes of corresponding c parameters
- if c is generic, passed type arguments are subtypes of c type variables
- Specified by:
visitNewClass
in interfacecom.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
- Overrides:
visitNewClass
in classBaseTypeVisitor<GuiEffectTypeFactory>
-
processClassTree
public void processClassTree(com.sun.source.tree.ClassTree classTree)
Description copied from class:BaseTypeVisitor
Type-check classTree. Subclasses should override this method instead ofBaseTypeVisitor.visitClass(ClassTree, Void)
.- Overrides:
processClassTree
in classBaseTypeVisitor<GuiEffectTypeFactory>
- Parameters:
classTree
- class to check
-
-