@SupportedOptions(value={"debug","verify"})
public class AutoServiceProcessor
extends javax.annotation.processing.AbstractProcessor
AutoService
annotations and generates the service provider
configuration files described in ServiceLoader
.
Processor Options:
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
AutoServiceProcessor() |
Modifier and Type | Method and Description |
---|---|
private boolean |
checkImplementer(javax.lang.model.element.TypeElement providerImplementer,
javax.lang.model.element.TypeElement providerType)
Verifies
ServiceProvider 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) |
private javax.lang.model.type.DeclaredType |
getProviderInterface(javax.lang.model.element.AnnotationMirror providerAnnotation) |
com.google.common.collect.ImmutableSet<java.lang.String> |
getSupportedAnnotationTypes() |
javax.lang.model.SourceVersion |
getSupportedSourceVersion() |
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 with
AutoService
Verify the AutoService interface value is correct
Categorize the class by its service interface
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
|
private void |
processAnnotations(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations,
javax.annotation.processing.RoundEnvironment roundEnv) |
private boolean |
processImpl(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations,
javax.annotation.processing.RoundEnvironment roundEnv) |
private com.google.common.collect.Multimap<java.lang.String,java.lang.String> providers
For example,
"com.google.apphosting.LocalRpcService" ->
"com.google.apphosting.datastore.LocalDatastoreService"
public com.google.common.collect.ImmutableSet<java.lang.String> getSupportedAnnotationTypes()
getSupportedAnnotationTypes
in interface javax.annotation.processing.Processor
getSupportedAnnotationTypes
in class javax.annotation.processing.AbstractProcessor
public javax.lang.model.SourceVersion getSupportedSourceVersion()
getSupportedSourceVersion
in interface javax.annotation.processing.Processor
getSupportedSourceVersion
in class javax.annotation.processing.AbstractProcessor
public boolean process(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)
AutoService
AutoService
interface value is correct
AutoService
interface META-INF/services/<interface>
AutoService
annotated class for this interface process
in interface javax.annotation.processing.Processor
process
in class javax.annotation.processing.AbstractProcessor
private boolean processImpl(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)
private void processAnnotations(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)
private void generateConfigFiles()
private boolean checkImplementer(javax.lang.model.element.TypeElement providerImplementer, javax.lang.model.element.TypeElement providerType)
ServiceProvider
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.private java.lang.String getBinaryName(javax.lang.model.element.TypeElement element)
com.google.Foo$Bar
, instead of com.google.Foo.Bar
.private java.lang.String getBinaryNameImpl(javax.lang.model.element.TypeElement element, java.lang.String className)
private javax.lang.model.type.DeclaredType getProviderInterface(javax.lang.model.element.AnnotationMirror providerAnnotation)
private void log(java.lang.String msg)
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)