Class AnnotationStatistics

All Implemented Interfaces:
Processor, OptionConfiguration

@SupportedOptions({"nolocations","annotations","annotationserror","annotationsummaryonly"}) @SupportedSourceVersion(RELEASE_8) public class AnnotationStatistics extends SourceChecker
An annotation processor for counting the annotations in a program and for listing the potential locations of annotations. To invoke it, use
 javac -proc:only -processor org.checkerframework.common.util.count.AnnotationStatistics MyFile.java ...
 

By default, this utility displays annotation locations only, but not the annotations themselves. Further, the output includes all annotations (including @Override, etc.), which is not very useful.

The following options can be used to adjust the output:

  • -Aannotations: prints the annotation name, the file that contains it, and whether it is in a signature or in a body
  • -Anolocations: suppresses location output; only makes sense in conjunction with -Aannotations
  • -Aannotationsummaryonly: with both of the above, only outputs a summary
  • -Aannotationserror: histogram is issued as a warning, not just printed

These use cases are not very useful, because they include all annotations including @Override, etc.

  • Output the locations of annotations, but not the annotations themselves: normal invocation, as above
  • Histogram of the locations of annotations, by location type: ... | sort | uniq -c
  • Total annotation count: ... | wc.
  • Count for only certain location types: use grep
See Also:
  • Constructor Details

    • AnnotationStatistics

      public AnnotationStatistics()
      Creates an AnnotationStatistics.
  • Method Details

    • typeProcessingOver

      public void typeProcessingOver()
      Description copied from class: AbstractTypeProcessor
      A method to be called once all the classes are processed.

      Subclasses can override this method to do any aggregate analysis (e.g., generate a report, persistence) or resource deallocation.

      Method AbstractTypeProcessor.getCompilerLog() can be used to access the number of compiler errors.

      Overrides:
      typeProcessingOver in class SourceChecker
    • incrementCount

      protected void incrementCount(Name annoName)
      Increments the number of times the annotation with name annoName has appeared.
      Parameters:
      annoName - the name of the annotation that was encountered
    • createSourceVisitor

      protected SourceVisitor<?,?> createSourceVisitor()
      Description copied from class: SourceChecker
      Provides the SourceVisitor that the checker should use to scan input source trees.
      Specified by:
      createSourceVisitor in class SourceChecker
      Returns:
      a SourceVisitor to use to scan source trees
    • getAnnotationProvider

      public AnnotationProvider getAnnotationProvider()
      Description copied from class: SourceChecker
      Returns the AnnotationProvider (the type factory) associated with this.
      Overrides:
      getAnnotationProvider in class SourceChecker
      Returns:
      the AnnotationProvider (the type factory) associated with this