|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.annotation.processing.AbstractProcessor com.sun.source.util.AbstractTypeProcessor checkers.source.SourceChecker checkers.basetype.BaseTypeChecker
public abstract class BaseTypeChecker extends SourceChecker
An abstract SourceChecker
that provides a simple SourceVisitor
implementation for typical assignment and
pseudo-assignment checking of annotated types. Pseudo-assignment checks
include method overriding checks, parameter passing, and method invocation.
Most type-checker plug-ins will want to extend this class, instead of
SourceChecker
. Checkers which require annotated types but not
subtype checking (e.g. for testing purposes)
should extend SourceChecker
.
Non-type checkers (e.g. checkers to enforce coding
styles) should extend SourceChecker
or AbstractProcessor
directly; the Checker Framework is not designed for such checkers.
It is a convention that, for a type system Foo, the checker, the visitor, and the annotated type factory are named as FooChecker, FooVisitor, and FooAnnotatedTypeFactory. Some factory methods uses this convention to construct the appriopriate classes reflectively.
BaseTypeChecker
encapsulates a group for factories for various
representations/classes related the type system, mainly:
QualifierHierarchy
:
to represent the supported qualifiers in addition to their hierarchy,
mainly, subtyping rulesTypeHierarchy
:
to check subtyping rules between annotated types rather than qualifiersAnnotatedTypeFactory
:
to construct qualified types enriched with implicit qualifiers
according to the type system rulesBaseTypeVisitor
:
to visit the compiled Java files and check for violations of the type
system rules
Subclasses must specify the set of type qualifiers they support either by
annotating the subclass with TypeQualifiers
or by overriding the
getSupportedTypeQualifiers()
method.
If the specified type qualifiers are meta-annotated with SubtypeOf
,
this implementation will automatically construct the type qualifier
hierarchy. Otherwise, or if this behavior must be overridden, the subclass
may override the createQualifierHierarchy()
method.
checkers.quals
Modifier and Type | Field and Description |
---|
Fields inherited from class checkers.source.SourceChecker |
---|
currentPath, currentRoot, env, messager, messages, trees |
Fields inherited from class javax.annotation.processing.AbstractProcessor |
---|
processingEnv |
Constructor and Description |
---|
BaseTypeChecker()
|
Modifier and Type | Method and Description |
---|---|
AnnotatedTypeFactory |
createFactory(CompilationUnitTree root)
Constructs an instance of the appropriate type factory for the implemented type system. |
protected QualifierHierarchy |
createQualifierHierarchy()
Returns the type qualifier hierarchy graph to be used by this processor. |
protected BaseTypeVisitor<?,?> |
createSourceVisitor(CompilationUnitTree root)
Returns the appropriate visitor that type checks the compilation unit according to the type system rules. |
protected Set<Class<? extends Annotation>> |
createSupportedTypeQualifiers()
If the checker class is annotated with TypeQualifiers , return an immutable set with the same set
of classes as the annotation. |
protected TypeHierarchy |
createTypeHierarchy()
Creates the type subtyping checker using the current type qualifier hierarchy. |
QualifierHierarchy |
getQualifierHierarchy()
Returns the type qualifier hierarchy graph to be used by this processor. |
Set<String> |
getSupportedLintOptions()
Specify 'flow' and 'cast' as supported lint options for all Type checkers |
Set<Class<? extends Annotation>> |
getSupportedTypeQualifiers()
Returns an immutable set of the type qualifiers supported by this checker. |
void |
init(ProcessingEnvironment processingEnv)
|
boolean |
isAssignable(AnnotatedTypeMirror varType,
AnnotatedTypeMirror receiverType,
Tree variable)
Tests whether the variable accessed is an assignable variable or not, given the current scope |
boolean |
isSubtype(AnnotatedTypeMirror sub,
AnnotatedTypeMirror sup)
Tests whether one annotated type is a subtype of another, with respect to the annotations on these types. |
boolean |
isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType,
AnnotatedTypeMirror.AnnotatedDeclaredType useType)
Tests that the qualifiers present on the useType are valid qualifiers, given the qualifiers on the declaration of the type, declarationType. |
Methods inherited from class checkers.source.SourceChecker |
---|
fullMessageOf, getLintOption, getLintOption, getMessages, getProcessingEnvironment, getShouldSkip, getSupportedAnnotationTypes, getSupportedOptions, getSupportedSourceVersion, getSuppressWarningsKey, message, report, typeProcess |
Methods inherited from class com.sun.source.util.AbstractTypeProcessor |
---|
process, typeProcessingOver |
Methods inherited from class javax.annotation.processing.AbstractProcessor |
---|
getCompletions, isInitialized, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public BaseTypeChecker()
Method Detail |
---|
public void init(ProcessingEnvironment processingEnv)
SourceChecker
init
in interface Processor
init
in class SourceChecker
AbstractProcessor.init(ProcessingEnvironment)
protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers()
TypeQualifiers
, return an immutable set with the same set
of classes as the annotation. If the class is not so annotated,
return an empty set.
Subclasses may override this method to return an immutable set
of their supported type qualifiers.
TypeQualifiers
public final Set<Class<? extends Annotation>> getSupportedTypeQualifiers()
createSupportedTypeQualifiers()
protected QualifierHierarchy createQualifierHierarchy()
getSupportedTypeQualifiers()
using the
meta-annotations found in them. The current implementation returns an
instance of GraphQualifierHierarchy
.
Subclasses may override this method to express any relationships that
cannot be inferred using meta-annotations (e.g. due to lack of
meta-annotations).
public final QualifierHierarchy getQualifierHierarchy()
QualifierHierarchy
for this checkercreateQualifierHierarchy()
protected TypeHierarchy createTypeHierarchy()
protected BaseTypeVisitor<?,?> createSourceVisitor(CompilationUnitTree root)
BaseTypeVisitor
. It reflectively invokes the constructor that
accepts this checker and the 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.
createSourceVisitor
in class SourceChecker
root
- the compilation unit currently being visitedpublic AnnotatedTypeFactory createFactory(CompilationUnitTree root)
BasicAnnotatedTypeFactory
. 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.
createFactory
in class SourceChecker
root
- the currently visited compilation unitpublic boolean isSubtype(AnnotatedTypeMirror sub, AnnotatedTypeMirror sup)
TypeHierarchy
. Its behavior is undefined for any annotations
not specified by either TypeQualifiers
or the result of
getSupportedTypeQualifiers()
.
sub
- the child typesup
- the parent typesub
is a subtype of sup
public boolean isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType, AnnotatedTypeMirror.AnnotatedDeclaredType useType)
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
outmost array dimension). BaseTypeVisitor.validateTypeOf(Tree)
would call this for each type argument or array dimention separately.
For instance, in the IGJ type system, a @Mutable
is an invalid
qualifier for String
, as String
is declared as
@Immutable String
.
In most cases, useType
simply needs to be a subtype of
declarationType
, but there are exceptions. In IGJ, a variable may be
declared @ReadOnly String
, even though String
is
@Immutable String
; ReadOnly
is not a subtype of
Immutable
.
declarationType
- the type of the class (TypeElement)useType
- the use of the class (instance type)public boolean isAssignable(AnnotatedTypeMirror varType, AnnotatedTypeMirror receiverType, Tree variable)
varType
- the annotated variable typevariable
- tree used to access the variablepublic Set<String> getSupportedLintOptions()
getSupportedLintOptions
in class SourceChecker
Set
of the lint options recognized by
this checker
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |