FileDocCategorySizeDatePackage
AbstractProcessor.javaAPI DocJava SE 6 API5975Tue Jun 10 00:26:04 BST 2008javax.annotation.processing

AbstractProcessor

public abstract class AbstractProcessor extends Object implements Processor
An abstract annotation processor designed to be a convenient superclass for most concrete annotation processors. This class examines annotation values to compute the {@linkplain #getSupportedOptions options}, {@linkplain #getSupportedAnnotationTypes annotations}, and {@linkplain #getSupportedSourceVersion source version} supported by its subtypes.

The getter methods may {@linkplain Messager#printMessage issue warnings} about noteworthy conditions using the facilities available after the processor has been {@linkplain #isInitialized initialized}.

Subclasses are free to override the implementation and specification of any of the methods in this class as long as the general {@link javax.annotation.processing.Processor Processor} contract for that method is obeyed.

author
Joseph D. Darcy
author
Scott Seligman
author
Peter von der Ahé
version
1.8 06/07/17
since
1.6

Fields Summary
protected ProcessingEnvironment
processingEnv
Processing environment providing by the tool framework.
private boolean
initialized
Constructors Summary
protected AbstractProcessor()
Constructor for subclasses to call.


              
      
Methods Summary
private static java.util.SetarrayToSet(java.lang.String[] array)

	assert array != null;
	Set<String> set = new HashSet<String>(array.length);
	for (String s : array)
	    set.add(s);
	return Collections.unmodifiableSet(set);
    
public java.lang.IterablegetCompletions(javax.lang.model.element.Element element, javax.lang.model.element.AnnotationMirror annotation, javax.lang.model.element.ExecutableElement member, java.lang.String userText)
Returns an empty iterable of completions.

param
element {@inheritDoc}
param
annotation {@inheritDoc}
param
member {@inheritDoc}
param
userText {@inheritDoc}

 
	return Collections.emptyList();
    
public java.util.SetgetSupportedAnnotationTypes()
If the processor class is annotated with {@link SupportedAnnotationTypes}, return an unmodifiable set with the same set of strings as the annotation. If the class is not so annotated, an empty set is returned.

return
the names of the annotation types supported by this processor, or an empty set if none

	    SupportedAnnotationTypes sat = this.getClass().getAnnotation(SupportedAnnotationTypes.class);
	    if  (sat == null) {
		if (isInitialized())
		    processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING,
							     "No SupportedAnnotationTypes annotation " +
							     "found on " + this.getClass().getName() +
							     ", returning an empty set.");
		return Collections.emptySet();
	    }
	    else
		return arrayToSet(sat.value()); 
	
public java.util.SetgetSupportedOptions()
If the processor class is annotated with {@link SupportedOptions}, return an unmodifiable set with the same set of strings as the annotation. If the class is not so annotated, an empty set is returned.

return
the options recognized by this processor, or an empty set if none

	SupportedOptions so = this.getClass().getAnnotation(SupportedOptions.class);
	if  (so == null) 
	    return Collections.emptySet();
	else
	    return arrayToSet(so.value()); 
    
public javax.lang.model.SourceVersiongetSupportedSourceVersion()
If the processor class is annotated with {@link SupportedSourceVersion}, return the source version in the annotation. If the class is not so annotated, {@link SourceVersion#RELEASE_6} is returned.

return
the latest source version supported by this processor

	SupportedSourceVersion ssv = this.getClass().getAnnotation(SupportedSourceVersion.class);
	SourceVersion sv = null;
	if (ssv == null) {
	    sv = SourceVersion.RELEASE_6;
	    if (isInitialized())
		processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING,
							 "No SupportedSourceVersion annotation " +
							 "found on " + this.getClass().getName() +
							 ", returning " + sv + ".");
	} else
	    sv = ssv.value();
	return sv;
    
public synchronized voidinit(javax.annotation.processing.ProcessingEnvironment processingEnv)
Initializes the processor with the processing environment by setting the {@code processingEnv} field to the value of the {@code processingEnv} argument. An {@code IllegalStateException} will be thrown if this method is called more than once on the same object.

param
processingEnv environment to access facilities the tool framework provides to the processor
throws
IllegalStateException if this method is called more than once.

	if (initialized)
	    throw new IllegalStateException("Cannot call init more than once.");
	if (processingEnv == null)
	    throw new NullPointerException("Tool provided null ProcessingEnvironment");

	this.processingEnv = processingEnv;
	initialized = true;
    
protected synchronized booleanisInitialized()
Returns {@code true} if this object has been {@linkplain #init initialized}, {@code false} otherwise.

return
{@code true} if this object has been initialized, {@code false} otherwise.

	return initialized;
    
public abstract booleanprocess(java.util.Set annotations, javax.annotation.processing.RoundEnvironment roundEnv)
{@inheritDoc}