Uast: resolving references to local function declarations
This commit is contained in:
+5
-4
@@ -59,6 +59,7 @@ import org.jetbrains.kotlin.types.*
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.isInterface
|
import org.jetbrains.kotlin.types.typeUtil.isInterface
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
import org.jetbrains.uast.*
|
import org.jetbrains.uast.*
|
||||||
|
import org.jetbrains.uast.kotlin.expressions.KotlinLocalFunctionUVariable
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
import java.text.StringCharacterIterator
|
import java.text.StringCharacterIterator
|
||||||
|
|
||||||
@@ -250,19 +251,19 @@ internal fun KtClassOrObject.toPsiType(): PsiType {
|
|||||||
|
|
||||||
internal fun PsiElement.getMaybeLightElement(context: UElement): PsiElement? {
|
internal fun PsiElement.getMaybeLightElement(context: UElement): PsiElement? {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is KtVariableDeclaration -> {
|
is KtDeclaration -> {
|
||||||
val lightElement = toLightElements().firstOrNull()
|
val lightElement = toLightElements().firstOrNull()
|
||||||
if (lightElement != null) return lightElement
|
if (lightElement != null) return lightElement
|
||||||
|
|
||||||
val languagePlugin = context.getLanguagePlugin()
|
val languagePlugin = context.getLanguagePlugin()
|
||||||
val uElement = languagePlugin.convertElementWithParent(this, null)
|
val uElement = languagePlugin.convertElementWithParent(this, null)
|
||||||
when (uElement) {
|
when (uElement) {
|
||||||
is UDeclaration -> uElement.psi
|
is UDeclaration -> uElement.javaPsi
|
||||||
is UDeclarationsExpression -> uElement.declarations.firstOrNull()?.psi
|
is UDeclarationsExpression -> uElement.declarations.firstOrNull()?.javaPsi
|
||||||
|
is ULambdaExpression -> (uElement.uastParent as? KotlinLocalFunctionUVariable)?.javaPsi
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is KtDeclaration -> toLightElements().firstOrNull()
|
|
||||||
is KtElement -> null
|
is KtElement -> null
|
||||||
else -> this
|
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
|
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 = int) -> USimpleNameReferenceExpression (identifier = Int) -> PsiClass:Integer: Integer
|
||||||
UTypeReferenceExpression (name = java.lang.String) -> USimpleNameReferenceExpression (identifier = String) -> PsiClass:String: String
|
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
|
UBinaryExpression (operator = ==) -> USimpleNameReferenceExpression (identifier = ==) -> null: null
|
||||||
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) -> USimpleNameReferenceExpression (identifier = Local) -> KtLightClassForLocalDeclaration:class Local: Local
|
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) -> USimpleNameReferenceExpression (identifier = Local) -> KtLightClassForLocalDeclaration:class Local: Local
|
||||||
|
|||||||
Reference in New Issue
Block a user