dev.kolibrium.ksp.processors.ProcessorUtil.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kolibrium-ksp Show documentation
Show all versions of kolibrium-ksp Show documentation
"processors" module of Kolibrium
/*
* Copyright 2023-2024 Attila Fazekas & contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.kolibrium.ksp.processors
import com.google.devtools.ksp.processing.CodeGenerator
import com.google.devtools.ksp.processing.Dependencies
import com.google.devtools.ksp.symbol.KSAnnotation
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSDeclaration
import com.google.devtools.ksp.symbol.KSValueArgument
import com.squareup.kotlinpoet.FileSpec
import kotlin.reflect.KClass
internal const val SELENIUM_PACKAGE_NAME = "org.openqa.selenium"
internal val KSClassDeclaration.generatedPackageName: String
get() = packageName.asString() + ".generated"
internal fun CodeGenerator.writeToFile(
classDeclaration: KSClassDeclaration,
builder: FileSpec.Builder,
) {
val fileSpec =
builder
.addFileComment("Code generated by kolibrium-codegen. Do not edit.")
.build()
createNewFile(
Dependencies(false, classDeclaration.containingFile!!),
fileSpec.packageName,
fileSpec.name,
).writer().use { writer -> fileSpec.writeTo(writer) }
}
internal fun KSDeclaration.getAnnotation(klass: KClass<*>): KSAnnotation? =
annotations.firstOrNull {
it.shortName.asString() == klass.simpleName
}
internal fun KSAnnotation.getArgument(arg: String): KSValueArgument = arguments.first { it.name!!.asString() == arg }
© 2015 - 2024 Weber Informatics LLC | Privacy Policy