Update uast-kotlin to Uast 1.0.8
This commit is contained in:
@@ -174,9 +174,9 @@ internal inline fun <reified T : UElement> Class<out UElement>?.expr(f: () -> UE
|
||||
internal object KotlinConverter {
|
||||
internal fun convertPsiElement(element: PsiElement?, parent: UElement?, requiredType: Class<out UElement>?): UElement? {
|
||||
return with (requiredType) { when (element) {
|
||||
is KtParameterList -> el<UVariableDeclarationsExpression> {
|
||||
KotlinUVariableDeclarationsExpression(parent).apply {
|
||||
variables = element.parameters.mapIndexed { i, p ->
|
||||
is KtParameterList -> el<UDeclarationsExpression> {
|
||||
KotlinUDeclarationsExpression(parent).apply {
|
||||
declarations = element.parameters.mapIndexed { i, p ->
|
||||
KotlinUVariable.create(UastKotlinPsiParameter.create(p, element, parent!!, i), this)
|
||||
}
|
||||
}
|
||||
@@ -200,10 +200,10 @@ internal object KotlinConverter {
|
||||
private fun convertVariablesDeclaration(
|
||||
psi: KtVariableDeclaration,
|
||||
parent: UElement?
|
||||
): UVariableDeclarationsExpression {
|
||||
): UDeclarationsExpression {
|
||||
val parentPsiElement = (parent as? PsiElementBacked)?.psi
|
||||
val variable = KotlinUVariable.create(UastKotlinPsiVariable.create(psi, parentPsiElement, parent!!), parent)
|
||||
return KotlinUVariableDeclarationsExpression(parent).apply { variables = listOf(variable) }
|
||||
return KotlinUDeclarationsExpression(parent).apply { declarations = listOf(variable) }
|
||||
}
|
||||
|
||||
private fun convertStringTemplateExpression(
|
||||
@@ -230,7 +230,7 @@ internal object KotlinConverter {
|
||||
|
||||
internal fun convertExpression(expression: KtExpression, parent: UElement?, requiredType: Class<out UElement>? = null): UExpression {
|
||||
return with (requiredType) { when (expression) {
|
||||
is KtVariableDeclaration -> expr<UVariableDeclarationsExpression> { convertVariablesDeclaration(expression, parent) }
|
||||
is KtVariableDeclaration -> expr<UDeclarationsExpression> { convertVariablesDeclaration(expression, parent) }
|
||||
|
||||
is KtStringTemplateExpression -> expr<ULiteralExpression> {
|
||||
if (expression.entries.isEmpty())
|
||||
@@ -240,8 +240,8 @@ internal object KotlinConverter {
|
||||
else
|
||||
convertStringTemplateExpression(expression, parent, expression.entries.size - 1)
|
||||
}
|
||||
is KtDestructuringDeclaration -> expr<UVariableDeclarationsExpression> {
|
||||
KotlinUVariableDeclarationsExpression(parent).apply {
|
||||
is KtDestructuringDeclaration -> expr<UDeclarationsExpression> {
|
||||
KotlinUDeclarationsExpression(parent).apply {
|
||||
val tempAssignment = KotlinUVariable.create(UastKotlinPsiVariable.create(expression, parent!!), parent)
|
||||
val destructuringAssignments = expression.entries.mapIndexed { i, entry ->
|
||||
val psiFactory = KtPsiFactory(expression.project)
|
||||
@@ -250,7 +250,7 @@ internal object KotlinConverter {
|
||||
KotlinUVariable.create(UastKotlinPsiVariable.create(
|
||||
entry, tempAssignment.psi, parent, initializer), parent)
|
||||
}
|
||||
variables = listOf(tempAssignment) + destructuringAssignments
|
||||
declarations = listOf(tempAssignment) + destructuringAssignments
|
||||
}
|
||||
}
|
||||
is KtLabeledExpression -> expr<ULabeledExpression> { KotlinULabeledExpression(expression, parent) }
|
||||
|
||||
+20
-6
@@ -16,10 +16,12 @@
|
||||
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtImportDirective
|
||||
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UImportStatement
|
||||
import org.jetbrains.uast.USimpleNameReferenceExpression
|
||||
@@ -31,22 +33,34 @@ class KotlinUImportStatement(
|
||||
) : UImportStatement {
|
||||
override val isOnDemand: Boolean
|
||||
get() = psi.isAllUnder
|
||||
|
||||
private val importRef by lz { psi.importedReference?.let { ImportReference(it, psi.name ?: psi.text, this) } }
|
||||
|
||||
private val importRef by lz {
|
||||
psi.importedReference?.let {
|
||||
ImportReference(it, psi.name ?: psi.text, this, psi)
|
||||
}
|
||||
}
|
||||
|
||||
override val importReference: UElement?
|
||||
get() = importRef
|
||||
|
||||
override fun resolve() = importRef?.resolve()
|
||||
|
||||
|
||||
private class ImportReference(
|
||||
override val psi: KtExpression,
|
||||
override val identifier: String,
|
||||
override val containingElement: UElement?
|
||||
override val containingElement: UElement?,
|
||||
private val importDirective: KtImportDirective
|
||||
) : KotlinAbstractUExpression(), USimpleNameReferenceExpression, PsiElementBacked {
|
||||
override val resolvedName: String?
|
||||
get() = identifier
|
||||
|
||||
override fun resolve() = psi.getQualifiedElementSelector()?.mainReference?.resolve()?.getMaybeLightElement(this)
|
||||
override fun asRenderString(): String = importDirective.importedFqName?.asString() ?: psi.text
|
||||
|
||||
override fun resolve(): PsiElement? {
|
||||
val reference = psi.getQualifiedElementSelector() as? KtReferenceExpression ?: return null
|
||||
val bindingContext = reference.analyze()
|
||||
val referenceTarget = bindingContext[BindingContext.REFERENCE_TARGET, reference] ?: return null
|
||||
return referenceTarget.toSource()?.getMaybeLightElement(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -61,9 +61,9 @@ class KotlinUBinaryExpression(
|
||||
KtTokens.EQEQEQ -> UastBinaryOperator.IDENTITY_EQUALS
|
||||
KtTokens.EXCLEQEQEQ -> UastBinaryOperator.IDENTITY_NOT_EQUALS
|
||||
KtTokens.GT -> UastBinaryOperator.GREATER
|
||||
KtTokens.GTEQ -> UastBinaryOperator.GREATER_OR_EQUAL
|
||||
KtTokens.GTEQ -> UastBinaryOperator.GREATER_OR_EQUALS
|
||||
KtTokens.LT -> UastBinaryOperator.LESS
|
||||
KtTokens.LTEQ -> UastBinaryOperator.LESS_OR_EQUAL
|
||||
KtTokens.LTEQ -> UastBinaryOperator.LESS_OR_EQUALS
|
||||
KtTokens.PLUSEQ -> UastBinaryOperator.PLUS_ASSIGN
|
||||
KtTokens.MINUSEQ -> UastBinaryOperator.MINUS_ASSIGN
|
||||
KtTokens.MULTEQ -> UastBinaryOperator.MULTIPLY_ASSIGN
|
||||
|
||||
+1
-3
@@ -16,10 +16,8 @@
|
||||
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext.DOUBLE_COLON_LHS
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.uast.UCallableReferenceExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
@@ -37,7 +35,7 @@ class KotlinUCallableReferenceExpression(
|
||||
}
|
||||
|
||||
override val qualifierType by lz {
|
||||
val ktType = psi.analyze(BodyResolveMode.PARTIAL)[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null
|
||||
val ktType = psi.analyze()[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null
|
||||
ktType.toPsiType(this, psi, boxed = true)
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -16,10 +16,8 @@
|
||||
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.psi.KtClassLiteralExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext.DOUBLE_COLON_LHS
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.uast.UClassLiteralExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
@@ -30,7 +28,7 @@ class KotlinUClassLiteralExpression(
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UClassLiteralExpression, PsiElementBacked, KotlinUElementWithType {
|
||||
override val type by lz {
|
||||
val ktType = psi.analyze(BodyResolveMode.PARTIAL)[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null
|
||||
val ktType = psi.analyze()[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null
|
||||
ktType.toPsiType(this, psi, boxed = true)
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -17,9 +17,9 @@ package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.kotlin.KotlinAbstractUExpression
|
||||
|
||||
class KotlinUVariableDeclarationsExpression(
|
||||
class KotlinUDeclarationsExpression(
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UVariableDeclarationsExpression {
|
||||
override lateinit var variables: List<UVariable>
|
||||
) : KotlinAbstractUExpression(), UDeclarationsExpression {
|
||||
override lateinit var declarations: List<UDeclaration>
|
||||
internal set
|
||||
}
|
||||
+2
-2
@@ -27,7 +27,7 @@ class KotlinUSwitchExpression(
|
||||
) : KotlinAbstractUExpression(), USwitchExpression, PsiElementBacked, KotlinUElementWithType {
|
||||
override val expression by lz { KotlinConverter.convertOrNull(psi.subjectExpression, this) }
|
||||
|
||||
override val body: UExpression by lz {
|
||||
override val body: UExpressionList by lz {
|
||||
object : KotlinUExpressionList(psi, KotlinSpecialExpressionKinds.WHEN, this) {
|
||||
override fun asRenderString() = expressions.joinToString("\n") { it.asRenderString().withMargin }
|
||||
}.apply {
|
||||
@@ -76,7 +76,7 @@ class KotlinUSwitchEntry(
|
||||
}}
|
||||
}
|
||||
|
||||
override val body: UExpression by lz {
|
||||
override val body: UExpressionList by lz {
|
||||
object : KotlinUExpressionList(psi, KotlinSpecialExpressionKinds.WHEN_ENTRY, this) {
|
||||
override fun asRenderString() = buildString {
|
||||
appendln("{")
|
||||
|
||||
+1
-1
@@ -136,7 +136,7 @@ internal fun PsiElement.getMaybeLightElement(context: UElement): PsiElement? {
|
||||
val uElement = languagePlugin.convertElementWithParent(this, null)
|
||||
when (uElement) {
|
||||
is UDeclaration -> uElement.psi
|
||||
is UVariableDeclarationsExpression -> uElement.variables.firstOrNull()?.psi
|
||||
is UDeclarationsExpression -> uElement.declarations.firstOrNull()?.psi
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user