checkers.javari
Class JavariVisitor

java.lang.Object
  extended by com.sun.source.util.TreeScanner<R,P>
      extended by com.sun.source.util.TreePathScanner<R,P>
          extended by checkers.source.SourceVisitor<R,P>
              extended by checkers.basetype.BaseTypeVisitor<Void,Void>
                  extended by checkers.javari.JavariVisitor
All Implemented Interfaces:
TreeVisitor<Void,Void>

public class JavariVisitor
extends BaseTypeVisitor<Void,Void>

A type-checking visitor for the Javari mutability annotations (@ReadOnly, @Mutable and @Assignable) that extends BaseTypeVisitor.

See Also:
BaseTypeVisitor

Field Summary
 
Fields inherited from class checkers.basetype.BaseTypeVisitor
annoFactory, annoTypes, checker, visitorState
 
Fields inherited from class checkers.source.SourceVisitor
atypeFactory, elements, root, trees, types
 
Constructor Summary
JavariVisitor(JavariChecker checker, CompilationUnitTree root)
          Creates a new visitor for type-checking the Javari mutability annotations.
 
Method Summary
protected  void checkArguments(List<? extends AnnotatedTypeMirror> requiredArgs, List<? extends ExpressionTree> passedArgs, Void p)
          Overriding assignment check to annotate every {code @PolyRead} parameter with {code @ReadOnly}.
protected  boolean checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method, MethodInvocationTree node)
          Overriding invocability check to let {code @ReadOnly} references invoke {code @PolyRead} methods.
protected  void commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, String errorKey, Void p)
          Overrides its super method, calling the assignment check unless the error key is generic.argument.invalid and the upper bound is java.lang.Object .
protected  void commonAssignmentCheck(Tree varTree, ExpressionTree valueTree, String errorKey, Void p)
          Checks whether the local field of a readonly reference is being assigned, before calling commonAssignmentCheck to proceed with subtype checking.
 void validateTypeOf(Tree tree)
          Tests whether the tree expressed by the passed type tree contains a qualified primitive type on its qualified type, and if so emits an error.
 Void visitClass(ClassTree node, Void p)
          Ensures the class type is valid.
 Void visitTypeCast(TypeCastTree node, Void p)
          Emits a warning if a cast is made increasing mutability.
 Void visitUnary(UnaryTree node, Void p)
          Checks for prefix and postfix increments and decrements on unassignable fields of readonly classes.
 
Methods inherited from class checkers.basetype.BaseTypeVisitor
checkAssignability, checkOverride, checkTypeArguments, commonAssignmentCheck, scan, shouldSkip, shouldSkip, visitAnnotation, visitAssignment, visitCompilationUnit, visitCompoundAssignment, visitEnhancedForLoop, visitInstanceOf, visitMethod, visitMethodInvocation, visitNewArray, visitNewClass, visitParameterizedType, visitReturn, visitVariable
 
Methods inherited from class com.sun.source.util.TreePathScanner
getCurrentPath, scan
 
Methods inherited from class com.sun.source.util.TreeScanner
reduce, scan, visitAnnotatedType, visitArrayAccess, visitArrayType, visitAssert, visitBinary, visitBlock, visitBreak, visitCase, visitCatch, visitConditionalExpression, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExpressionStatement, visitForLoop, visitIdentifier, visitIf, visitImport, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitOther, visitParenthesized, visitPrimitiveType, visitSwitch, visitSynchronized, visitThrow, visitTry, visitTypeParameter, visitWhileLoop, visitWildcard
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavariVisitor

public JavariVisitor(JavariChecker checker,
                     CompilationUnitTree root)
Creates a new visitor for type-checking the Javari mutability annotations.

Parameters:
checker - the JavariChecker to use
root - the root of the input program's AST to check
Method Detail

visitClass

public Void visitClass(ClassTree node,
                       Void p)
Ensures the class type is valid.

Specified by:
visitClass in interface TreeVisitor<Void,Void>
Overrides:
visitClass in class BaseTypeVisitor<Void,Void>

commonAssignmentCheck

protected void commonAssignmentCheck(AnnotatedTypeMirror varType,
                                     AnnotatedTypeMirror valueType,
                                     Tree valueTree,
                                     String errorKey,
                                     Void p)
Overrides its super method, calling the assignment check unless the error key is generic.argument.invalid and the upper bound is java.lang.Object .

Overrides:
commonAssignmentCheck in class BaseTypeVisitor<Void,Void>
Parameters:
varType - the annotated type of the variable
valueType - the annotated type of the value
valueTree - the location to use when reporting the error message
errorKey - the error message to use if the check fails
p - a checker-specified parameter

commonAssignmentCheck

protected void commonAssignmentCheck(Tree varTree,
                                     ExpressionTree valueTree,
                                     String errorKey,
                                     Void p)
Checks whether the local field of a readonly reference is being assigned, before calling commonAssignmentCheck to proceed with subtype checking.

Overrides:
commonAssignmentCheck in class BaseTypeVisitor<Void,Void>
Parameters:
varTree - the AST node for the variable
valueTree - the AST node for the value
errorKey - the error message to use if the check fails
p - a checker-specified parameter

visitUnary

public Void visitUnary(UnaryTree node,
                       Void p)
Checks for prefix and postfix increments and decrements on unassignable fields of readonly classes.

Specified by:
visitUnary in interface TreeVisitor<Void,Void>
Overrides:
visitUnary in class BaseTypeVisitor<Void,Void>
See Also:
TreeScanner.visitUnary(com.sun.source.tree.UnaryTree,java.lang.Object)

validateTypeOf

public void validateTypeOf(Tree tree)
Tests whether the tree expressed by the passed type tree contains a qualified primitive type on its qualified type, and if so emits an error.

Overrides:
validateTypeOf in class BaseTypeVisitor<Void,Void>
Parameters:
tree - the AST type supplied by the user

visitTypeCast

public Void visitTypeCast(TypeCastTree node,
                          Void p)
Emits a warning if a cast is made increasing mutability.

Specified by:
visitTypeCast in interface TreeVisitor<Void,Void>
Overrides:
visitTypeCast in class BaseTypeVisitor<Void,Void>
See Also:
TreeScanner.visitTypeCast(com.sun.source.tree.TypeCastTree,java.lang.Object)

checkMethodInvocability

protected boolean checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method,
                                          MethodInvocationTree node)
Overriding invocability check to let {code @ReadOnly} references invoke {code @PolyRead} methods.

Overrides:
checkMethodInvocability in class BaseTypeVisitor<Void,Void>
Parameters:
method - the type of the invoked method
node - the method invocation node
Returns:
true iff the call of 'node' is a valid call

checkArguments

protected void checkArguments(List<? extends AnnotatedTypeMirror> requiredArgs,
                              List<? extends ExpressionTree> passedArgs,
                              Void p)
Overriding assignment check to annotate every {code @PolyRead} parameter with {code @ReadOnly}.

Overrides:
checkArguments in class BaseTypeVisitor<Void,Void>
Parameters:
requiredArgs - the required types
passedArgs - the expressions passed to the corresponding types