181: Uast: identifiers fixes for KotlinUFunctionCallExpression and AbstractKotlinUVariable
This commit is contained in:
committed by
Nikolay Krasko
parent
7988fcabcc
commit
f40ea754cb
@@ -75,7 +75,13 @@ open class KotlinUMethod(
|
||||
override val uastAnchor by lazy {
|
||||
KotlinUIdentifier(
|
||||
nameIdentifier,
|
||||
(sourcePsi as? PsiNameIdentifierOwner)?.nameIdentifier ?: sourcePsi?.navigationElement,
|
||||
sourcePsi.let { sourcePsi ->
|
||||
when (sourcePsi) {
|
||||
is PsiNameIdentifierOwner -> sourcePsi.nameIdentifier
|
||||
is KtObjectDeclaration -> sourcePsi.getObjectKeyword()
|
||||
else -> sourcePsi?.navigationElement
|
||||
}
|
||||
},
|
||||
this
|
||||
)
|
||||
}
|
||||
|
||||
+4
-4
@@ -39,8 +39,8 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
abstract class AbstractKotlinUVariable(givenParent: UElement?)
|
||||
: KotlinAbstractUElement(givenParent), PsiVariable, UVariable, KotlinUElementWithComments {
|
||||
abstract class AbstractKotlinUVariable(givenParent: UElement?) : KotlinAbstractUElement(givenParent), PsiVariable, UVariable, UAnchorOwner,
|
||||
KotlinUElementWithComments {
|
||||
|
||||
override val uastInitializer: UExpression?
|
||||
get() {
|
||||
@@ -95,8 +95,8 @@ abstract class AbstractKotlinUVariable(givenParent: UElement?)
|
||||
|
||||
override val typeReference by lz { getLanguagePlugin().convertOpt<UTypeReferenceExpression>(psi.typeElement, this) }
|
||||
|
||||
override val uastAnchor: UElement?
|
||||
get() = KotlinUIdentifier(nameIdentifier, sourcePsi, this)
|
||||
override val uastAnchor: UIdentifier?
|
||||
get() = KotlinUIdentifier(nameIdentifier, (sourcePsi as? KtNamedDeclaration)?.nameIdentifier ?: sourcePsi, this)
|
||||
|
||||
override fun equals(other: Any?) = other is AbstractKotlinUVariable && psi == other.psi
|
||||
|
||||
|
||||
+14
-2
@@ -16,11 +16,13 @@
|
||||
|
||||
package org.jetbrains.uast.kotlin.declarations
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiNameIdentifierOwner
|
||||
import com.intellij.psi.impl.source.tree.LeafPsiElement
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightIdentifier
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.uast.UElement
|
||||
@@ -41,10 +43,20 @@ class KotlinUIdentifier private constructor(
|
||||
) : UIdentifier(psi, givenParent) {
|
||||
|
||||
init {
|
||||
assert(sourcePsi == null || sourcePsi is LeafPsiElement || sourcePsi is KtElement, { "sourcePsi should be physical" })
|
||||
if (ApplicationManager.getApplication().isUnitTestMode)
|
||||
assert(sourcePsi == null || sourcePsi is LeafPsiElement || (sourcePsi is KtElement && sourcePsi.firstChild == null),
|
||||
{ "sourcePsi should be physical leaf element but got $sourcePsi of (${sourcePsi?.javaClass})" })
|
||||
}
|
||||
|
||||
override val uastParent: UElement? by lazy { givenParent ?: sourcePsi?.parent?.toUElement() }
|
||||
override val uastParent: UElement? by lazy {
|
||||
if (givenParent != null) return@lazy givenParent
|
||||
val parent = sourcePsi?.parent ?: return@lazy null
|
||||
val parentParent = parent.parent
|
||||
if (parentParent is KtCallElement && parentParent.calleeExpression == parent) { // method identifiers in calls
|
||||
return@lazy parentParent.toUElement()
|
||||
}
|
||||
return@lazy parent.toUElement()
|
||||
}
|
||||
|
||||
constructor(javaPsi: PsiElement?, sourcePsi: PsiElement?, uastParent: UElement?) : this(javaPsi, sourcePsi, javaPsi, uastParent)
|
||||
constructor(sourcePsi: PsiElement?, uastParent: UElement?) : this(null, sourcePsi, sourcePsi, uastParent)
|
||||
|
||||
+7
-2
@@ -73,8 +73,13 @@ class KotlinUFunctionCallExpression(
|
||||
}
|
||||
|
||||
override val methodIdentifier by lz {
|
||||
val calleeExpression = psi.calleeExpression ?: return@lz null
|
||||
KotlinUIdentifier(calleeExpression, this)
|
||||
val calleeExpression = psi.calleeExpression
|
||||
when (calleeExpression) {
|
||||
null -> null
|
||||
is KtNameReferenceExpression ->
|
||||
KotlinUIdentifier(calleeExpression.getReferencedNameElement(), this /* ReferenceExpression will be the parent */)
|
||||
else -> KotlinUIdentifier(calleeExpression, this)
|
||||
}
|
||||
}
|
||||
|
||||
override val valueArgumentCount: Int
|
||||
|
||||
Reference in New Issue
Block a user