Skip to content

Commit c4e843e

Browse files
committed
Implement featureScope/featureComponent support for @DevelopmentAppComponent
When `featureScope` and `featureComponent` are set on `@DevelopmentAppComponent`, the compiler plugin now generates two additional types that redirect the `FeatureProvider` binding from `ActivityScope` to the feature scope: - `FeatureLoginScreenComponent`: a `@ContributesTo(featureScope)` interface extending `DevelopmentLoginScreenComponent`, making `FeatureProvider` available at the feature scope. - `NoopLoginScreenComponent`: a `@ContributesTo(ActivityScope::class, replaces = [ContributedDevelopmentLoginScreenComponent::class])` interface that removes the default login screen component from `ActivityScope`, so `FeatureProvider` is no longer required there. This matches what the KSP generator produced. Without these types, demo apps with a feature scope fail to compile because `ContributedDevelopmentLoginScreenComponent.featureProvider()` demands `FeatureProvider` at `ActivityScope`, but the app only provides it at the feature scope. New stubs (minimal copies from android-register): - `ActivityScope`, `FeatureProvider`, `DevelopmentLoginScreenComponent`, `ContributedDevelopmentLoginScreenComponent`, `DefaultFeatureModule`, `DevelopmentFeatureScopeComponent` Tests: - Box test: multi-module compilation verifying the graph compiles and runs - FIR dump test: validates the generated FIR structure - Integration test: `FeatureScopeDemoApp` with `featureScope`/`featureComponent`
1 parent 22c5fb9 commit c4e843e

17 files changed

Lines changed: 948 additions & 2 deletions

File tree

compiler/api/compiler.api

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public final class com/squareup/metro/extensions/SquareMetroExtensionsPluginRegi
2525
public final class com/squareup/metro/extensions/developmentapp/DevelopmentAppComponentFir : dev/zacsweers/metro/compiler/api/fir/MetroFirDeclarationGenerationExtension {
2626
public fun <init> (Lorg/jetbrains/kotlin/fir/FirSession;)V
2727
public fun generateNestedClassLikeDeclaration (Lorg/jetbrains/kotlin/fir/symbols/impl/FirClassSymbol;Lorg/jetbrains/kotlin/name/Name;Lorg/jetbrains/kotlin/fir/extensions/DeclarationGenerationContext$Nested;)Lorg/jetbrains/kotlin/fir/symbols/impl/FirClassLikeSymbol;
28+
public fun getContributionHints ()Ljava/util/List;
2829
public fun getNestedClassifiersNames (Lorg/jetbrains/kotlin/fir/symbols/impl/FirClassSymbol;Lorg/jetbrains/kotlin/fir/extensions/DeclarationGenerationContext$Nested;)Ljava/util/Set;
2930
public fun registerPredicates (Lorg/jetbrains/kotlin/fir/extensions/FirDeclarationPredicateRegistrar;)V
3031
}
@@ -34,6 +35,17 @@ public final class com/squareup/metro/extensions/developmentapp/DevelopmentAppCo
3435
public fun create (Lorg/jetbrains/kotlin/fir/FirSession;Ldev/zacsweers/metro/compiler/MetroOptions;)Ldev/zacsweers/metro/compiler/api/fir/MetroFirDeclarationGenerationExtension;
3536
}
3637

38+
public final class com/squareup/metro/extensions/developmentapp/DevelopmentAppComponentMetroExtension : dev/zacsweers/metro/compiler/api/fir/MetroContributionExtension {
39+
public fun <init> (Lorg/jetbrains/kotlin/fir/FirSession;)V
40+
public fun getContributions (Lorg/jetbrains/kotlin/name/ClassId;)Ljava/util/List;
41+
public fun registerPredicates (Lorg/jetbrains/kotlin/fir/extensions/FirDeclarationPredicateRegistrar;)V
42+
}
43+
44+
public final class com/squareup/metro/extensions/developmentapp/DevelopmentAppComponentMetroExtension$Factory : dev/zacsweers/metro/compiler/api/fir/MetroContributionExtension$Factory {
45+
public fun <init> ()V
46+
public fun create (Lorg/jetbrains/kotlin/fir/FirSession;Ldev/zacsweers/metro/compiler/MetroOptions;)Ldev/zacsweers/metro/compiler/api/fir/MetroContributionExtension;
47+
}
48+
3749
public final class com/squareup/metro/extensions/featureflag/ContributesFeatureFlagFir : dev/zacsweers/metro/compiler/api/fir/MetroFirDeclarationGenerationExtension {
3850
public fun <init> (Lorg/jetbrains/kotlin/fir/FirSession;)V
3951
public fun generateNestedClassLikeDeclaration (Lorg/jetbrains/kotlin/fir/symbols/impl/FirClassSymbol;Lorg/jetbrains/kotlin/name/Name;Lorg/jetbrains/kotlin/fir/extensions/DeclarationGenerationContext$Nested;)Lorg/jetbrains/kotlin/fir/symbols/impl/FirClassLikeSymbol;

compiler/src/main/kotlin/com/squareup/metro/extensions/ClassIds.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ internal object ClassIds {
6767

6868
val APPLICATION = ClassId(FqName("android.app"), Name.identifier("Application"))
6969

70+
val ACTIVITY_SCOPE = ClassId(FqName("com.squareup.dagger"), Name.identifier("ActivityScope"))
71+
7072
val LOGIN_SCREEN_MODULE =
7173
ClassId(
7274
FqName("com.squareup.development.shell.login.screen"),
@@ -79,6 +81,31 @@ internal object ClassIds {
7981
Name.identifier("DevelopmentLoggedInComponent"),
8082
)
8183

84+
val DEVELOPMENT_LOGIN_SCREEN_COMPONENT =
85+
ClassId(
86+
FqName("com.squareup.development.shell.login.screen"),
87+
Name.identifier("DevelopmentLoginScreenComponent"),
88+
)
89+
90+
val CONTRIBUTED_DEVELOPMENT_LOGIN_SCREEN_COMPONENT =
91+
ClassId(
92+
FqName("com.squareup.development.shell.login.screen"),
93+
Name.identifier("ContributedDevelopmentLoginScreenComponent"),
94+
)
95+
96+
val DEFAULT_FEATURE_MODULE =
97+
ClassId(FqName("com.squareup.development.shell"), Name.identifier("DefaultFeatureModule"))
98+
99+
val DEVELOPMENT_FEATURE_SCOPE_COMPONENT =
100+
ClassId(
101+
FqName("com.squareup.development.shell"),
102+
Name.identifier("DevelopmentFeatureScopeComponent"),
103+
)
104+
105+
val DAGGER_MODULE = ClassId(FqName("dagger"), Name.identifier("Module"))
106+
107+
val BINDS_INSTANCE = ClassId(FqName("dev.zacsweers.metro"), Name.identifier("Provides"))
108+
82109
val JAVAX_QUALIFIER = ClassId(FqName("javax.inject"), Name.identifier("Qualifier"))
83110

84111
val METRO_QUALIFIER = ClassId(FqName("dev.zacsweers.metro"), Name.identifier("Qualifier"))

0 commit comments

Comments
 (0)