Skip to content

AnnotationProcessing_Configurer

Ladislav Gazo edited this page Aug 29, 2015 · 1 revision

The "standard way"

Using @SupportedAnnotationTypes annotation (used mainly to support all annotations using asterix "*")

@SupportedAnnotationTypes("sk.seges.sesam.core.annotation.CustomAnnotation")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class SesamProcessor extends AbstractProcessor {
}

or using getSupportedAnnotationTypes method (in order to have type safe code)

@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class SesamProcessor extends AbstractProcessor {
	@Override
	public Set<String> getSupportedAnnotationTypes() {
		Set<String> annotations = new HashSet<String>();
		annotations.add(CustomAnnotation.class.getCanonicalName());
		return annotations;
	}
}

Using configurers

public class SesamProcessorConfigurer extends DefaultProcessorConfigurer {

	@Override
	protected Type[] getConfigurationElement(DefaultConfigurationElement element) {
		switch (element) {
		case PROCESSING_ANNOTATIONS:
			return new Type[] {
				CustomAnnotation.class
			};
		}
		return new Type[] {};
	}

}

@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class SesamProcessor extends MutableAnnotationProcessor {
	@Override
	protected ProcessorConfigurer getConfigurer() {
		return new SesamProcessorConfigurer();
	}	
}

Clone this wiki locally