Compiler Tree API

com.sun.source.util
Class AbstractTypeProcessor

java.lang.Object
  extended by javax.annotation.processing.AbstractProcessor
      extended by com.sun.source.util.AbstractTypeProcessor
All Implemented Interfaces:
Processor

public abstract class AbstractTypeProcessor
extends AbstractProcessor

This class is an abstract annotation processor designed to be a convenient superclass for concrete "type processors", processors that require the type information in the processed source.

Type processing occurs in one round after the tool (e.g. java compiler) analyzes the source (all sources taken as input to the tool and sources generated by other annotation processors).

The tool infrastructure will interact with classes extending this abstract class as follows:

    [1-3: Identical to Processor life cycle]
  1. If an existing Processor object is not being used, to create an instance of a processor the tool calls the no-arg constructor of the processor class.
  2. Next, the tool calls the init method with an appropriate ProcessingEnvironment.
  3. Afterwards, the tool calls getSupportedAnnotationTypes, getSupportedOptions, and getSupportedSourceVersion. These methods are only called once per run, not on each round. [4-5Unique to AbstractTypeProcessor subclasses]
  4. For each class containing a supported annotation, the tool calls typeProcess method on the Processor. The class is guaranteed to be type-checked Java code and all the tree type and symbol information is resolved.
  5. Finally, the tools calls the typeProcessingOver method on the Processor.

The tool is permitted to ask type processors to process a class once it is analyzed before the rest of classes are analyzed. The tool is also permitted to stop type processing immediately if any errors are raised, without invoking typeProcessingOver

A subclass may override any of the methods in this class, as long as the general Processor contract is obeyed, with one notable exception. process(Set, RoundEnvironment) may not be overridden, as it is called during the regular annotation phase before classes are analyzed.

Since:
1.7

Field Summary
Modifier and Type Field and Description
 
Fields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv
 
Constructor Summary
Modifier Constructor and Description
protected AbstractTypeProcessor()
          Constructor for subclasses to call.
 
Method Summary
Modifier and Type Method and Description
 void init(ProcessingEnvironment env)
          
 boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
          The use of this method is obsolete in type processors.
abstract  void typeProcess(TypeElement element, TreePath tree)
          Processes a fully analyzed class that contains a supported annotation (look AbstractProcessor.getSupportedAnnotationTypes()).
 void typeProcessingOver()
          A method to be called once all the classes are processed and no error is reported.
 
Methods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, getSupportedAnnotationTypes, getSupportedOptions, getSupportedSourceVersion, isInitialized
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTypeProcessor

protected AbstractTypeProcessor()
Constructor for subclasses to call.

Method Detail

init

public void init(ProcessingEnvironment env)

Specified by:
init in interface Processor
Overrides:
init in class AbstractProcessor

process

public final boolean process(Set<? extends TypeElement> annotations,
                             RoundEnvironment roundEnv)
The use of this method is obsolete in type processors. The method is called during regular annotation processing phase only.

Specified by:
process in interface Processor
Specified by:
process in class AbstractProcessor

typeProcess

public abstract void typeProcess(TypeElement element,
                                 TreePath tree)
Processes a fully analyzed class that contains a supported annotation (look AbstractProcessor.getSupportedAnnotationTypes()).

The passed class is always a valid type-checked Java code.

Parameters:
element - element of the analyzed class
tree - the tree path to the element, with the leaf being a ClassTree

typeProcessingOver

public void typeProcessingOver()
A method to be called once all the classes are processed and no error is reported.

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

If an error (a Java error or a processor error) is reported, this method is not guaranteed to be invoked.


Compiler Tree API

Report a bug or request a feature.
Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.