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.AbstractProcessor
ProcessesAutoService
annotations 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.String
MISSING_SERVICES_ERROR
private 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.
-
Constructor Summary
Constructors Constructor Description AutoServiceProcessor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
checkImplementer(javax.lang.model.element.TypeElement providerImplementer, javax.lang.model.element.TypeElement providerType, javax.lang.model.element.AnnotationMirror annotationMirror)
VerifiesServiceProvider
constraints on the concrete provider class.private void
error(java.lang.String msg, javax.lang.model.element.Element element, javax.lang.model.element.AnnotationMirror annotation)
private void
fatalError(java.lang.String msg)
private void
generateConfigFiles()
private java.lang.String
getBinaryName(javax.lang.model.element.TypeElement element)
Returns the binary name of a reference type.private java.lang.String
getBinaryNameImpl(javax.lang.model.element.TypeElement element, java.lang.String className)
com.google.common.collect.ImmutableSet<java.lang.String>
getSupportedAnnotationTypes()
javax.lang.model.SourceVersion
getSupportedSourceVersion()
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 void
log(java.lang.String msg)
boolean
process(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)
For each class annotated withAutoService
Verify theAutoService
interface value is correct Categorize the class by its service interface For eachAutoService
interface Create a file namedMETA-INF/services/<interface>
For eachAutoService
annotated class for this interface Create an entry in the fileprivate void
processAnnotations(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)
private void
processImpl(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)
private static boolean
rawTypesSuppressed(javax.lang.model.element.Element element)
private void
warning(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:
getSupportedAnnotationTypes
in interfacejavax.annotation.processing.Processor
- Overrides:
getSupportedAnnotationTypes
in classjavax.annotation.processing.AbstractProcessor
-
getSupportedSourceVersion
public javax.lang.model.SourceVersion getSupportedSourceVersion()
- Specified by:
getSupportedSourceVersion
in interfacejavax.annotation.processing.Processor
- Overrides:
getSupportedSourceVersion
in 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
AutoService
interface value is correct - Categorize the class by its service interface
- Verify the
- For each
AutoService
interface- Create a file named
META-INF/services/<interface>
- For each
AutoService
annotated class for this interface- Create an entry in the file
- Create a file named
- Specified by:
process
in interfacejavax.annotation.processing.Processor
- Specified by:
process
in 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)
VerifiesServiceProvider
constraints 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)
-
-