diff options
-rw-r--r-- | java/com/android/dialer/rootcomponentgenerator/annotation/IncludeInDialerRoot.java (renamed from java/com/android/dialer/rootcomponentgenerator/annotation/DialerComponent.java) | 24 | ||||
-rw-r--r-- | java/com/android/dialer/rootcomponentgenerator/processor/ComponentGeneratingStep.java | 11 | ||||
-rw-r--r-- | java/com/android/dialer/rootcomponentgenerator/processor/MetadataGeneratingStep.java | 20 | ||||
-rw-r--r-- | java/com/android/dialer/rootcomponentgenerator/processor/RootComponentGeneratingStep.java | 7 |
4 files changed, 34 insertions, 28 deletions
diff --git a/java/com/android/dialer/rootcomponentgenerator/annotation/DialerComponent.java b/java/com/android/dialer/rootcomponentgenerator/annotation/IncludeInDialerRoot.java index 573abae7f..4ce9ec3a3 100644 --- a/java/com/android/dialer/rootcomponentgenerator/annotation/DialerComponent.java +++ b/java/com/android/dialer/rootcomponentgenerator/annotation/IncludeInDialerRoot.java @@ -20,26 +20,28 @@ import java.lang.annotation.ElementType; import java.lang.annotation.Target; /** - * Annotates a type equivalent to {@link dagger.Subcomponent}. + * Annotates a type that should be included in Dialer Root Component. Typically, annotated types are + * HasComponent interfaces. * - * <p>The annotation processor will generate a new type file with some prefix, which contains public - * static XXX get(Context context) method and HasComponent interface like: - * - * <p> + * <p>An example: * * <pre> * <code> - * public static SimulatorComponent get(Context context) { - * HasRootComponent hasRootComponent = (HasRootComponent) context.getApplicationContext(); - * return ((HasComponent)(hasRootComponent.component()).simulatorComponent(); - * } - * public interface HasComponent { + * {@literal @}dagger.Subcomponent + * public abstract class SimulatorComponent { + * public static SimulatorComponent get(Context context) { + * return ((HasComponent)((HasRootComponent) context.getApplicationContext()).component()) + * .simulatorComponent(); + * } + * {@literal @}IncludeInDialerRoot + * public interface HasComponent { * SimulatorComponent simulatorComponent(); * } + * } * </code> * </pre> */ @Target(ElementType.TYPE) -public @interface DialerComponent { +public @interface IncludeInDialerRoot { Class<?>[] modules() default {}; } diff --git a/java/com/android/dialer/rootcomponentgenerator/processor/ComponentGeneratingStep.java b/java/com/android/dialer/rootcomponentgenerator/processor/ComponentGeneratingStep.java index 8605499c7..04d42ac59 100644 --- a/java/com/android/dialer/rootcomponentgenerator/processor/ComponentGeneratingStep.java +++ b/java/com/android/dialer/rootcomponentgenerator/processor/ComponentGeneratingStep.java @@ -23,7 +23,7 @@ import static javax.lang.model.element.Modifier.PUBLIC; import static javax.lang.model.element.Modifier.STATIC; import static javax.lang.model.util.ElementFilter.typesIn; -import com.android.dialer.rootcomponentgenerator.annotation.DialerComponent; +import com.android.dialer.rootcomponentgenerator.annotation.IncludeInDialerRoot; import com.google.auto.common.BasicAnnotationProcessor.ProcessingStep; import com.google.auto.common.MoreElements; import com.google.common.base.Optional; @@ -52,7 +52,7 @@ import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; /** - * Generates component for a type annotated with {@link DialerComponent}. + * Generates component for a type annotated with {@link IncludeInDialerRoot}. * * <p>Our components have boilerplate code like: * @@ -67,6 +67,7 @@ import javax.lang.model.type.TypeMirror; * return ((HasComponent)((HasRootComponent) context.getApplicationContext()).component()) * .simulatorComponent(); * } + * {@literal @}IncludeInDialerRoot * public interface HasComponent { * SimulatorComponent simulatorComponent(); * } @@ -88,13 +89,13 @@ final class ComponentGeneratingStep implements ProcessingStep { @Override public Set<? extends Class<? extends Annotation>> annotations() { - return ImmutableSet.of(DialerComponent.class); + return ImmutableSet.of(IncludeInDialerRoot.class); } @Override public Set<? extends Element> process( SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) { - for (TypeElement type : typesIn(elementsByAnnotation.get(DialerComponent.class))) { + for (TypeElement type : typesIn(elementsByAnnotation.get(IncludeInDialerRoot.class))) { generateComponent(type); } return Collections.emptySet(); @@ -124,7 +125,7 @@ final class ComponentGeneratingStep implements ProcessingStep { private AnnotationSpec makeDaggerSubcomponentAnnotation(TypeElement dialerComponentElement) { Optional<AnnotationMirror> componentMirror = - getAnnotationMirror(dialerComponentElement, DialerComponent.class); + getAnnotationMirror(dialerComponentElement, IncludeInDialerRoot.class); AnnotationSpec.Builder subcomponentBuilder = AnnotationSpec.builder(Subcomponent.class); for (AnnotationValue annotationValue : diff --git a/java/com/android/dialer/rootcomponentgenerator/processor/MetadataGeneratingStep.java b/java/com/android/dialer/rootcomponentgenerator/processor/MetadataGeneratingStep.java index b7d31c0e9..3b46ed0d0 100644 --- a/java/com/android/dialer/rootcomponentgenerator/processor/MetadataGeneratingStep.java +++ b/java/com/android/dialer/rootcomponentgenerator/processor/MetadataGeneratingStep.java @@ -18,22 +18,25 @@ package com.android.dialer.rootcomponentgenerator.processor; import static javax.tools.Diagnostic.Kind.ERROR; +import com.android.dialer.rootcomponentgenerator.annotation.IncludeInDialerRoot; import com.android.dialer.rootcomponentgenerator.annotation.InstallIn; import com.android.dialer.rootcomponentgenerator.annotation.RootComponentGeneratorMetadata; import com.google.auto.common.BasicAnnotationProcessor.ProcessingStep; +import com.google.auto.common.MoreElements; import com.google.common.collect.ImmutableSet; import com.google.common.collect.SetMultimap; import com.squareup.javapoet.AnnotationSpec; import com.squareup.javapoet.TypeSpec; -import dagger.Subcomponent; import java.lang.annotation.Annotation; import java.util.Collections; import java.util.Set; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; /** - * Genereates metadata for every type annotated by {@link InstallIn} and {@link Subcomponent}. + * Genereates metadata for every type annotated by {@link InstallIn} and {@link + * IncludeInDialerRoot}. * * <p>The metadata has the information where the annotated types are and it is used by annotation * processor when the processor tries to generate root component. @@ -48,15 +51,15 @@ final class MetadataGeneratingStep implements ProcessingStep { @Override public Set<? extends Class<? extends Annotation>> annotations() { - return ImmutableSet.of(Subcomponent.class, InstallIn.class); + return ImmutableSet.of(IncludeInDialerRoot.class, InstallIn.class); } @Override public Set<? extends Element> process( SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) { - for (Element element : elementsByAnnotation.get(Subcomponent.class)) { - generateMetadataFor(Subcomponent.class, element); + for (Element element : elementsByAnnotation.get(IncludeInDialerRoot.class)) { + generateMetadataFor(IncludeInDialerRoot.class, MoreElements.asType(element)); } for (Element element : elementsByAnnotation.get(InstallIn.class)) { if (element.getAnnotation(InstallIn.class).variants().length == 0) { @@ -66,16 +69,17 @@ final class MetadataGeneratingStep implements ProcessingStep { ERROR, String.format("@InstallIn %s must have at least one variant", element)); continue; } - generateMetadataFor(InstallIn.class, element); + generateMetadataFor(InstallIn.class, MoreElements.asType(element)); } return Collections.emptySet(); } private void generateMetadataFor( - Class<? extends Annotation> annotation, Element annotatedElement) { + Class<? extends Annotation> annotation, TypeElement annotatedElement) { TypeSpec.Builder metadataClassBuilder = - TypeSpec.classBuilder(annotatedElement.getSimpleName() + "Metadata"); + TypeSpec.classBuilder( + annotatedElement.getQualifiedName().toString().replace('.', '_') + "Metadata"); metadataClassBuilder.addAnnotation( AnnotationSpec.builder(RootComponentGeneratorMetadata.class) .addMember("tag", "$S", annotation.getSimpleName()) diff --git a/java/com/android/dialer/rootcomponentgenerator/processor/RootComponentGeneratingStep.java b/java/com/android/dialer/rootcomponentgenerator/processor/RootComponentGeneratingStep.java index 9b97adafd..ad91a3cbe 100644 --- a/java/com/android/dialer/rootcomponentgenerator/processor/RootComponentGeneratingStep.java +++ b/java/com/android/dialer/rootcomponentgenerator/processor/RootComponentGeneratingStep.java @@ -22,6 +22,7 @@ import static com.google.auto.common.MoreElements.isAnnotationPresent; import com.android.dialer.rootcomponentgenerator.annotation.DialerRootComponent; import com.android.dialer.rootcomponentgenerator.annotation.DialerVariant; +import com.android.dialer.rootcomponentgenerator.annotation.IncludeInDialerRoot; import com.android.dialer.rootcomponentgenerator.annotation.InstallIn; import com.android.dialer.rootcomponentgenerator.annotation.RootComponentGeneratorMetadata; import com.google.auto.common.BasicAnnotationProcessor.ProcessingStep; @@ -35,7 +36,6 @@ import com.squareup.javapoet.AnnotationSpec; import com.squareup.javapoet.ClassName; import com.squareup.javapoet.TypeSpec; import dagger.Component; -import dagger.Subcomponent; import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collections; @@ -89,8 +89,7 @@ final class RootComponentGeneratingStep implements ProcessingStep { .addModifiers(Modifier.PUBLIC) .addAnnotation(Singleton.class); for (TypeElement componentWithSuperInterface : componentList) { - rootComponentClassBuilder.addSuperinterface( - ClassName.get(componentWithSuperInterface).nestedClass("HasComponent")); + rootComponentClassBuilder.addSuperinterface(ClassName.get(componentWithSuperInterface)); } AnnotationSpec.Builder componentAnnotation = AnnotationSpec.builder(Component.class); for (TypeElement annotatedElement : componentModuleMap.get(dialerVariant)) { @@ -104,7 +103,7 @@ final class RootComponentGeneratingStep implements ProcessingStep { private List<TypeElement> generateComponentList() { List<TypeElement> list = new ArrayList<>(); - extractInfoFromMetadata(Subcomponent.class, list::add); + extractInfoFromMetadata(IncludeInDialerRoot.class, list::add); return list; } |