checkers.util.test
Class FactoryTestChecker
java.lang.Object
javax.annotation.processing.AbstractProcessor
com.sun.source.util.AbstractTypeProcessor
checkers.source.SourceChecker
checkers.util.test.FactoryTestChecker
- All Implemented Interfaces:
- Processor
@SupportedSourceVersion(value=RELEASE_7)
@SupportedOptions(value="checker")
public class FactoryTestChecker
extends SourceChecker
A specialized checker for testing purposes. It compares an expression's
annotated type to an exprected type.
The expected type is written in a stylized comment (starting with '///')
in the same Java source file. The comment appears either on the same
line as the expression, or else by itself on the line preceeding the
expression.
The comments are of two forms:
/// <expected type>
:
to specify the type of the expression in the expression statement
/// <subtree> -:- <expected type>
:
to specify the type of the given subexpression within the line.
The specified types are allowed to use simple names (e.g.,
List<String>), instead of fully qualified names (e.g.,
java.util.List<java.lang.String>).
Example:
void test() {
// Comments in the same line
Collections.<@NonNull String>emptyList(); /// List<@NonNull String>
List<@NonNull String> l = Collections.emptyList(); /// Collections.emptyList() -:- List<@NonNull String>
// Comments in the previous lines
/// List<@NonNull String>
Collections.<@NonNull String>emptyList();
/// Collections.emptyList() -:- List<@NonNull String>
List<@NonNull String> l = Collections.emptyList();
}
The fully qualified name of the custom AnnotatedTypeFactory is
specified through an -Afactory argument (e.g.
-Afactory=checkers.nullness.NullnessAnnotatedTypeFactory). The factory needs
to have a constractor of the form
<init>(ProcessingEnvironment, CompilationUnitTree)
.
Methods inherited from class checkers.source.SourceChecker |
getLintOption, getLintOption, getProcessingEnvironment, getShouldSkip, getSupportedAnnotationTypes, getSupportedLintOptions, getSupportedOptions, getSupportedSourceVersion, getSuppressWarningsKey, message, report, shouldSkip, typeProcess |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
FactoryTestChecker
public FactoryTestChecker()
init
public void init(ProcessingEnvironment p)
- Description copied from class:
SourceChecker
-
- Specified by:
init
in interface Processor
- Overrides:
init
in class SourceChecker
- See Also:
AbstractProcessor.init(ProcessingEnvironment)
createFactory
public AnnotatedTypeFactory createFactory(CompilationUnitTree root)
- Overrides:
createFactory
in class SourceChecker
- Parameters:
root
- the AST root for the factory
- Returns:
- an
AnnotatedTypeFactory
for use by typecheckers
getMessages
public Properties getMessages()
- Description copied from class:
SourceChecker
- Provides a mapping of error keys to custom error messages.
As a default, this implementation builds a
Properties
out of
file messages.properties
. It accumulates all the properties files
in the Java class hierarchy from the checker up to SourceChecker
.
This permits subclasses to inherit default messages while being able to
override them.
- Overrides:
getMessages
in class SourceChecker
- Returns:
- a
Properties
that maps error keys to error message text
createSourceVisitor
protected SourceVisitor<Void,Void> createSourceVisitor(CompilationUnitTree root)
- Description copied from class:
SourceChecker
- Provides the
SourceVisitor
that the checker should use to scan
input source trees.
- Specified by:
createSourceVisitor
in class SourceChecker
- Parameters:
root
- the AST root
- Returns:
- a
SourceVisitor
to use to scan source trees