From 836b75d30853816739a0db0b69a34d03fd850b6b Mon Sep 17 00:00:00 2001 From: weijiaxu Date: Fri, 1 Jun 2018 12:05:52 -0700 Subject: Remove @GenerateTestDaggerApp from RCG. Test: tap presubmit. PiperOrigin-RevId: 198907001 Change-Id: Ida32182c4d6a45334cb120e1e2183abae3af2a54 --- .../android/dialer/inject/DialerRootComponent.java | 2 ++ .../RootComponentGeneratingStep.java | 28 ++++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) (limited to 'java') diff --git a/java/com/android/dialer/inject/DialerRootComponent.java b/java/com/android/dialer/inject/DialerRootComponent.java index 11dbf962e..e508e17b6 100644 --- a/java/com/android/dialer/inject/DialerRootComponent.java +++ b/java/com/android/dialer/inject/DialerRootComponent.java @@ -41,4 +41,6 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.SOURCE) public @interface DialerRootComponent { DialerVariant variant(); + + Class injectClass() default Object.class; } diff --git a/java/com/android/dialer/rootcomponentgenerator/RootComponentGeneratingStep.java b/java/com/android/dialer/rootcomponentgenerator/RootComponentGeneratingStep.java index 5321849ec..06b994ff7 100644 --- a/java/com/android/dialer/rootcomponentgenerator/RootComponentGeneratingStep.java +++ b/java/com/android/dialer/rootcomponentgenerator/RootComponentGeneratingStep.java @@ -26,7 +26,6 @@ import com.android.dialer.inject.DialerVariant; import com.android.dialer.inject.IncludeInDialerRoot; import com.android.dialer.inject.InstallIn; import com.android.dialer.inject.RootComponentGeneratorMetadata; -import com.android.dialer.inject.testing.GenerateTestDaggerApp; import com.google.auto.common.BasicAnnotationProcessor.ProcessingStep; import com.google.auto.common.MoreElements; import com.google.common.base.Optional; @@ -81,27 +80,18 @@ final class RootComponentGeneratingStep implements ProcessingStep { private final ProcessingEnvironment processingEnv; - private TypeElement annotatedTest; - public RootComponentGeneratingStep(ProcessingEnvironment processingEnv) { this.processingEnv = processingEnv; } @Override public Set> annotations() { - return ImmutableSet.of( - DialerRootComponent.class, - InstallIn.class, - IncludeInDialerRoot.class, - GenerateTestDaggerApp.class); + return ImmutableSet.of(DialerRootComponent.class, InstallIn.class, IncludeInDialerRoot.class); } @Override public Set process( SetMultimap, Element> elementsByAnnotation) { - for (Element element : elementsByAnnotation.get(GenerateTestDaggerApp.class)) { - annotatedTest = MoreElements.asType(element); - } for (Element element : elementsByAnnotation.get(DialerRootComponent.class)) { // defer root components to the next round in case where the current build target contains // elements annotated with @InstallIn. Annotation processor cannot detect metadata files @@ -144,9 +134,15 @@ final class RootComponentGeneratingStep implements ProcessingStep { componentAnnotation.addMember("modules", "$T.class", annotatedElement.asType()); } rootComponentClassBuilder.addAnnotation(componentAnnotation.build()); - if (annotatedTest != null) { - rootComponentClassBuilder.addMethod(generateInjectMethod()); - } + + AnnotationMirror dialerRootComponentMirror = + getAnnotationMirror(rootElement, DialerRootComponent.class).get(); + + TypeMirror annotatedTestClass = + (TypeMirror) getAnnotationValue(dialerRootComponentMirror, "injectClass").getValue(); + + rootComponentClassBuilder.addMethod(generateInjectMethod(annotatedTestClass)); + TypeSpec rootComponentClass = rootComponentClassBuilder.build(); RootComponentUtils.writeJavaFile( processingEnv, ClassName.get(rootElement).packageName(), rootComponentClass); @@ -200,11 +196,11 @@ final class RootComponentGeneratingStep implements ProcessingStep { } } - private MethodSpec generateInjectMethod() { + private MethodSpec generateInjectMethod(TypeMirror testClassTypeMirror) { return MethodSpec.methodBuilder("inject") .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT) .returns(void.class) - .addParameter(ClassName.get(annotatedTest), "test") + .addParameter(ClassName.get(testClassTypeMirror), "clazz") .build(); } -- cgit v1.2.3