https://kotlinlang.org logo
#android-studio
Title
# android-studio
n

Nick Kleban

03/11/2024, 4:03 PM
Is it possible to get access to my own Kotlin class in a live template groovyScript() method? I want to get access to the constructor params for my live template. I’m trying something like:
Copy code
groovyScript("Class.forName(_1).constructors", qualifiedClassName())
groovyScript("Class.forName(_1).constructors", kotlinClassName())
Ended up with groovy script that looks like
Copy code
def packageName = _1
def className = _2
def qualifiedClassName = "$packageName.$className"

def scope = GlobalSearchScope.allScope(_editor.project)
def psiClass = JavaPsiFacade.getInstance(_editor.project)
    .findClass(qualifiedClassName, scope)

return psiClass.constructors
    .first()
    .parameters
    .collect { param -> "${param.name}: ${param.tryGetKotlinType()}," }
    .join("\n")