Auto-Dagger2 icon indicating copy to clipboard operation
Auto-Dagger2 copied to clipboard

Inheritance issue

Open novachevskyi opened this issue 8 years ago • 0 comments

I was implementing inheritance hierarchy with my screens and faced an issue with @AutoComponent.

I have next hierarchy of components: -- MainActivityComponent ---- DrawerKeyComponent ------ ListKeyComponent

I got manually defined MainActivityComponent. DrawerKeyComponent and ListKeyComponent was generated with auto-dagger:

@ScopeSingleton(MainActivityComponent::class)
@Component(
    dependencies = arrayOf(AppComponent::class),
    modules = arrayOf(MainActivityModule::class)
)
interface MainActivityComponent : AppComponent
@AutoComponent(
    dependencies = arrayOf(MainActivityComponent::class),
    superinterfaces = arrayOf(MainActivityComponent::class)
)
@ScopeSingleton(DrawerKey::class)
class DrawerKey
@AutoComponent(
    dependencies = arrayOf(DrawerKeyComponent::class),
    superinterfaces = arrayOf(DrawerKeyComponent::class),
    modules = arrayOf(ListModule::class)
)
@ScopeSingleton(ListKey::class)
class ListKey

Auto-generated components:

@Generated("autodagger.compiler.AnnotationProcessor")
@Component(
    dependencies = MainActivityComponent.class
)
@ScopeSingleton(DrawerKey.class)
public interface DrawerKeyComponent extends MainActivityComponent
@Generated("autodagger.compiler.AnnotationProcessor")
@Component(
    modules = ListModule.class
)
@ScopeSingleton(ListKey.class)
public interface ListKeyComponent

For some reason ListKeyComponent was generated without inheritance from DrawerKeyComponent. So I tried to define DrawerKeyComponent manually and use @AutoComponent only for ListKey. Here what I get in a result:

@Component(dependencies = arrayOf(MainActivityComponent::class))
@ScopeSingleton(DrawerKey::class)
interface DrawerKeyComponent : MainActivityComponent
@Generated("autodagger.compiler.AnnotationProcessor")
@Component(
    dependencies = DrawerKeyComponent.class,
    modules = ListKeyModule.class
)
@ScopeSingleton(ListKey.class)
public interface ListKeyComponent extends DrawerKeyComponent

In this case inheritance was set properly.

I was also testing example-kotlin project and it seems that auto-dagger can't setup inheritance from auto-generated components at all. To reproduce this issue you can set in example-kotlin next declaration for Container1:

@AutoComponent(
        dependencies = arrayOf(KotlinMainActivityComponent::class), 
        superinterfaces = arrayOf(KotlinMainActivityComponent::class)
)
@ScopeSingleton(Container1::class)
class Container1 {}

Generated component will look like this:

@Generated("autodagger.compiler.AnnotationProcessor")
@Component
@ScopeSingleton(Container1.class)
public interface Container1Component {
}

In this case Container1Component is not extended from KotlinMainActivityComponent as expected.

Would be appreciated for any help.

novachevskyi avatar Aug 15 '16 17:08 novachevskyi