Class AutoServiceProcessor
- java.lang.Object
-
- javax.annotation.processing.AbstractProcessor
-
- com.google.auto.service.processor.AutoServiceProcessor
-
- All Implemented Interfaces:
javax.annotation.processing.Processor
@SupportedOptions({"debug","verify"}) public class AutoServiceProcessor extends javax.annotation.processing.AbstractProcessorProcessesAutoServiceannotations and generates the service provider configuration files described inServiceLoader.Processor Options:
-Adebug- turns on debug statements-Averify=true- turns on extra verification
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.StringMISSING_SERVICES_ERRORprivate com.google.common.collect.Multimap<java.lang.String,java.lang.String>providersMaps the class names of service provider interfaces to the class names of the concrete classes which implement them.
-
Constructor Summary
Constructors Constructor Description AutoServiceProcessor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleancheckImplementer(javax.lang.model.element.TypeElement providerImplementer, javax.lang.model.element.TypeElement providerType, javax.lang.model.element.AnnotationMirror annotationMirror)VerifiesServiceProviderconstraints on the concrete provider class.private voiderror(java.lang.String msg, javax.lang.model.element.Element element, javax.lang.model.element.AnnotationMirror annotation)private voidfatalError(java.lang.String msg)private voidgenerateConfigFiles()private java.lang.StringgetBinaryName(javax.lang.model.element.TypeElement element)Returns the binary name of a reference type.private java.lang.StringgetBinaryNameImpl(javax.lang.model.element.TypeElement element, java.lang.String className)com.google.common.collect.ImmutableSet<java.lang.String>getSupportedAnnotationTypes()javax.lang.model.SourceVersiongetSupportedSourceVersion()private com.google.common.collect.ImmutableSet<javax.lang.model.type.DeclaredType>getValueFieldOfClasses(javax.lang.model.element.AnnotationMirror annotationMirror)Returns the contents of aClass[]-typed "value" field in a givenannotationMirror.private voidlog(java.lang.String msg)booleanprocess(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)For each class annotated withAutoServiceVerify theAutoServiceinterface value is correct Categorize the class by its service interface For eachAutoServiceinterface Create a file namedMETA-INF/services/<interface>For eachAutoServiceannotated class for this interface Create an entry in the fileprivate voidprocessAnnotations(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)private voidprocessImpl(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)private static booleanrawTypesSuppressed(javax.lang.model.element.Element element)private voidwarning(java.lang.String msg, javax.lang.model.element.Element element, javax.lang.model.element.AnnotationMirror annotation)
-
-
-
Field Detail
-
MISSING_SERVICES_ERROR
static final java.lang.String MISSING_SERVICES_ERROR
- See Also:
- Constant Field Values
-
providers
private final com.google.common.collect.Multimap<java.lang.String,java.lang.String> providers
Maps the class names of service provider interfaces to the class names of the concrete classes which implement them.For example,
"com.google.apphosting.LocalRpcService" -> "com.google.apphosting.datastore.LocalDatastoreService"
-
-
Method Detail
-
getSupportedAnnotationTypes
public com.google.common.collect.ImmutableSet<java.lang.String> getSupportedAnnotationTypes()
- Specified by:
getSupportedAnnotationTypesin interfacejavax.annotation.processing.Processor- Overrides:
getSupportedAnnotationTypesin classjavax.annotation.processing.AbstractProcessor
-
getSupportedSourceVersion
public javax.lang.model.SourceVersion getSupportedSourceVersion()
- Specified by:
getSupportedSourceVersionin interfacejavax.annotation.processing.Processor- Overrides:
getSupportedSourceVersionin classjavax.annotation.processing.AbstractProcessor
-
process
public boolean process(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)- For each class annotated with
AutoService- Verify the
AutoServiceinterface value is correct - Categorize the class by its service interface
- Verify the
- For each
AutoServiceinterface- Create a file named
META-INF/services/<interface> - For each
AutoServiceannotated class for this interface- Create an entry in the file
- Create a file named
- Specified by:
processin interfacejavax.annotation.processing.Processor- Specified by:
processin classjavax.annotation.processing.AbstractProcessor
- For each class annotated with
-
processImpl
private void processImpl(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)
-
processAnnotations
private void processAnnotations(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)
-
generateConfigFiles
private void generateConfigFiles()
-
checkImplementer
private boolean checkImplementer(javax.lang.model.element.TypeElement providerImplementer, javax.lang.model.element.TypeElement providerType, javax.lang.model.element.AnnotationMirror annotationMirror)VerifiesServiceProviderconstraints on the concrete provider class. Note that these constraints are enforced at runtime via the ServiceLoader, we're just checking them at compile time to be extra nice to our users.
-
rawTypesSuppressed
private static boolean rawTypesSuppressed(javax.lang.model.element.Element element)
-
getBinaryName
private java.lang.String getBinaryName(javax.lang.model.element.TypeElement element)
Returns the binary name of a reference type. For example,com.google.Foo$Bar, instead ofcom.google.Foo.Bar.
-
getBinaryNameImpl
private java.lang.String getBinaryNameImpl(javax.lang.model.element.TypeElement element, java.lang.String className)
-
getValueFieldOfClasses
private com.google.common.collect.ImmutableSet<javax.lang.model.type.DeclaredType> getValueFieldOfClasses(javax.lang.model.element.AnnotationMirror annotationMirror)
Returns the contents of aClass[]-typed "value" field in a givenannotationMirror.
-
log
private void log(java.lang.String msg)
-
warning
private void warning(java.lang.String msg, javax.lang.model.element.Element element, javax.lang.model.element.AnnotationMirror annotation)
-
error
private void error(java.lang.String msg, javax.lang.model.element.Element element, javax.lang.model.element.AnnotationMirror annotation)
-
fatalError
private void fatalError(java.lang.String msg)
-
-