|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.annotation.processing.AbstractProcessor
checkers.source.SourceChecker
@Default(value="checkers.nonnull.quals.NonNull") public abstract class SourceChecker
An abstract annotation processor designed for implementing a
source-file checker for a JSR-308 conforming compiler plug-in. It provides an
interface to javac's annotation processing API, routines for error
reporting via the JSR 199 compiler API, and an implementation for using a
SourceVisitor to perform the type-checking.
Subclasses must implement the following methods:
getMessages() (for type-qualifier specific error messages)
SourceChecker#getSourceVisitor (for a custom SourceVisitor)
createFactory(com.sun.source.tree.CompilationUnitTree) (for a custom AnnotatedTypeFactory)
getSuppressWarningsKey() (for honoring
SuppressWarnings annotations)
| Field Summary | |
|---|---|
protected CompilationUnitTree |
currentRoot
The source tree that's being scanned. |
protected ProcessingEnvironment |
env
Provides access to compiler helpers/internals. |
protected com.sun.tools.javac.processing.JavacMessager |
messager
Used to report error messages and warnings via the compiler. |
protected Properties |
messages
Maps error keys to localized/custom error messages. |
protected Pattern |
skipPattern
A regular expression for classes that should be skipped. |
protected Trees |
trees
Used as a helper for the SourceVisitor. |
| Fields inherited from class javax.annotation.processing.AbstractProcessor |
|---|
processingEnv |
| Constructor Summary | |
|---|---|
SourceChecker()
|
|
| Method Summary | |
|---|---|
AnnotatedTypeFactory |
createFactory(CompilationUnitTree root)
|
protected abstract SourceVisitor<?,?> |
createSourceVisitor(CompilationUnitTree root)
Provides the SourceVisitor that the checker should use to scan
input source trees. |
boolean |
getLintOption(String name)
Determines the value of the lint option with the given name. |
boolean |
getLintOption(String name,
boolean def)
Determines the value of the lint option with the given name. |
Properties |
getMessages()
Provides a mapping of error keys to custom error messages. |
ProcessingEnvironment |
getProcessingEnvironment()
|
Pattern |
getShouldSkip()
Returns a regular expression pattern to specify java classes that are not annotated, and thus whose warnings and should be surpressed. |
Set<String> |
getSupportedAnnotationTypes()
Always returns a singleton set containing only "*", forcing all type checkers to run always (even on unannotated code), and explicitly checks that subclasses do not contain a SupportedAnnotationTypes
annotation on their declarations. |
Set<String> |
getSupportedLintOptions()
Returns the lint options recognized by this checker. |
Set<String> |
getSupportedOptions()
|
SourceVersion |
getSupportedSourceVersion()
|
protected String |
getSuppressWarningsKey()
|
void |
init(ProcessingEnvironment processingEnv)
|
protected void |
message(Diagnostic.Kind kind,
Object source,
Object msgKey,
Object... args)
Prints a message (error, warning, note, etc.) via JSR-269. |
boolean |
process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv)
|
void |
report(Result r,
Object src)
Reports a result. |
boolean |
shouldSkip(String className)
Determines whether checking against members of the class with the given name should be performed. |
| Methods inherited from class javax.annotation.processing.AbstractProcessor |
|---|
getCompletions, isInitialized |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected ProcessingEnvironment env
protected Properties messages
protected com.sun.tools.javac.processing.JavacMessager messager
protected Trees trees
SourceVisitor.
protected CompilationUnitTree currentRoot
protected final Pattern skipPattern
| Constructor Detail |
|---|
public SourceChecker()
| Method Detail |
|---|
public ProcessingEnvironment getProcessingEnvironment()
ProcessingEnvironment that was supplied to this
checkerpublic AnnotatedTypeFactory createFactory(CompilationUnitTree root)
root - the AST root for the factory
AnnotatedTypeFactory for use by typecheckersprotected abstract SourceVisitor<?,?> createSourceVisitor(CompilationUnitTree root)
SourceVisitor that the checker should use to scan
input source trees.
root - the AST root
SourceVisitor to use to scan source treespublic Properties getMessages()
Properties that maps error keys to error message textpublic void init(ProcessingEnvironment processingEnv)
init in interface Processorinit in class AbstractProcessorAbstractProcessor.init(javax.annotation.processing.ProcessingEnvironment)
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv)
process in interface Processorprocess in class AbstractProcessorAbstractProcessor.process(java.util.Set,
javax.annotation.processing.RoundEnvironment)
protected void message(Diagnostic.Kind kind,
Object source,
Object msgKey,
Object... args)
kind - the type of message to printsource - the object from which to obtain source position informationmsgKey - the message key to printargs - arguments for interpolation in the string corresponding to the
given message key
IllegalArgumentException - if source is neither a Tree nor an
ElementDiagnostic
public void report(Result r,
Object src)
r - the result to reportsrc - the position object associated with the resultpublic boolean shouldSkip(String className)
checkers.skipClasses property.
className - the fully qualified name of the class to check
className should
not be checked againstpublic boolean getLintOption(String name)
name - the name of the lint option to check for
IllegalArgumentException - if the option name is not recognized
via the SupportedLintOptions annotation or the getSupportedLintOptions() methodgetLintOption(String,boolean)
public boolean getLintOption(String name,
boolean def)
def argument (the default
option value).
name - the name of the lint option to check fordef - the default option value, returned if the option was not given
def if it was not given at all
IllegalArgumentException - if the option name is not recognized
via the SupportedLintOptions annotation or the getSupportedLintOptions() methodgetLintOption(String)public Set<String> getSupportedOptions()
getSupportedOptions in interface ProcessorgetSupportedOptions in class AbstractProcessorpublic final Set<String> getSupportedAnnotationTypes()
SupportedAnnotationTypes
annotation on their declarations.
To specify the annotations that a checker recognizes as type qualifiers,
use the TypeQualifiers annotation on the declaration of
subclasses of this class or override the
BaseTypeChecker.getSupportedTypeQualifiers() method.
getSupportedAnnotationTypes in interface ProcessorgetSupportedAnnotationTypes in class AbstractProcessorError - if a subclass is annotated with
SupportedAnnotationTypesTypeQualifiers,
getSupportedAnnotationTypes()public Set<String> getSupportedLintOptions()
getLintOption(java.lang.String).
Set of the lint options recognized by
this checker@Nullable protected String getSuppressWarningsKey()
SuppressWarningsKeypublic Pattern getShouldSkip()
checkers.skipClasses; otherwise it returns a pattern that can
match no class.
public SourceVersion getSupportedSourceVersion()
getSupportedSourceVersion in interface ProcessorgetSupportedSourceVersion in class AbstractProcessor
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||