Skip to content

Instantly share code, notes, and snippets.

@Foso
Last active October 11, 2019 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Foso/ca126f184378ff2afb98d29f5355ebff to your computer and use it in GitHub Desktop.
Save Foso/ca126f184378ff2afb98d29f5355ebff to your computer and use it in GitHub Desktop.
MpApt find @JsName
package de.jensklingenberg
import de.jensklingenberg.mpapt.common.simpleName
import de.jensklingenberg.mpapt.model.AbstractProcessor
import de.jensklingenberg.mpapt.model.Element
import de.jensklingenberg.mpapt.model.RoundEnvironment
import de.jensklingenberg.mpapt.utils.KotlinPlatformValues
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.resolve.descriptorUtil.module
class MpAptTestProcessor : AbstractProcessor() {
val TAG = "MyAnnotationProcessor"
val jsName = "kotlin.js.JsName"
val jsNamesList = mutableListOf<String>()
override fun initProcessor() {
log("$TAG***Processor started on ***")
}
override fun isTargetPlatformSupported(platform: TargetPlatform): Boolean {
val targetName = platform.first().platformName
return when (targetName) {
KotlinPlatformValues.JS -> true
else -> {
false
}
}
}
/**
* Add the name of the annotation to the processor
*/
override fun getSupportedAnnotationTypes(): Set<String> = setOf(jsName)
override fun process(roundEnvironment: RoundEnvironment) {
roundEnvironment.getElementsAnnotatedWith(jsName).forEach {
when (it) {
is Element.FunctionElement -> {
val name = it.annotation?.allValueArguments?.get(Name.identifier("name"))?.value.toString()
log("Found Function: " + it.func.name + "with :"+jsName+" and value:"+name)
jsNamesList.add(name)
}
is Element.ClassElement -> {
val name = it.annotation?.allValueArguments?.get(Name.identifier("name"))?.value.toString()
log("Found Class: " + it.classDescriptor.name + "with :"+jsName+" and value:"+name)
jsNamesList.add(name)
}
else -> {
/**
* Check [Element] for the other types that available
*/
}
}
}
}
/**
* When processing is over, write the list to any file
*/
override fun processingOver() {
log("$TAG***Processor over ***")
jsNamesList.forEach {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment