Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Sep 20, 2023
1 parent aafba71 commit a0e66ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,80 +6,79 @@ import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.TypeSpec
import dev.kord.codegen.kotlinpoet.addAnnotation
import kotlin.String

/**
* Adds `JsName` to this [FunSpec]
*/
public fun FunSpec.Builder.jsName(name: String) {
addAnnotation(ClassName("kotlin.js", "JsName")) {
addMember("%S", name)
}
addAnnotation(ClassName("kotlin.js", "JsName")) {
addMember("%S", name)
}
}

/**
* Adds `JsName` to this [TypeSpec]
*/
public fun TypeSpec.Builder.jsName(name: String) {
addAnnotation(ClassName("kotlin.js", "JsName")) {
addMember("%S", name)
}
addAnnotation(ClassName("kotlin.js", "JsName")) {
addMember("%S", name)
}
}

/**
* Adds `JsName` to this [PropertySpec]
*/
public fun PropertySpec.Builder.jsName(name: String) {
addAnnotation(ClassName("kotlin.js", "JsName")) {
addMember("%S", name)
}
addAnnotation(ClassName("kotlin.js", "JsName")) {
addMember("%S", name)
}
}

/**
* Adds `JsExport` to this [FileSpec]
*/
public fun FileSpec.Builder.jsExport() {
addAnnotation(ClassName("kotlin.js", "JsExport"))
addAnnotation(ClassName("kotlin.js", "JsExport"))
}

/**
* Adds `JsExport` to this [FunSpec]
*/
public fun FunSpec.Builder.jsExport() {
addAnnotation(ClassName("kotlin.js", "JsExport"))
addAnnotation(ClassName("kotlin.js", "JsExport"))
}

/**
* Adds `JsExport` to this [TypeSpec]
*/
public fun TypeSpec.Builder.jsExport() {
addAnnotation(ClassName("kotlin.js", "JsExport"))
addAnnotation(ClassName("kotlin.js", "JsExport"))
}

/**
* Adds `JsExport` to this [PropertySpec]
*/
public fun PropertySpec.Builder.jsExport() {
addAnnotation(ClassName("kotlin.js", "JsExport"))
addAnnotation(ClassName("kotlin.js", "JsExport"))
}

/**
* Adds `Ignore` to this [FunSpec]
*/
public fun FunSpec.Builder.ignore() {
addAnnotation(ClassName("kotlin.js", "JsExport", "Ignore"))
addAnnotation(ClassName("kotlin.js", "JsExport", "Ignore"))
}

/**
* Adds `Ignore` to this [TypeSpec]
*/
public fun TypeSpec.Builder.ignore() {
addAnnotation(ClassName("kotlin.js", "JsExport", "Ignore"))
addAnnotation(ClassName("kotlin.js", "JsExport", "Ignore"))
}

/**
* Adds `Ignore` to this [PropertySpec]
*/
public fun PropertySpec.Builder.ignore() {
addAnnotation(ClassName("kotlin.js", "JsExport", "Ignore"))
addAnnotation(ClassName("kotlin.js", "JsExport", "Ignore"))
}
5 changes: 1 addition & 4 deletions kotlinpoet/processor/src/main/kotlin/annotator/Annotator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import com.squareup.kotlinpoet.ksp.writeTo
import dev.kord.codegen.generator.utils.ADD_ANNOTATION
import dev.kord.codegen.generator.utils.mapToValueParameterList
import dev.kord.codegen.kotlinpoet.CodeBlock
import dev.kord.codegen.kotlinpoet.FileSpec
import dev.kord.codegen.kotlinpoet.addFunction
import dev.kord.codegen.kotlinpoet.withControlFlow
import dev.kord.codegen.ksp.annotations.AnnotationArguments.Companion.arguments
import dev.kord.codegen.ksp.getAnnotationByType
import dev.kord.codegen.generator.utils.FileSpec

@OptIn(KspExperimental::class)
fun SymbolProcessorEnvironment.processAnnotators(resolver: Resolver, origin: KSFile, annotators: Sequence<Annotator>) {
Expand All @@ -31,9 +31,6 @@ fun SymbolProcessorEnvironment.processAnnotators(resolver: Resolver, origin: KSF
.filter { it.classKind == ClassKind.ANNOTATION_CLASS }
.filter { it.simpleName.asString() !in annotator.ignore }
.forEach {
val targetAnnotation = it.getAnnotationByType<Target>()
val targetsRaw = targetAnnotation.arguments<Target>()
val targets = targetsRaw[Target::allowedTargets]!!
it.generateAnnotator(origin, this)
}
}
Expand Down

0 comments on commit a0e66ae

Please sign in to comment.