Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d1913a9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add support for adding module in the same class annotated with @DialerRootComponent."

parents 05dce3a8 560eb125
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -50,6 +50,6 @@ public final class DemoDaggerApplication extends Application implements HasRootC
  public void onCreate() {
    super.onCreate();

    DemoSubcomponent.get(this).demoObject();
    DemoSubcomponent.get(this).demoObjects();
  }
}
+3 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import com.android.dialer.inject.DialerVariant;
import com.android.dialer.inject.InstallIn;
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.IntoSet;

/** Module for demo dagger application. */
@Module
@@ -29,7 +30,8 @@ public final class DemoModule {
  private DemoModule() {}

  @Provides
  @IntoSet
  static DemoObject provide() {
    return new DemoObject("prod");
    return DemoObject.create("prod");
  }
}
+7 −9
Original line number Diff line number Diff line
@@ -16,17 +16,15 @@

package com.android.dialer.inject.demo;

/** Object used to demonstrate dagger bindings. */
class DemoObject {
import com.google.auto.value.AutoValue;

  private final String value;
/** Object used to demonstrate dagger bindings. */
@AutoValue
abstract class DemoObject {

  DemoObject(String value) {
    this.value = value;
  }
  abstract String value();

  @Override
  public String toString() {
    return value;
  static DemoObject create(String value) {
    return new AutoValue_DemoObject(value);
  }
}
+2 −1
Original line number Diff line number Diff line
@@ -20,12 +20,13 @@ import android.content.Context;
import com.android.dialer.inject.HasRootComponent;
import com.android.dialer.inject.IncludeInDialerRoot;
import dagger.Subcomponent;
import java.util.Set;

/** Subcomponent for the demo dagger application. */
@Subcomponent
public abstract class DemoSubcomponent {

  abstract DemoObject demoObject();
  abstract Set<DemoObject> demoObjects();

  public static DemoSubcomponent get(Context context) {
    return ((HasComponent) ((HasRootComponent) context.getApplicationContext()).component())
+20 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.dialer.rootcomponentgenerator;
import static com.google.auto.common.AnnotationMirrors.getAnnotationValue;
import static com.google.auto.common.MoreElements.getAnnotationMirror;
import static com.google.auto.common.MoreElements.isAnnotationPresent;
import static javax.tools.Diagnostic.Kind.ERROR;

import com.android.dialer.inject.DialerRootComponent;
import com.android.dialer.inject.DialerVariant;
@@ -61,15 +62,23 @@ final class RootComponentGeneratingStep implements ProcessingStep {

  @Override
  public Set<? extends Class<? extends Annotation>> annotations() {
    return ImmutableSet.of(DialerRootComponent.class);
    return ImmutableSet.of(DialerRootComponent.class, InstallIn.class, IncludeInDialerRoot.class);
  }

  @Override
  public Set<? extends Element> process(
      SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) {
    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
      // generated in the same round and the metadata is accessible in the next round.
      if (elementsByAnnotation.containsKey(InstallIn.class)
          || elementsByAnnotation.containsKey(IncludeInDialerRoot.class)) {
        return elementsByAnnotation.get(DialerRootComponent.class);
      } else {
        generateRootComponent(MoreElements.asType(element));
      }
    }
    return Collections.emptySet();
  }

@@ -124,6 +133,15 @@ final class RootComponentGeneratingStep implements ProcessingStep {
      Class<? extends Annotation> annotation, MetadataProcessor metadataProcessor) {
    PackageElement cachePackage =
        processingEnv.getElementUtils().getPackageElement(RootComponentUtils.METADATA_PACKAGE_NAME);
    if (cachePackage == null) {
      processingEnv
          .getMessager()
          .printMessage(
              ERROR,
              "Metadata haven't been generated! do you forget to add modules "
                  + "or components in dependency of dialer root?");
      return;
    }
    for (Element element : cachePackage.getEnclosedElements()) {
      Optional<AnnotationMirror> metadataAnnotation =
          getAnnotationMirror(element, RootComponentGeneratorMetadata.class);