-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
046c082
commit b865c3f
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
kotlinpoet/processor/src/main/kotlin/annotator/ReceiversByTarget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package dev.kord.codegen.generator.annotator | ||
|
||
import com.google.devtools.ksp.symbol.KSClassDeclaration | ||
import com.google.devtools.ksp.symbol.KSType | ||
import com.squareup.kotlinpoet.* | ||
import dev.kord.codegen.ksp.annotations.AnnotationArguments | ||
import dev.kord.codegen.ksp.annotations.AnnotationArguments.Companion.arguments | ||
import dev.kord.codegen.ksp.getAnnotationByType | ||
import kotlin.reflect.KClass | ||
import kotlin.reflect.KProperty1 | ||
|
||
val KSClassDeclaration.receiversByTarget: List<ClassName> | ||
get() { | ||
val targetAnnotation = getAnnotationByType<Target>() | ||
val targetsRaw = targetAnnotation.arguments<Target>() | ||
val targets = targetsRaw[Target::allowedTargets]!! | ||
|
||
return buildList { | ||
if (AnnotationTarget.FILE in targets) { | ||
add(FileSpec.Builder::class) | ||
} | ||
if (AnnotationTarget.FUNCTION in targets || AnnotationTarget.PROPERTY_GETTER in targets || AnnotationTarget.PROPERTY_SETTER in targets) { | ||
add(FunSpec.Builder::class) | ||
} | ||
if (AnnotationTarget.VALUE_PARAMETER in targets) { | ||
add(ParameterSpec.Builder::class) | ||
} | ||
if (AnnotationTarget.CLASS in targets) { | ||
add(TypeSpec.Builder::class) | ||
} | ||
if (AnnotationTarget.TYPEALIAS in targets) { | ||
add(TypeAliasSpec.Builder::class) | ||
} | ||
if (AnnotationTarget.PROPERTY in targets) { | ||
add(PropertySpec.Builder::class) | ||
} | ||
}.map(KClass<*>::asClassName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters