Class FactoryTestChecker

All Implemented Interfaces:
Processor, OptionConfiguration

@SupportedSourceVersion(RELEASE_8) @SupportedOptions("checker") public class FactoryTestChecker extends BaseTypeChecker
A specialized checker for testing purposes. It compares an expression's annotated type to an expected 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 preceding 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 command-line argument (e.g. -Afactory=checkers.nullness.NullnessAnnotatedTypeFactory). The factory needs to have a constructor of the form <init>(ProcessingEnvironment, CompilationUnitTree).
  • Constructor Details

    • FactoryTestChecker

      public FactoryTestChecker()
  • Method Details

    • initChecker

      public void initChecker()
      Description copied from class: SourceChecker
      Initialize the checker.
      Overrides:
      initChecker in class BaseTypeChecker
      See Also:
    • getMessagesProperties

      public Properties getMessagesProperties()
      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:
      getMessagesProperties in class SourceChecker
      Returns:
      a Properties that maps error keys to error message text
    • createSourceVisitor

      protected BaseTypeVisitor<?> createSourceVisitor()
      Description copied from class: BaseTypeChecker
      Returns the appropriate visitor that type-checks the compilation unit according to the type system rules.

      This implementation uses the checker naming convention to create the appropriate visitor. If no visitor is found, it returns an instance of 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.

      Overrides:
      createSourceVisitor in class BaseTypeChecker
      Returns:
      the type-checking visitor