From 337f16194a1913ed8e27d29c3ba7d49f6acea734 Mon Sep 17 00:00:00 2001 From: Nicolay Mitropolsky Date: Tue, 26 Feb 2019 20:50:23 +0300 Subject: [PATCH] Uast: resolving references to local function declarations --- .../uast/kotlin/internal/kotlinInternalUastUtils.kt | 9 +++++---- .../uast-kotlin/testData/LocalDeclarations.resolved.txt | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt index 3c04fa70027..2daa39a2748 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt @@ -59,6 +59,7 @@ import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.typeUtil.isInterface import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.uast.* +import org.jetbrains.uast.kotlin.expressions.KotlinLocalFunctionUVariable import java.lang.ref.WeakReference import java.text.StringCharacterIterator @@ -250,19 +251,19 @@ internal fun KtClassOrObject.toPsiType(): PsiType { internal fun PsiElement.getMaybeLightElement(context: UElement): PsiElement? { return when (this) { - is KtVariableDeclaration -> { + is KtDeclaration -> { val lightElement = toLightElements().firstOrNull() if (lightElement != null) return lightElement val languagePlugin = context.getLanguagePlugin() val uElement = languagePlugin.convertElementWithParent(this, null) when (uElement) { - is UDeclaration -> uElement.psi - is UDeclarationsExpression -> uElement.declarations.firstOrNull()?.psi + is UDeclaration -> uElement.javaPsi + is UDeclarationsExpression -> uElement.declarations.firstOrNull()?.javaPsi + is ULambdaExpression -> (uElement.uastParent as? KotlinLocalFunctionUVariable)?.javaPsi else -> null } } - is KtDeclaration -> toLightElements().firstOrNull() is KtElement -> null else -> this } diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.resolved.txt b/plugins/uast-kotlin/testData/LocalDeclarations.resolved.txt index af61d785282..7e62130cb2f 100644 --- a/plugins/uast-kotlin/testData/LocalDeclarations.resolved.txt +++ b/plugins/uast-kotlin/testData/LocalDeclarations.resolved.txt @@ -3,6 +3,6 @@ UTypeReferenceExpression (name = boolean) -> USimpleNameReferenceExpression (ide UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) -> USimpleNameReferenceExpression (identifier = Local) -> KtLightClassForLocalDeclaration:class Local: Local UTypeReferenceExpression (name = int) -> USimpleNameReferenceExpression (identifier = Int) -> PsiClass:Integer: Integer UTypeReferenceExpression (name = java.lang.String) -> USimpleNameReferenceExpression (identifier = String) -> PsiClass:String: String - UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) -> USimpleNameReferenceExpression (identifier = bar) -> null: null + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) -> USimpleNameReferenceExpression (identifier = bar) -> LightVariableBuilder:bar: bar UBinaryExpression (operator = ==) -> USimpleNameReferenceExpression (identifier = ==) -> null: null UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) -> USimpleNameReferenceExpression (identifier = Local) -> KtLightClassForLocalDeclaration:class Local: Local