@@ -26,6 +26,7 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration
26
26
import com.google.devtools.ksp.symbol.KSDeclaration
27
27
import com.google.devtools.ksp.symbol.KSFunctionDeclaration
28
28
import com.google.devtools.ksp.symbol.KSType
29
+ import com.google.devtools.ksp.symbol.KSTypeAlias
29
30
import com.google.devtools.ksp.symbol.Visibility
30
31
import com.squareup.anvil.annotations.ContributesMultibinding
31
32
import com.squareup.kotlinpoet.AnnotationSpec
@@ -128,8 +129,6 @@ private class CircuitSymbolProcessor(
128
129
private val platforms : List <PlatformInfo >,
129
130
) : SymbolProcessor {
130
131
131
- private val lenient = options[" circuit.codegen.lenient" ]?.toBoolean() ? : false
132
-
133
132
override fun process (resolver : Resolver ): List <KSAnnotated > {
134
133
val symbols = CircuitSymbols .create(resolver) ? : return emptyList()
135
134
val codegenMode =
@@ -174,7 +173,7 @@ private class CircuitSymbolProcessor(
174
173
codegenMode : CodegenMode ,
175
174
) {
176
175
val circuitInjectAnnotation =
177
- annotatedElement.getKSAnnotationsWithLeniency (CIRCUIT_INJECT_ANNOTATION ).single()
176
+ annotatedElement.getKSAnnotationsOfType (CIRCUIT_INJECT_ANNOTATION .canonicalName ).single()
178
177
179
178
// If we annotated a class, check that the class isn't using assisted inject. If so, error and
180
179
// return
@@ -269,7 +268,7 @@ private class CircuitSymbolProcessor(
269
268
annotation : KClass <out Annotation >
270
269
): KSFunctionDeclaration ? {
271
270
return getConstructors().singleOrNull { constructor ->
272
- constructor .isAnnotationPresentWithLeniency (annotation)
271
+ constructor .isAnnotationPresentOfType (annotation)
273
272
}
274
273
}
275
274
@@ -278,7 +277,7 @@ private class CircuitSymbolProcessor(
278
277
if (findConstructorAnnotatedWith(AssistedInject ::class ) != null ) {
279
278
val assistedFactory =
280
279
declarations.filterIsInstance<KSClassDeclaration >().find {
281
- it.isAnnotationPresentWithLeniency (AssistedFactory ::class )
280
+ it.isAnnotationPresentOfType (AssistedFactory ::class )
282
281
}
283
282
val suffix =
284
283
if (assistedFactory != null ) " (${assistedFactory.qualifiedName?.asString()} )" else " "
@@ -291,24 +290,31 @@ private class CircuitSymbolProcessor(
291
290
}
292
291
}
293
292
294
- private fun KSAnnotated.isAnnotationPresentWithLeniency (annotation : KClass <out Annotation >) =
295
- getKSAnnotationsWithLeniency(annotation).any()
296
-
297
- private fun KSAnnotated.getKSAnnotationsWithLeniency (annotation : KClass <out Annotation >) =
298
- getKSAnnotationsWithLeniency(annotation.asClassName())
299
-
300
- private fun KSAnnotated.getKSAnnotationsWithLeniency (
301
- annotation : ClassName
302
- ): Sequence <KSAnnotation > {
303
- val simpleName = annotation.simpleName
304
- return if (lenient) {
305
- annotations.filter { it.shortName.asString() == simpleName }
306
- } else {
307
- val qualifiedName = annotation.canonicalName
308
- this .annotations.filter {
309
- it.shortName.getShortName() == simpleName &&
310
- it.annotationType.resolve().declaration.qualifiedName?.asString() == qualifiedName
293
+ private fun KSAnnotated.isAnnotationPresentOfType (annotation : KClass <out Annotation >) =
294
+ getKSAnnotationsOfType(annotation).any()
295
+
296
+ private fun KSAnnotated.getKSAnnotationsOfType (annotation : KClass <out Annotation >) =
297
+ getKSAnnotationsOfType(annotation.qualifiedName!! )
298
+
299
+ private fun KSAnnotated.getKSAnnotationsOfType (qualifiedName : String ): Sequence <KSAnnotation > {
300
+ return this .annotations.filter {
301
+ it.annotationType
302
+ .resolve()
303
+ .declaration
304
+ .resolveKSClassDeclaration()
305
+ ?.qualifiedName
306
+ ?.asString() == qualifiedName
307
+ }
308
+ }
309
+
310
+ private fun KSDeclaration.resolveKSClassDeclaration (): KSClassDeclaration ? {
311
+ return when (this ) {
312
+ is KSClassDeclaration -> this
313
+ is KSTypeAlias -> {
314
+ // Note: doesn't work for generic aliased types, but we only use this for CircuitInject
315
+ type.resolve().declaration.resolveKSClassDeclaration()
311
316
}
317
+ else -> null
312
318
}
313
319
}
314
320
@@ -438,7 +444,7 @@ private class CircuitSymbolProcessor(
438
444
declaration.checkVisibility(logger) {
439
445
return null
440
446
}
441
- val isAssisted = declaration.isAnnotationPresentWithLeniency (AssistedFactory ::class )
447
+ val isAssisted = declaration.isAnnotationPresentOfType (AssistedFactory ::class )
442
448
val creatorOrConstructor: KSFunctionDeclaration ?
443
449
val targetClass: KSClassDeclaration
444
450
if (isAssisted) {
0 commit comments