checkers.util.test
Class FactoryTestChecker

java.lang.Object
  extended by javax.annotation.processing.AbstractProcessor
      extended by com.sun.source.util.AbstractTypeProcessor
          extended by checkers.source.SourceChecker
              extended by 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:

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).


Field Summary
Modifier and Type Field and Description
 
Fields inherited from class checkers.source.SourceChecker
currentPath, currentRoot, env, messager, messages, skipPattern, trees
 
Fields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv
 
Constructor Summary
Constructor and Description
FactoryTestChecker()
           
 
Method Summary
Modifier and Type Method and Description
 AnnotatedTypeFactory createFactory(CompilationUnitTree root)
           
protected  SourceVisitor<Void,Void> createSourceVisitor(CompilationUnitTree root)
          Provides the SourceVisitor that the checker should use to scan input source trees.
 Properties getMessages()
          Provides a mapping of error keys to custom error messages.
 void init(ProcessingEnvironment p)
          
 
Methods inherited from class checkers.source.SourceChecker
getLintOption, getLintOption, getProcessingEnvironment, getShouldSkip, getSupportedAnnotationTypes, getSupportedLintOptions, getSupportedOptions, getSupportedSourceVersion, getSuppressWarningsKey, message, report, shouldSkip, typeProcess
 
Methods inherited from class com.sun.source.util.AbstractTypeProcessor
process, typeProcessingOver
 
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
 

Constructor Detail

FactoryTestChecker

public FactoryTestChecker()
Method Detail

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