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