Skip to content

Commit 3710c42

Browse files
committed
Delete dead code
1 parent 9eb478b commit 3710c42

2 files changed

Lines changed: 3 additions & 126 deletions

File tree

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ internal object ClassIds {
101101
Name.identifier("DevelopmentFeatureScopeComponent"),
102102
)
103103

104-
val DAGGER_MODULE = ClassId(FqName("dagger"), Name.identifier("Module"))
105-
106104
val BINDS_INSTANCE = ClassId(FqName("dev.zacsweers.metro"), Name.identifier("Provides"))
107105

108106
val JAVAX_QUALIFIER = ClassId(FqName("javax.inject"), Name.identifier("Qualifier"))

compiler/src/main/kotlin/com/squareup/metro/extensions/developmentapp/DevelopmentAppComponentFir.kt

Lines changed: 3 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public class DevelopmentAppComponentFir(session: FirSession) :
239239
)
240240

241241
// Build the create(@Provides application: Application): MetroComponent method
242-
val createFunction = buildCreateFunction(factoryClassId, owner, factorySymbol)
242+
val createFunction = buildCreateFunction(factoryClassId, owner)
243243

244244
val klass = buildRegularClass {
245245
resolvePhase = FirResolvePhase.BODY_RESOLVE
@@ -276,7 +276,6 @@ public class DevelopmentAppComponentFir(session: FirSession) :
276276
private fun buildCreateFunction(
277277
factoryClassId: ClassId,
278278
metroComponentSymbol: FirClassSymbol<*>,
279-
factorySymbol: FirRegularClassSymbol,
280279
): org.jetbrains.kotlin.fir.declarations.FirFunction {
281280
val callableId = CallableId(factoryClassId, Name.identifier("create"))
282281
val functionSymbol = FirNamedFunctionSymbol(callableId)
@@ -372,10 +371,9 @@ public class DevelopmentAppComponentFir(session: FirSession) :
372371
val ref = innerArg.calleeReference
373372
if (
374373
ref is org.jetbrains.kotlin.fir.references.FirResolvedNamedReference &&
375-
ref.resolvedSymbol is org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol<*>
374+
ref.resolvedSymbol is FirClassLikeSymbol<*>
376375
) {
377-
(ref.resolvedSymbol as org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol<*>)
378-
.classId
376+
(ref.resolvedSymbol as FirClassLikeSymbol<*>).classId
379377
} else {
380378
// Scan the containing file's imports for a matching simple name
381379
val simpleName = ref.name
@@ -498,125 +496,6 @@ public class DevelopmentAppComponentFir(session: FirSession) :
498496
return classSymbol
499497
}
500498

501-
/**
502-
* Generate `@ContributesTo(ActivityScope, replaces=[DefaultFeatureModule]) @Module` object
503-
* providing the feature component class. This is an object with a @Provides method.
504-
*/
505-
private fun generateFeatureModule(owner: FirClassSymbol<*>, name: Name): FirClassLikeSymbol<*>? {
506-
if (!hasFeatureScope(owner)) return null
507-
val featureComponentId = readClassArgument(owner, "featureComponent") ?: return null
508-
// Only generate if all needed types are on the classpath
509-
if (session.symbolProvider.getClassLikeSymbolByClassId(ClassIds.ACTIVITY_SCOPE) == null)
510-
return null
511-
if (session.symbolProvider.getClassLikeSymbolByClassId(ClassIds.DEFAULT_FEATURE_MODULE) == null)
512-
return null
513-
val nestedClassId = owner.classId.createNestedClassId(name)
514-
val classSymbol = FirRegularClassSymbol(nestedClassId)
515-
516-
buildRegularClass {
517-
resolvePhase = FirResolvePhase.BODY_RESOLVE
518-
moduleData = session.moduleData
519-
origin = DevelopmentAppComponentGeneratorKey.origin
520-
source = owner.source
521-
classKind = ClassKind.INTERFACE
522-
scopeProvider = session.kotlinScopeProvider
523-
this.name = nestedClassId.shortClassName
524-
symbol = classSymbol
525-
status =
526-
FirResolvedDeclarationStatusImpl(
527-
Visibilities.Public,
528-
Modality.ABSTRACT,
529-
Visibilities.Public.toEffectiveVisibility(owner, forClass = true),
530-
)
531-
superTypeRefs += session.builtinTypes.anyType
532-
533-
// @ContributesTo(scope = ActivityScope::class, replaces = [DefaultFeatureModule::class])
534-
val scopeExpr = buildScopeClassExpression(ClassIds.ACTIVITY_SCOPE) ?: return null
535-
val replacesArray = buildExcludesArrayLiteral(listOf(ClassIds.DEFAULT_FEATURE_MODULE))
536-
annotations +=
537-
buildContributesToWithReplaces(scopeExpr, replacesArray, classSymbol) ?: return null
538-
539-
// @Module (Dagger annotation — only if on classpath)
540-
session.symbolProvider.getClassLikeSymbolByClassId(ClassIds.DAGGER_MODULE)?.let {
541-
annotations += buildSimpleAnnotationCall(ClassIds.DAGGER_MODULE, classSymbol)
542-
}
543-
544-
// @Provides @DevelopmentFeatureScopeComponent fun provideFeatureScopeComponent(): KClass<*>?
545-
declarations +=
546-
buildProvideFeatureScopeComponentFunction(nestedClassId, classSymbol, featureComponentId)
547-
}
548-
549-
return classSymbol
550-
}
551-
552-
/**
553-
* Build `@Provides @DevelopmentFeatureScopeComponent fun provideFeatureScopeComponent():
554-
* KClass<*>?` that returns the feature component class. The body is not needed — Metro treats
555-
* this as an abstract @Provides in a binding container (interface), so the graph implementation
556-
* provides it. However, since we want it to return a constant, we make it a default method in the
557-
* interface. For FIR, we just declare the signature; the IR extension would need to fill in the
558-
* body.
559-
*
560-
* Actually, Metro's binding containers with @Provides are handled as abstract declarations whose
561-
* return value is provided by the graph. We just need the signature with the right annotations
562-
* and return type.
563-
*/
564-
private fun buildProvideFeatureScopeComponentFunction(
565-
featureModuleClassId: ClassId,
566-
featureModuleSymbol: FirRegularClassSymbol,
567-
featureComponentId: ClassId,
568-
): org.jetbrains.kotlin.fir.declarations.FirFunction {
569-
val callableId =
570-
CallableId(featureModuleClassId, Name.identifier("provideFeatureScopeComponent"))
571-
val functionSymbol = FirNamedFunctionSymbol(callableId)
572-
573-
// Return type: KClass<*>? (nullable)
574-
val kClassClassId = ClassId(FqName("kotlin.reflect"), Name.identifier("KClass"))
575-
val starProjection = org.jetbrains.kotlin.fir.types.ConeStarProjection
576-
val kClassStarType =
577-
ConeClassLikeTypeImpl(
578-
ConeClassLikeLookupTagImpl(kClassClassId),
579-
arrayOf(starProjection),
580-
isMarkedNullable = true,
581-
)
582-
583-
val dispatchType =
584-
ConeClassLikeTypeImpl(
585-
ConeClassLikeLookupTagImpl(featureModuleClassId),
586-
emptyArray(),
587-
isMarkedNullable = false,
588-
)
589-
590-
return buildNamedFunction {
591-
isLocal = false
592-
resolvePhase = FirResolvePhase.BODY_RESOLVE
593-
moduleData = session.moduleData
594-
origin = DevelopmentAppComponentGeneratorKey.origin
595-
symbol = functionSymbol
596-
name = callableId.callableName
597-
returnTypeRef = kClassStarType.toFirResolvedTypeRef()
598-
dispatchReceiverType = dispatchType
599-
status =
600-
FirResolvedDeclarationStatusImpl(
601-
Visibilities.Public,
602-
Modality.ABSTRACT,
603-
Visibilities.Public.toEffectiveVisibility(featureModuleSymbol, forClass = true),
604-
)
605-
606-
// @Provides
607-
this.annotations += buildSimpleAnnotationCall(ClassIds.PROVIDES, functionSymbol)
608-
// @DevelopmentFeatureScopeComponent (qualifier)
609-
if (
610-
session.symbolProvider.getClassLikeSymbolByClassId(
611-
ClassIds.DEVELOPMENT_FEATURE_SCOPE_COMPONENT
612-
) != null
613-
) {
614-
this.annotations +=
615-
buildSimpleAnnotationCall(ClassIds.DEVELOPMENT_FEATURE_SCOPE_COMPONENT, functionSymbol)
616-
}
617-
}
618-
}
619-
620499
/** Build a `ScopeClass::class` expression from a ClassId. */
621500
private fun buildScopeClassExpression(scopeClassId: ClassId): FirExpression? {
622501
val scopeType =

0 commit comments

Comments
 (0)