ragdroid / Dahaka

Demo project for Dagger 2
Apache License 2.0
207 stars 35 forks source link

Providers are made static to remove redundant generated modules object #12

Closed bangarharshit closed 6 years ago

bangarharshit commented 6 years ago

Minor fix to move all the providers to static mode since it will not generate the module objects.

Without static

private final class ItemsActivitySubcomponentBuilder
    extends UserBindingModule_ItemsActivity.ItemsActivitySubcomponent.Builder {
  private ItemsModule itemsModule;

  private ItemsActivity seedInstance;

  @Override
  public UserBindingModule_ItemsActivity.ItemsActivitySubcomponent build() {
    if (itemsModule == null) {
      this.itemsModule = new ItemsModule();
    }
    if (seedInstance == null) {
      throw new IllegalStateException(ItemsActivity.class.getCanonicalName() + " must be set");
    }
    return new ItemsActivitySubcomponentImpl(this);
  }

  @Override
  public void seedInstance(ItemsActivity arg0) {
    this.seedInstance = Preconditions.checkNotNull(arg0);
  }
}

this.provideDividerItemDecorationProvider =
    ItemsModule_ProvideDividerItemDecorationFactory.create(
        builder.itemsModule, seedInstanceProvider);

@Generated(
  value = "dagger.internal.codegen.ComponentProcessor",
  comments = "https://google.github.io/dagger"
)
public final class ItemsModule_ProvideDividerItemDecorationFactory
    implements Factory<DividerItemDecoration> {
  private final ItemsModule module;

  private final Provider<ItemsActivity> activityProvider;

  public ItemsModule_ProvideDividerItemDecorationFactory(
      ItemsModule module, Provider<ItemsActivity> activityProvider) {
    assert module != null;
    this.module = module;
    assert activityProvider != null;
    this.activityProvider = activityProvider;
  }

  @Override
  public DividerItemDecoration get() {
    return Preconditions.checkNotNull(
        module.provideDividerItemDecoration(activityProvider.get()),
        "Cannot return null from a non-@Nullable @Provides method");
  }

  public static Factory<DividerItemDecoration> create(
      ItemsModule module, Provider<ItemsActivity> activityProvider) {
    return new ItemsModule_ProvideDividerItemDecorationFactory(module, activityProvider);
  }
}

With static, the items module object is not generated

private final class ItemsActivitySubcomponentBuilder
    extends UserBindingModule_ItemsActivity.ItemsActivitySubcomponent.Builder {
  private ItemsActivity seedInstance;

  @Override
  public UserBindingModule_ItemsActivity.ItemsActivitySubcomponent build() {
    if (seedInstance == null) {
      throw new IllegalStateException(ItemsActivity.class.getCanonicalName() + " must be set");
    }
    return new ItemsActivitySubcomponentImpl(this);
  }

  @Override
  public void seedInstance(ItemsActivity arg0) {
    this.seedInstance = Preconditions.checkNotNull(arg0);
  }
}

@Generated(
  value = "dagger.internal.codegen.ComponentProcessor",
  comments = "https://google.github.io/dagger"
)
public final class ItemsModule_ProvideHomePresenterFactory
    implements Factory<ItemsContract.Presenter> {
  private final Provider<ItemsPresenter> presenterProvider;

  public ItemsModule_ProvideHomePresenterFactory(Provider<ItemsPresenter> presenterProvider) {
    assert presenterProvider != null;
    this.presenterProvider = presenterProvider;
  }

  @Override
  public ItemsContract.Presenter get() {
    return Preconditions.checkNotNull(
        ItemsModule.provideHomePresenter(presenterProvider.get()),
        "Cannot return null from a non-@Nullable @Provides method");
  }

  public static Factory<ItemsContract.Presenter> create(
      Provider<ItemsPresenter> presenterProvider) {
    return new ItemsModule_ProvideHomePresenterFactory(presenterProvider);
  }

  /** Proxies {@link ItemsModule#provideHomePresenter(ItemsPresenter)}. */
  public static ItemsContract.Presenter proxyProvideHomePresenter(ItemsPresenter presenter) {
    return ItemsModule.provideHomePresenter(presenter);
  }
}

this.provideDividerItemDecorationProvider =
    ItemsModule_ProvideDividerItemDecorationFactory.create(seedInstanceProvider);
ragdroid commented 6 years ago

@harshitbangar123 Looks Great 👍 Thanks