Consistently convert local functions to UAST
This commit is contained in:
@@ -156,10 +156,26 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin {
|
||||
KotlinUClass.create(lightClass, givenParent)
|
||||
}
|
||||
}
|
||||
is KtFunction -> el<UMethod> {
|
||||
val lightMethod = LightClassUtil.getLightClassMethod(original) ?: return null
|
||||
convertDeclaration(lightMethod, givenParent, requiredType)
|
||||
}
|
||||
is KtFunction ->
|
||||
if (original.isLocal) {
|
||||
el<ULambdaExpression> {
|
||||
if (original.name.isNullOrEmpty()) {
|
||||
createLocalFunctionLambdaExpression(original, givenParent)
|
||||
}
|
||||
else {
|
||||
val uDeclarationsExpression = createLocalFunctionDeclaration(original, givenParent)
|
||||
val localFunctionVar = uDeclarationsExpression.declarations.single() as KotlinLocalFunctionUVariable
|
||||
localFunctionVar.uastInitializer
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
el<UMethod> {
|
||||
val lightMethod = LightClassUtil.getLightClassMethod(original) ?: return null
|
||||
convertDeclaration(lightMethod, givenParent, requiredType)
|
||||
}
|
||||
}
|
||||
|
||||
is KtPropertyAccessor -> el<UMethod> {
|
||||
val lightMethod = LightClassUtil.getLightClassAccessorMethod(original) ?: return null
|
||||
convertDeclaration(lightMethod, givenParent, requiredType)
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
||||
|
||||
|
||||
private class KotlinLocalFunctionUVariable(
|
||||
internal class KotlinLocalFunctionUVariable(
|
||||
val function: KtFunction,
|
||||
override val psi: PsiVariable,
|
||||
givenParent: UElement?
|
||||
@@ -50,7 +50,7 @@ private class KotlinLocalFunctionULambdaExpression(
|
||||
|
||||
|
||||
fun createLocalFunctionDeclaration(function: KtFunction, parent: UElement?): UDeclarationsExpression {
|
||||
return KotlinUDeclarationsExpression(parent).apply {
|
||||
return KotlinUDeclarationsExpression(null, parent, function).apply {
|
||||
val functionVariable = UastKotlinPsiVariable.create(function.name.orAnonymous(), function, this)
|
||||
declarations = listOf(KotlinLocalFunctionUVariable(function, functionVariable, this))
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ abstract class AbstractKotlinRenderLogTest : AbstractKotlinUastTest(), RenderLog
|
||||
if (expectedParents != null) {
|
||||
assertNotNull("Expected to be able to convert PSI element $element", uElement)
|
||||
val parents = generateSequence(uElement!!.uastParent) { it.uastParent }.joinToString { it.asLogString() }
|
||||
assertEquals("Inconsistent parents for $uElement", expectedParents, parents)
|
||||
assertEquals("Inconsistent parents for $uElement (converted from $element)", expectedParents, parents)
|
||||
}
|
||||
super.visitElement(element)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user