public class BaseTypeValidator extends AnnotatedTypeScanner<Void,Tree> implements TypeValidator
Modifier and Type | Field and Description |
---|---|
protected AnnotatedTypeFactory |
atypeFactory
AnnotatedTypeFactory.
|
protected BaseTypeChecker |
checker
BaseTypeChecker.
|
protected boolean |
checkTopLevelDeclaredType
Should the primary annotation on the top level type be checked?
|
protected boolean |
isValid
Is the type valid?
|
protected BaseTypeVisitor<?> |
visitor
BaseTypeVisitor.
|
visitedNodes
Constructor and Description |
---|
BaseTypeValidator(BaseTypeChecker checker,
BaseTypeVisitor<?> visitor,
AnnotatedTypeFactory atypeFactory) |
reduce, reset, scan, scan, scanAndReduce, scanAndReduce, visit, visit, visitExecutable, visitIntersection, visitNoType, visitNull, visitUnion
protected boolean isValid
protected boolean checkTopLevelDeclaredType
protected final BaseTypeChecker checker
protected final BaseTypeVisitor<?> visitor
protected final AnnotatedTypeFactory atypeFactory
public BaseTypeValidator(BaseTypeChecker checker, BaseTypeVisitor<?> visitor, AnnotatedTypeFactory atypeFactory)
public boolean isValid(AnnotatedTypeMirror type, Tree tree)
BaseTypeVisitor.validateTypeOf(Tree)
.isValid
in interface TypeValidator
type
- the type to validatetree
- the tree from which the type originated. If the tree is a method tree, validate
its return type. If the tree is a variable tree, validate its field type.protected boolean shouldCheckTopLevelDeclaredType(AnnotatedTypeMirror type, Tree tree)
Top-level type is not checked if tree is a local variable or an expression tree.
type
- AnnotatedTypeMirror being validatedtree
- a Tree whose type is type
protected List<DiagMessage> isValidType(QualifierHierarchy qualifierHierarchy, AnnotatedTypeMirror type)
AnnotatedTypeMirror
. Returns a list
of failures. If successful, returns an empty list. The method will never return failures for
a valid type, but might not catch all invalid types.
Currently, the following is checked:
qualifierHierarchy
- the qualifier hierachytype
- the type to testprotected List<DiagMessage> isTopLevelValidType(QualifierHierarchy qualifierHierarchy, AnnotatedTypeMirror type)
isValidType(org.checkerframework.framework.type.QualifierHierarchy, org.checkerframework.framework.type.AnnotatedTypeMirror)
, but only for the top level type. If
successful, returns an empty list. If not successful, returns diagnostics.qualifierHierarchy
- the qualifier hierarchytype
- the type to be checkedprotected void reportValidityResult(@CompilerMessageKey String errorType, AnnotatedTypeMirror type, Tree p)
protected void reportValidityResultOnUnannotatedType(@CompilerMessageKey String errorType, AnnotatedTypeMirror type, Tree p)
reportValidityResult(java.lang.String, org.checkerframework.framework.type.AnnotatedTypeMirror, com.sun.source.tree.Tree)
, but the type is printed in the error message without
annotations. This method would print "annotation @NonNull is not permitted on type int",
whereas reportValidityResult(java.lang.String, org.checkerframework.framework.type.AnnotatedTypeMirror, com.sun.source.tree.Tree)
would print "annotation @NonNull is not permitted on
type @NonNull int". In addition, when the underlying type is a compound type such as
@Bad List<String>
, the erased type will be used, i.e., "List
" will print
instead of "@Bad List<String>
".protected void reportInvalidBounds(AnnotatedTypeMirror type, Tree tree)
protected void reportInvalidType(AnnotatedTypeMirror type, Tree p)
protected void reportInvalidAnnotationsOnUse(AnnotatedTypeMirror type, Tree p)
public Void visitDeclared(AnnotatedTypeMirror.AnnotatedDeclaredType type, Tree tree)
AnnotatedTypeVisitor
visitDeclared
in interface AnnotatedTypeVisitor<Void,Tree>
visitDeclared
in class AnnotatedTypeScanner<Void,Tree>
type
- the type to visittree
- a visitor-specified parameterpublic Void visitPrimitive(AnnotatedTypeMirror.AnnotatedPrimitiveType type, Tree tree)
AnnotatedTypeVisitor
visitPrimitive
in interface AnnotatedTypeVisitor<Void,Tree>
visitPrimitive
in class AnnotatedTypeScanner<Void,Tree>
type
- the type to visittree
- a visitor-specified parameterpublic Void visitArray(AnnotatedTypeMirror.AnnotatedArrayType type, Tree tree)
AnnotatedTypeVisitor
visitArray
in interface AnnotatedTypeVisitor<Void,Tree>
visitArray
in class AnnotatedTypeScanner<Void,Tree>
type
- the type to visittree
- a visitor-specified parameterprotected Void visitParameterizedType(AnnotatedTypeMirror.AnnotatedDeclaredType type, ParameterizedTypeTree tree)
type
- the type to checktree
- the type's treepublic Void visitTypeVariable(AnnotatedTypeMirror.AnnotatedTypeVariable type, Tree tree)
AnnotatedTypeVisitor
visitTypeVariable
in interface AnnotatedTypeVisitor<Void,Tree>
visitTypeVariable
in class AnnotatedTypeScanner<Void,Tree>
type
- the type to visittree
- a visitor-specified parameterpublic Void visitWildcard(AnnotatedTypeMirror.AnnotatedWildcardType type, Tree tree)
AnnotatedTypeVisitor
visitWildcard
in interface AnnotatedTypeVisitor<Void,Tree>
visitWildcard
in class AnnotatedTypeScanner<Void,Tree>
type
- the type to visittree
- a visitor-specified parameterpublic boolean areBoundsValid(AnnotatedTypeMirror upperBound, AnnotatedTypeMirror lowerBound)