Uast: resolving references to local function declarations

This commit is contained in:
Nicolay Mitropolsky
2019-02-26 20:50:23 +03:00
parent 72860fb695
commit 337f16194a
2 changed files with 6 additions and 5 deletions
@@ -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
}
@@ -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