@SupportedAnnotationTypes(value="*") @SupportedSourceVersion(value=RELEASE_8) public class TreePrinter extends AbstractTypeProcessor
The class is actually an annotation processor; in order to use it, invoke the compiler on the
source file(s) for which you wish to view the AST of the program. You may also wish to use the
-proc:only
javac option to stop compilation after annotation processing. (But, in general
-proc:only
causes type annotation processors not to be run.)
A simple main method is also provided. Put jsr308-all.jar on the bootclasspath and you can invoke this tool as:
java org.checkerframework.common.util.debug.TreePrinter *.java
TODO: is there an environment variable for the bootclasspath?
The visitor simply uses the javac Pretty visitor to output a nicely formatted version of the AST.
TODO: I couldn't find a way to display the result of Pretty, therefore I wrote this simple class. If there already was a way, please let me know.
TODO: what I really want is something like SignaturePrinter, but for the whole source of the program, that is, for each type in the program use the factory to determine the defaulted annotations on the type.
TreeDebug
processingEnv
Constructor and Description |
---|
TreePrinter() |
Modifier and Type | Method and Description |
---|---|
static void |
main(String[] args) |
void |
typeProcess(TypeElement element,
TreePath tree)
Processes a fully-analyzed class that contains a supported annotation (see
AbstractProcessor.getSupportedAnnotationTypes() ). |
init, process, typeProcessingOver, typeProcessingStart
getCompletions, getSupportedAnnotationTypes, getSupportedOptions, getSupportedSourceVersion, isInitialized
public void typeProcess(TypeElement element, TreePath tree)
AbstractTypeProcessor
AbstractProcessor.getSupportedAnnotationTypes()
).
The passed class is always valid type-checked Java code.
typeProcess
in class AbstractTypeProcessor
element
- element of the analyzed classtree
- the tree path to the element, with the leaf being a ClassTree