Class AutoServiceProcessor
java.lang.Object
javax.annotation.processing.AbstractProcessor
com.google.auto.service.processor.AutoServiceProcessor
- All Implemented Interfaces:
Processor
Processes
AutoService
annotations and generates the service provider
configuration files described in ServiceLoader
.
Processor Options:
- debug - turns on debug statements
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final String
Maps the class names of service provider interfaces to the class names of the concrete classes which implement them.Fields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
checkImplementer
(TypeElement providerImplementer, TypeElement providerType) VerifiesServiceProvider
constraints on the concrete provider class.private void
error
(String msg, Element element, AnnotationMirror annotation) private void
fatalError
(String msg) private void
private String
getBinaryName
(TypeElement element) Returns the binary name of a reference type.private String
getBinaryNameImpl
(TypeElement element, String className) com.google.common.collect.ImmutableSet<String>
private com.google.common.collect.ImmutableSet<DeclaredType>
getValueFieldOfClasses
(AnnotationMirror annotationMirror) Returns the contents of aClass[]
-typed "value" field in a givenannotationMirror
.private void
boolean
process
(Set<? extends TypeElement> annotations, 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
(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) private boolean
processImpl
(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) Methods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, getSupportedOptions, init, isInitialized
-
Field Details
-
MISSING_SERVICES_ERROR
- See Also:
-
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"
-
-
Constructor Details
-
AutoServiceProcessor
public AutoServiceProcessor()
-
-
Method Details
-
getSupportedAnnotationTypes
- Specified by:
getSupportedAnnotationTypes
in interfaceProcessor
- Overrides:
getSupportedAnnotationTypes
in classAbstractProcessor
-
getSupportedSourceVersion
- Specified by:
getSupportedSourceVersion
in interfaceProcessor
- Overrides:
getSupportedSourceVersion
in classAbstractProcessor
-
process
- 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 interfaceProcessor
- Specified by:
process
in classAbstractProcessor
- For each class annotated with
-
processImpl
-
processAnnotations
-
generateConfigFiles
private void generateConfigFiles() -
checkImplementer
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. -
getBinaryName
Returns the binary name of a reference type. For example,com.google.Foo$Bar
, instead ofcom.google.Foo.Bar
. -
getBinaryNameImpl
-
getValueFieldOfClasses
private com.google.common.collect.ImmutableSet<DeclaredType> getValueFieldOfClasses(AnnotationMirror annotationMirror) Returns the contents of aClass[]
-typed "value" field in a givenannotationMirror
. -
log
-
error
-
fatalError
-