Uast: cleaunp warnings (but some still remains)

This commit is contained in:
Nicolay Mitropolsky
2019-04-23 10:46:53 +03:00
parent 13b332e99e
commit 0794ab9432
61 changed files with 378 additions and 344 deletions
@@ -40,7 +40,8 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : Kotl
} }
protected open fun convertParent(): UElement? { protected open fun convertParent(): UElement? {
val psi = psi @Suppress("DEPRECATION")
val psi = psi //TODO: `psi` is deprecated but it seems that it couldn't be simply replaced for this case
var parent = psi?.parent ?: psi?.containingFile var parent = psi?.parent ?: psi?.containingFile
if (psi is KtLightClassForLocalDeclaration) { if (psi is KtLightClassForLocalDeclaration) {
@@ -221,12 +222,12 @@ abstract class KotlinAbstractUExpression(givenParent: UElement?) :
override val javaPsi: PsiElement? = null override val javaPsi: PsiElement? = null
override val sourcePsi override val psi
get() = psi get() = sourcePsi
override val annotations: List<UAnnotation> override val annotations: List<UAnnotation>
get() { get() {
val annotatedExpression = psi?.parent as? KtAnnotatedExpression ?: return emptyList() val annotatedExpression = sourcePsi?.parent as? KtAnnotatedExpression ?: return emptyList()
return annotatedExpression.annotationEntries.map { KotlinUAnnotation(it, this) } return annotatedExpression.annotationEntries.map { KotlinUAnnotation(it, this) }
} }
} }
@@ -40,7 +40,8 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : Kotl
} }
protected open fun convertParent(): UElement? { protected open fun convertParent(): UElement? {
val psi = psi @Suppress("DEPRECATION")
val psi = psi //TODO: `psi` is deprecated but it seems that it couldn't be simply replaced for this case
var parent = psi?.parent ?: psi?.containingFile var parent = psi?.parent ?: psi?.containingFile
if (psi is KtLightClassForLocalDeclaration) { if (psi is KtLightClassForLocalDeclaration) {
@@ -110,7 +111,7 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : Kotl
val result = doConvertParent(this, parent) val result = doConvertParent(this, parent)
if (result == this) { if (result == this) {
throw IllegalStateException("Loop in parent structure when converting a $psi of type ${psi?.javaClass} with parent $parent of type ${parent?.javaClass} text: [${parent?.text}]") throw IllegalStateException("Loop in parent structure when converting a $psi of type ${psi?.javaClass} with parent $parent of type ${parent?.javaClass} text: [${parent?.text}], result = $result")
} }
return result return result
@@ -217,12 +218,12 @@ abstract class KotlinAbstractUExpression(givenParent: UElement?) :
override val javaPsi: PsiElement? = null override val javaPsi: PsiElement? = null
override val sourcePsi override val psi
get() = psi get() = sourcePsi
override val annotations: List<UAnnotation> override val annotations: List<UAnnotation>
get() { get() {
val annotatedExpression = psi?.parent as? KtAnnotatedExpression ?: return emptyList() val annotatedExpression = sourcePsi?.parent as? KtAnnotatedExpression ?: return emptyList()
return annotatedExpression.annotationEntries.map { KotlinUAnnotation(it, this) } return annotatedExpression.annotationEntries.map { KotlinUAnnotation(it, this) }
} }
} }
@@ -134,7 +134,7 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin {
return when (element) { return when (element) {
is KotlinUSimpleReferenceExpression.KotlinAccessorCallExpression -> element.setterValue != null is KotlinUSimpleReferenceExpression.KotlinAccessorCallExpression -> element.setterValue != null
is KotlinAbstractUExpression -> { is KotlinAbstractUExpression -> {
val ktElement = element.psi as? KtElement ?: return false val ktElement = element.sourcePsi as? KtElement ?: return false
ktElement.analyze()[BindingContext.USED_AS_EXPRESSION, ktElement] ?: false ktElement.analyze()[BindingContext.USED_AS_EXPRESSION, ktElement] ?: false
} }
else -> false else -> false
@@ -239,7 +239,7 @@ internal object KotlinConverter {
} }
} }
is KtLiteralStringTemplateEntry, is KtEscapeStringTemplateEntry -> el<ULiteralExpression>(build(::KotlinStringULiteralExpression)) is KtLiteralStringTemplateEntry, is KtEscapeStringTemplateEntry -> el<ULiteralExpression>(build(::KotlinStringULiteralExpression))
is KtStringTemplateEntry -> element.expression?.let { convertExpression(it, givenParent, expectedTypes) } ?: expr<UExpression> { UastEmptyExpression(null) } is KtStringTemplateEntry -> element.expression?.let { convertExpression(it, givenParent, expectedTypes) } ?: expr<UExpression> { UastEmptyExpression(givenParent) }
is KtWhenEntry -> el<USwitchClauseExpressionWithBody>(build(::KotlinUSwitchEntry)) is KtWhenEntry -> el<USwitchClauseExpressionWithBody>(build(::KotlinUSwitchEntry))
is KtWhenCondition -> convertWhenCondition(element, givenParent, expectedTypes) is KtWhenCondition -> convertWhenCondition(element, givenParent, expectedTypes)
is KtTypeReference -> el<UTypeReferenceExpression> { LazyKotlinUTypeReferenceExpression(element, givenParent) } is KtTypeReference -> el<UTypeReferenceExpression> { LazyKotlinUTypeReferenceExpression(element, givenParent) }
@@ -341,7 +341,7 @@ internal object KotlinConverter {
val initializer = psiFactory.createAnalyzableExpression("${tempAssignment.name}.component${i + 1}()", val initializer = psiFactory.createAnalyzableExpression("${tempAssignment.name}.component${i + 1}()",
expression.containingFile) expression.containingFile)
initializer.destructuringDeclarationInitializer = true initializer.destructuringDeclarationInitializer = true
KotlinULocalVariable(UastKotlinPsiVariable.create(entry, tempAssignment.psi, declarationsExpression, initializer), entry, declarationsExpression) KotlinULocalVariable(UastKotlinPsiVariable.create(entry, tempAssignment.javaPsi, declarationsExpression, initializer), entry, declarationsExpression)
} }
declarations = listOf(tempAssignment) + destructuringAssignments declarations = listOf(tempAssignment) + destructuringAssignments
} }
@@ -387,7 +387,7 @@ internal object KotlinConverter {
KotlinUDeclarationsExpression(givenParent).apply { KotlinUDeclarationsExpression(givenParent).apply {
declarations = listOf(KotlinUClass.create(lightClass, this)) declarations = listOf(KotlinUClass.create(lightClass, this))
} }
} ?: UastEmptyExpression(null) } ?: UastEmptyExpression(givenParent)
} }
is KtFunction -> if (expression.name.isNullOrEmpty()) { is KtFunction -> if (expression.name.isNullOrEmpty()) {
expr<ULambdaExpression>(build(::createLocalFunctionLambdaExpression)) expr<ULambdaExpression>(build(::createLocalFunctionLambdaExpression))
@@ -433,7 +433,7 @@ internal object KotlinConverter {
is KtWhenConditionWithExpression -> is KtWhenConditionWithExpression ->
condition.expression?.let { KotlinConverter.convertExpression(it, givenParent, requiredType) } condition.expression?.let { KotlinConverter.convertExpression(it, givenParent, requiredType) }
else -> expr<UExpression> { UastEmptyExpression(null) } else -> expr<UExpression> { UastEmptyExpression(givenParent) }
} }
} }
} }
@@ -627,7 +627,7 @@ internal object KotlinConverter {
internal fun convertOrEmpty(expression: KtExpression?, parent: UElement?): UExpression { internal fun convertOrEmpty(expression: KtExpression?, parent: UElement?): UExpression {
return expression?.let { convertExpression(it, parent, DEFAULT_EXPRESSION_TYPES_LIST) } ?: UastEmptyExpression(null) return expression?.let { convertExpression(it, parent, DEFAULT_EXPRESSION_TYPES_LIST) } ?: UastEmptyExpression(parent)
} }
internal fun convertOrNull(expression: KtExpression?, parent: UElement?): UExpression? { internal fun convertOrNull(expression: KtExpression?, parent: UElement?): UExpression? {
@@ -656,7 +656,7 @@ private fun convertVariablesDeclaration(
val declarationsExpression = parent as? KotlinUDeclarationsExpression val declarationsExpression = parent as? KotlinUDeclarationsExpression
?: psi.parent.toUElementOfType<UDeclarationsExpression>() as? KotlinUDeclarationsExpression ?: psi.parent.toUElementOfType<UDeclarationsExpression>() as? KotlinUDeclarationsExpression
?: KotlinUDeclarationsExpression(null, parent, psi) ?: KotlinUDeclarationsExpression(null, parent, psi)
val parentPsiElement = parent?.psi val parentPsiElement = parent?.javaPsi //TODO: looks weird. mb look for the first non-null `javaPsi` in `parents` ?
val variable = KotlinUAnnotatedLocalVariable( val variable = KotlinUAnnotatedLocalVariable(
UastKotlinPsiVariable.create(psi, parentPsiElement, declarationsExpression), psi, declarationsExpression) { annotationParent -> UastKotlinPsiVariable.create(psi, parentPsiElement, declarationsExpression), psi, declarationsExpression) { annotationParent ->
psi.annotationEntries.map { KotlinUAnnotation(it, annotationParent) } psi.annotationEntries.map { KotlinUAnnotation(it, annotationParent) }
@@ -128,7 +128,7 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin {
return when (element) { return when (element) {
is KotlinUSimpleReferenceExpression.KotlinAccessorCallExpression -> element.setterValue != null is KotlinUSimpleReferenceExpression.KotlinAccessorCallExpression -> element.setterValue != null
is KotlinAbstractUExpression -> { is KotlinAbstractUExpression -> {
val ktElement = element.psi as? KtElement ?: return false val ktElement = element.sourcePsi as? KtElement ?: return false
ktElement.analyze()[BindingContext.USED_AS_EXPRESSION, ktElement] ?: false ktElement.analyze()[BindingContext.USED_AS_EXPRESSION, ktElement] ?: false
} }
else -> false else -> false
@@ -166,7 +166,10 @@ internal object KotlinConverter {
givenParent: UElement?, givenParent: UElement?,
requiredType: Class<out UElement>?): UElement? { requiredType: Class<out UElement>?): UElement? {
fun <P : PsiElement> build(ctor: (P, UElement?) -> UElement): () -> UElement? { fun <P : PsiElement> build(ctor: (P, UElement?) -> UElement): () -> UElement? {
return { ctor(element as P, givenParent) } return {
@Suppress("UNCHECKED_CAST")
ctor(element as P, givenParent)
}
} }
return with (requiredType) { when (element) { return with (requiredType) { when (element) {
@@ -266,7 +269,10 @@ internal object KotlinConverter {
givenParent: UElement?, givenParent: UElement?,
requiredType: Class<out UElement>? = null): UExpression? { requiredType: Class<out UElement>? = null): UExpression? {
fun <P : PsiElement> build(ctor: (P, UElement?) -> UExpression): () -> UExpression? { fun <P : PsiElement> build(ctor: (P, UElement?) -> UExpression): () -> UExpression? {
return { ctor(expression as P, givenParent) } return {
@Suppress("UNCHECKED_CAST")
ctor(expression as P, givenParent)
}
} }
return with (requiredType) { when (expression) { return with (requiredType) { when (expression) {
@@ -292,7 +298,7 @@ internal object KotlinConverter {
val initializer = psiFactory.createAnalyzableExpression("${tempAssignment.name}.component${i + 1}()", val initializer = psiFactory.createAnalyzableExpression("${tempAssignment.name}.component${i + 1}()",
expression.containingFile) expression.containingFile)
initializer.destructuringDeclarationInitializer = true initializer.destructuringDeclarationInitializer = true
KotlinULocalVariable(UastKotlinPsiVariable.create(entry, tempAssignment.psi, declarationsExpression, initializer), entry, declarationsExpression) KotlinULocalVariable(UastKotlinPsiVariable.create(entry, tempAssignment.javaPsi, declarationsExpression, initializer), entry, declarationsExpression)
} }
declarations = listOf(tempAssignment) + destructuringAssignments declarations = listOf(tempAssignment) + destructuringAssignments
} }
@@ -338,7 +344,7 @@ internal object KotlinConverter {
KotlinUDeclarationsExpression(givenParent).apply { KotlinUDeclarationsExpression(givenParent).apply {
declarations = listOf(KotlinUClass.create(lightClass, this)) declarations = listOf(KotlinUClass.create(lightClass, this))
} }
} ?: UastEmptyExpression } ?: UastEmptyExpression(givenParent)
} }
is KtFunction -> if (expression.name.isNullOrEmpty()) { is KtFunction -> if (expression.name.isNullOrEmpty()) {
expr<ULambdaExpression>(build(::createLocalFunctionLambdaExpression)) expr<ULambdaExpression>(build(::createLocalFunctionLambdaExpression))
@@ -384,7 +390,7 @@ internal object KotlinConverter {
is KtWhenConditionWithExpression -> is KtWhenConditionWithExpression ->
condition.expression?.let { KotlinConverter.convertExpression(it, givenParent, requiredType) } condition.expression?.let { KotlinConverter.convertExpression(it, givenParent, requiredType) }
else -> expr<UExpression> { UastEmptyExpression } else -> expr<UExpression> { UastEmptyExpression(givenParent) }
} }
} }
} }
@@ -405,13 +411,20 @@ internal object KotlinConverter {
givenParent: UElement?, givenParent: UElement?,
requiredType: Class<out UElement>? requiredType: Class<out UElement>?
): UElement? { ): UElement? {
fun <P : PsiElement> build(ctor: (P, UElement?) -> UElement): () -> UElement? = { ctor(element as P, givenParent) } fun <P : PsiElement> build(ctor: (P, UElement?) -> UElement): () -> UElement? = {
@Suppress("UNCHECKED_CAST")
ctor(element as P, givenParent)
}
fun <P : PsiElement, K : KtElement> buildKt(ktElement: K, ctor: (P, K, UElement?) -> UElement): () -> UElement? = fun <P : PsiElement, K : KtElement> buildKt(ktElement: K, ctor: (P, K, UElement?) -> UElement): () -> UElement? = {
{ ctor(element as P, ktElement, givenParent) } @Suppress("UNCHECKED_CAST")
ctor(element as P, ktElement, givenParent)
}
fun <P : PsiElement, K : KtElement> buildKtOpt(ktElement: K?, ctor: (P, K?, UElement?) -> UElement): () -> UElement? = fun <P : PsiElement, K : KtElement> buildKtOpt(ktElement: K?, ctor: (P, K?, UElement?) -> UElement): () -> UElement? = {
{ ctor(element as P, ktElement, givenParent) } @Suppress("UNCHECKED_CAST")
ctor(element as P, ktElement, givenParent)
}
val original = element.originalElement val original = element.originalElement
return with(requiredType) { return with(requiredType) {
@@ -552,6 +565,7 @@ internal object KotlinConverter {
val file = createAnalyzableFile("dummy.kt", text, context) val file = createAnalyzableFile("dummy.kt", text, context)
val declarations = file.declarations val declarations = file.declarations
assert(declarations.size == 1) { "${declarations.size} declarations in $text" } assert(declarations.size == 1) { "${declarations.size} declarations in $text" }
@Suppress("UNCHECKED_CAST")
return declarations.first() as TDeclaration return declarations.first() as TDeclaration
} }
} }
@@ -563,7 +577,7 @@ private fun convertVariablesDeclaration(
val declarationsExpression = parent as? KotlinUDeclarationsExpression val declarationsExpression = parent as? KotlinUDeclarationsExpression
?: psi.parent.toUElementOfType<UDeclarationsExpression>() as? KotlinUDeclarationsExpression ?: psi.parent.toUElementOfType<UDeclarationsExpression>() as? KotlinUDeclarationsExpression
?: KotlinUDeclarationsExpression(null, parent, psi) ?: KotlinUDeclarationsExpression(null, parent, psi)
val parentPsiElement = parent?.psi val parentPsiElement = parent?.javaPsi //TODO: looks weird. mb look for the first non-null `javaPsi` in `parents` ?
val variable = KotlinUAnnotatedLocalVariable( val variable = KotlinUAnnotatedLocalVariable(
UastKotlinPsiVariable.create(psi, parentPsiElement, declarationsExpression), psi, declarationsExpression) { annotationParent -> UastKotlinPsiVariable.create(psi, parentPsiElement, declarationsExpression), psi, declarationsExpression) { annotationParent ->
psi.annotationEntries.map { KotlinUAnnotation(it, annotationParent) } psi.annotationEntries.map { KotlinUAnnotation(it, annotationParent) }
@@ -130,7 +130,7 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin {
return when (element) { return when (element) {
is KotlinUSimpleReferenceExpression.KotlinAccessorCallExpression -> element.setterValue != null is KotlinUSimpleReferenceExpression.KotlinAccessorCallExpression -> element.setterValue != null
is KotlinAbstractUExpression -> { is KotlinAbstractUExpression -> {
val ktElement = element.psi as? KtElement ?: return false val ktElement = element.sourcePsi as? KtElement ?: return false
ktElement.analyze()[BindingContext.USED_AS_EXPRESSION, ktElement] ?: false ktElement.analyze()[BindingContext.USED_AS_EXPRESSION, ktElement] ?: false
} }
else -> false else -> false
@@ -168,7 +168,10 @@ internal object KotlinConverter {
givenParent: UElement?, givenParent: UElement?,
requiredType: Class<out UElement>?): UElement? { requiredType: Class<out UElement>?): UElement? {
fun <P : PsiElement> build(ctor: (P, UElement?) -> UElement): () -> UElement? { fun <P : PsiElement> build(ctor: (P, UElement?) -> UElement): () -> UElement? {
return { ctor(element as P, givenParent) } return {
@Suppress("UNCHECKED_CAST")
ctor(element as P, givenParent)
}
} }
return with (requiredType) { when (element) { return with (requiredType) { when (element) {
@@ -268,7 +271,10 @@ internal object KotlinConverter {
givenParent: UElement?, givenParent: UElement?,
requiredType: Class<out UElement>? = null): UExpression? { requiredType: Class<out UElement>? = null): UExpression? {
fun <P : PsiElement> build(ctor: (P, UElement?) -> UExpression): () -> UExpression? { fun <P : PsiElement> build(ctor: (P, UElement?) -> UExpression): () -> UExpression? {
return { ctor(expression as P, givenParent) } return {
@Suppress("UNCHECKED_CAST")
ctor(expression as P, givenParent)
}
} }
return with (requiredType) { when (expression) { return with (requiredType) { when (expression) {
@@ -294,7 +300,7 @@ internal object KotlinConverter {
val initializer = psiFactory.createAnalyzableExpression("${tempAssignment.name}.component${i + 1}()", val initializer = psiFactory.createAnalyzableExpression("${tempAssignment.name}.component${i + 1}()",
expression.containingFile) expression.containingFile)
initializer.destructuringDeclarationInitializer = true initializer.destructuringDeclarationInitializer = true
KotlinULocalVariable(UastKotlinPsiVariable.create(entry, tempAssignment.psi, declarationsExpression, initializer), entry, declarationsExpression) KotlinULocalVariable(UastKotlinPsiVariable.create(entry, tempAssignment.javaPsi, declarationsExpression, initializer), entry, declarationsExpression)
} }
declarations = listOf(tempAssignment) + destructuringAssignments declarations = listOf(tempAssignment) + destructuringAssignments
} }
@@ -340,7 +346,7 @@ internal object KotlinConverter {
KotlinUDeclarationsExpression(givenParent).apply { KotlinUDeclarationsExpression(givenParent).apply {
declarations = listOf(KotlinUClass.create(lightClass, this)) declarations = listOf(KotlinUClass.create(lightClass, this))
} }
} ?: UastEmptyExpression } ?: UastEmptyExpression(givenParent)
} }
is KtFunction -> if (expression.name.isNullOrEmpty()) { is KtFunction -> if (expression.name.isNullOrEmpty()) {
expr<ULambdaExpression>(build(::createLocalFunctionLambdaExpression)) expr<ULambdaExpression>(build(::createLocalFunctionLambdaExpression))
@@ -386,7 +392,7 @@ internal object KotlinConverter {
is KtWhenConditionWithExpression -> is KtWhenConditionWithExpression ->
condition.expression?.let { KotlinConverter.convertExpression(it, givenParent, requiredType) } condition.expression?.let { KotlinConverter.convertExpression(it, givenParent, requiredType) }
else -> expr<UExpression> { UastEmptyExpression } else -> expr<UExpression> { UastEmptyExpression(givenParent) }
} }
} }
} }
@@ -407,13 +413,20 @@ internal object KotlinConverter {
givenParent: UElement?, givenParent: UElement?,
requiredType: Class<out UElement>? requiredType: Class<out UElement>?
): UElement? { ): UElement? {
fun <P : PsiElement> build(ctor: (P, UElement?) -> UElement): () -> UElement? = { ctor(element as P, givenParent) } fun <P : PsiElement> build(ctor: (P, UElement?) -> UElement): () -> UElement? = {
@Suppress("UNCHECKED_CAST")
ctor(element as P, givenParent)
}
fun <P : PsiElement, K : KtElement> buildKt(ktElement: K, ctor: (P, K, UElement?) -> UElement): () -> UElement? = fun <P : PsiElement, K : KtElement> buildKt(ktElement: K, ctor: (P, K, UElement?) -> UElement): () -> UElement? = {
{ ctor(element as P, ktElement, givenParent) } @Suppress("UNCHECKED_CAST")
ctor(element as P, ktElement, givenParent)
}
fun <P : PsiElement, K : KtElement> buildKtOpt(ktElement: K?, ctor: (P, K?, UElement?) -> UElement): () -> UElement? = fun <P : PsiElement, K : KtElement> buildKtOpt(ktElement: K?, ctor: (P, K?, UElement?) -> UElement): () -> UElement? = {
{ ctor(element as P, ktElement, givenParent) } @Suppress("UNCHECKED_CAST")
ctor(element as P, ktElement, givenParent)
}
val original = element.originalElement val original = element.originalElement
return with(requiredType) { return with(requiredType) {
@@ -554,6 +567,7 @@ internal object KotlinConverter {
val file = createAnalyzableFile("dummy.kt", text, context) val file = createAnalyzableFile("dummy.kt", text, context)
val declarations = file.declarations val declarations = file.declarations
assert(declarations.size == 1) { "${declarations.size} declarations in $text" } assert(declarations.size == 1) { "${declarations.size} declarations in $text" }
@Suppress("UNCHECKED_CAST")
return declarations.first() as TDeclaration return declarations.first() as TDeclaration
} }
} }
@@ -565,7 +579,7 @@ private fun convertVariablesDeclaration(
val declarationsExpression = parent as? KotlinUDeclarationsExpression val declarationsExpression = parent as? KotlinUDeclarationsExpression
?: psi.parent.toUElementOfType<UDeclarationsExpression>() as? KotlinUDeclarationsExpression ?: psi.parent.toUElementOfType<UDeclarationsExpression>() as? KotlinUDeclarationsExpression
?: KotlinUDeclarationsExpression(null, parent, psi) ?: KotlinUDeclarationsExpression(null, parent, psi)
val parentPsiElement = parent?.psi val parentPsiElement = parent?.javaPsi //TODO: looks weird. mb look for the first non-null `javaPsi` in `parents` ?
val variable = KotlinUAnnotatedLocalVariable( val variable = KotlinUAnnotatedLocalVariable(
UastKotlinPsiVariable.create(psi, parentPsiElement, declarationsExpression), psi, declarationsExpression) { annotationParent -> UastKotlinPsiVariable.create(psi, parentPsiElement, declarationsExpression), psi, declarationsExpression) { annotationParent ->
psi.annotationEntries.map { KotlinUAnnotation(it, annotationParent) } psi.annotationEntries.map { KotlinUAnnotation(it, annotationParent) }
@@ -78,8 +78,8 @@ private fun createElvisExpressions(
} }
fun createElvisExpression(elvisExpression: KtBinaryExpression, givenParent: UElement?): UExpression { fun createElvisExpression(elvisExpression: KtBinaryExpression, givenParent: UElement?): UExpression {
val left = elvisExpression.left ?: return UastEmptyExpression(null) val left = elvisExpression.left ?: return UastEmptyExpression(givenParent)
val right = elvisExpression.right ?: return UastEmptyExpression(null) val right = elvisExpression.right ?: return UastEmptyExpression(givenParent)
return KotlinUElvisExpression(elvisExpression, left, right, givenParent) return KotlinUElvisExpression(elvisExpression, left, right, givenParent)
} }
@@ -78,8 +78,8 @@ private fun createElvisExpressions(
} }
fun createElvisExpression(elvisExpression: KtBinaryExpression, givenParent: UElement?): UExpression { fun createElvisExpression(elvisExpression: KtBinaryExpression, givenParent: UElement?): UExpression {
val left = elvisExpression.left ?: return UastEmptyExpression val left = elvisExpression.left ?: return UastEmptyExpression(givenParent)
val right = elvisExpression.right ?: return UastEmptyExpression val right = elvisExpression.right ?: return UastEmptyExpression(givenParent)
return KotlinUElvisExpression(elvisExpression, left, right, givenParent) return KotlinUElvisExpression(elvisExpression, left, right, givenParent)
} }
@@ -22,7 +22,7 @@ import org.jetbrains.uast.*
import org.jetbrains.uast.expressions.UInjectionHost import org.jetbrains.uast.expressions.UInjectionHost
class KotlinStringTemplateUPolyadicExpression( class KotlinStringTemplateUPolyadicExpression(
override val psi: KtStringTemplateExpression, override val sourcePsi: KtStringTemplateExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), ) : KotlinAbstractUExpression(givenParent),
UPolyadicExpression, UPolyadicExpression,
@@ -30,7 +30,7 @@ class KotlinStringTemplateUPolyadicExpression(
KotlinEvaluatableUElement, KotlinEvaluatableUElement,
UInjectionHost { UInjectionHost {
override val operands: List<UExpression> by lz { override val operands: List<UExpression> by lz {
psi.entries.map { sourcePsi.entries.map {
KotlinConverter.convertEntry( KotlinConverter.convertEntry(
it, it,
this, this,
@@ -40,7 +40,7 @@ class KotlinStringTemplateUPolyadicExpression(
} }
override val operator = UastBinaryOperator.PLUS override val operator = UastBinaryOperator.PLUS
override val psiLanguageInjectionHost: PsiLanguageInjectionHost get() = psi override val psiLanguageInjectionHost: PsiLanguageInjectionHost get() = sourcePsi
override val isString: Boolean get() = true override val isString: Boolean get() = true
override fun asRenderString(): String = if (operands.isEmpty()) "\"\"" else super<UPolyadicExpression>.asRenderString() override fun asRenderString(): String = if (operands.isEmpty()) "\"\"" else super<UPolyadicExpression>.asRenderString()
@@ -23,12 +23,12 @@ import org.jetbrains.uast.UPolyadicExpression
import org.jetbrains.uast.UastBinaryOperator import org.jetbrains.uast.UastBinaryOperator
class KotlinStringTemplateUPolyadicExpression( class KotlinStringTemplateUPolyadicExpression(
override val psi: KtStringTemplateExpression, override val sourcePsi: KtStringTemplateExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), ) : KotlinAbstractUExpression(givenParent),
UPolyadicExpression, UPolyadicExpression,
KotlinUElementWithType, KotlinUElementWithType,
KotlinEvaluatableUElement { KotlinEvaluatableUElement {
override val operands: List<UExpression> by lz { psi.entries.map { KotlinConverter.convertEntry(it, this)!! } } override val operands: List<UExpression> by lz { sourcePsi.entries.map { KotlinConverter.convertEntry(it, this)!! } }
override val operator = UastBinaryOperator.PLUS override val operator = UastBinaryOperator.PLUS
} }
@@ -21,9 +21,9 @@ import org.jetbrains.uast.UArrayAccessExpression
import org.jetbrains.uast.UElement import org.jetbrains.uast.UElement
class KotlinUArrayAccessExpression( class KotlinUArrayAccessExpression(
override val psi: KtArrayAccessExpression, override val sourcePsi: KtArrayAccessExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UArrayAccessExpression, KotlinUElementWithType, KotlinEvaluatableUElement { ) : KotlinAbstractUExpression(givenParent), UArrayAccessExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.arrayExpression, this) } override val receiver by lz { KotlinConverter.convertOrEmpty(sourcePsi.arrayExpression, this) }
override val indices by lz { psi.indexExpressions.map { KotlinConverter.convertOrEmpty(it, this) } } override val indices by lz { sourcePsi.indexExpressions.map { KotlinConverter.convertOrEmpty(it, this) } }
} }
@@ -28,7 +28,7 @@ import org.jetbrains.uast.*
import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
class KotlinUBinaryExpression( class KotlinUBinaryExpression(
override val psi: KtBinaryExpression, override val sourcePsi: KtBinaryExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UBinaryExpression, KotlinUElementWithType, KotlinEvaluatableUElement { ) : KotlinAbstractUExpression(givenParent), UBinaryExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
private companion object { private companion object {
@@ -39,15 +39,15 @@ class KotlinUBinaryExpression(
) )
} }
override val leftOperand by lz { KotlinConverter.convertOrEmpty(psi.left, this) } override val leftOperand by lz { KotlinConverter.convertOrEmpty(sourcePsi.left, this) }
override val rightOperand by lz { KotlinConverter.convertOrEmpty(psi.right, this) } override val rightOperand by lz { KotlinConverter.convertOrEmpty(sourcePsi.right, this) }
override val operatorIdentifier: UIdentifier? override val operatorIdentifier: UIdentifier?
get() = KotlinUIdentifier(psi.operationReference.getReferencedNameElement(), this) get() = KotlinUIdentifier(sourcePsi.operationReference.getReferencedNameElement(), this)
override fun resolveOperator() = psi.operationReference.resolveCallToDeclaration() as? PsiMethod override fun resolveOperator() = sourcePsi.operationReference.resolveCallToDeclaration() as? PsiMethod
override val operator = when (psi.operationToken) { override val operator = when (sourcePsi.operationToken) {
KtTokens.EQ -> UastBinaryOperator.ASSIGN KtTokens.EQ -> UastBinaryOperator.ASSIGN
KtTokens.PLUS -> UastBinaryOperator.PLUS KtTokens.PLUS -> UastBinaryOperator.PLUS
KtTokens.MINUS -> UastBinaryOperator.MINUS KtTokens.MINUS -> UastBinaryOperator.MINUS
@@ -74,8 +74,8 @@ class KotlinUBinaryExpression(
KtTokens.RANGE -> KotlinBinaryOperators.RANGE_TO KtTokens.RANGE -> KotlinBinaryOperators.RANGE_TO
else -> run { // Handle bitwise operators else -> run { // Handle bitwise operators
val other = UastBinaryOperator.OTHER val other = UastBinaryOperator.OTHER
val ref = psi.operationReference val ref = sourcePsi.operationReference
val resolvedCall = psi.operationReference.getResolvedCall(ref.analyze()) ?: return@run other val resolvedCall = sourcePsi.operationReference.getResolvedCall(ref.analyze()) ?: return@run other
val resultingDescriptor = resolvedCall.resultingDescriptor as? FunctionDescriptor ?: return@run other val resultingDescriptor = resolvedCall.resultingDescriptor as? FunctionDescriptor ?: return@run other
val applicableOperator = BITWISE_OPERATORS[resultingDescriptor.name.asString()] ?: return@run other val applicableOperator = BITWISE_OPERATORS[resultingDescriptor.name.asString()] ?: return@run other
@@ -23,19 +23,19 @@ import org.jetbrains.kotlin.psi.KtBinaryExpressionWithTypeRHS
import org.jetbrains.uast.* import org.jetbrains.uast.*
class KotlinUBinaryExpressionWithType( class KotlinUBinaryExpressionWithType(
override val psi: KtBinaryExpressionWithTypeRHS, override val sourcePsi: KtBinaryExpressionWithTypeRHS,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UBinaryExpressionWithType, ) : KotlinAbstractUExpression(givenParent), UBinaryExpressionWithType,
KotlinUElementWithType, KotlinEvaluatableUElement { KotlinUElementWithType, KotlinEvaluatableUElement {
override val operand by lz { KotlinConverter.convertOrEmpty(psi.left, this) } override val operand by lz { KotlinConverter.convertOrEmpty(sourcePsi.left, this) }
override val type by lz { psi.right.toPsiType(this) } override val type by lz { sourcePsi.right.toPsiType(this) }
override val typeReference by lz { override val typeReference by lz {
psi.right?.let { LazyKotlinUTypeReferenceExpression(it, this) } sourcePsi.right?.let { LazyKotlinUTypeReferenceExpression(it, this) }
} }
override val operationKind = when (psi.operationReference.getReferencedNameElementType()) { override val operationKind = when (sourcePsi.operationReference.getReferencedNameElementType()) {
KtTokens.AS_KEYWORD -> UastBinaryExpressionWithTypeKind.TYPE_CAST KtTokens.AS_KEYWORD -> UastBinaryExpressionWithTypeKind.TYPE_CAST
KtTokens.AS_SAFE -> KotlinBinaryExpressionWithTypeKinds.SAFE_TYPE_CAST KtTokens.AS_SAFE -> KotlinBinaryExpressionWithTypeKinds.SAFE_TYPE_CAST
else -> UastBinaryExpressionWithTypeKind.UNKNOWN else -> UastBinaryExpressionWithTypeKind.UNKNOWN
@@ -22,18 +22,18 @@ import org.jetbrains.kotlin.psi.KtBlockExpression
import org.jetbrains.uast.* import org.jetbrains.uast.*
class KotlinUBlockExpression( class KotlinUBlockExpression(
override val psi: KtBlockExpression, override val sourcePsi: KtBlockExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UBlockExpression, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), UBlockExpression, KotlinUElementWithType {
override val expressions by lz { psi.statements.map { KotlinConverter.convertOrEmpty(it, this) } } override val expressions by lz { sourcePsi.statements.map { KotlinConverter.convertOrEmpty(it, this) } }
class KotlinLazyUBlockExpression( class KotlinLazyUBlockExpression(
override val uastParent: UElement?, override val uastParent: UElement?,
expressionProducer: (expressionParent: UElement) -> List<UExpression> expressionProducer: (expressionParent: UElement) -> List<UExpression>
) : UBlockExpression, JvmDeclarationUElementPlaceholder { ) : UBlockExpression, JvmDeclarationUElementPlaceholder {
override val psi: PsiElement? = null override val psi: PsiElement? get() = null
override val javaPsi: PsiElement? = null override val javaPsi: PsiElement? get() = null
override val sourcePsi: PsiElement? = null override val sourcePsi: PsiElement? get() = null
override val annotations: List<UAnnotation> = emptyList() override val annotations: List<UAnnotation> = emptyList()
override val expressions by lz { expressionProducer(this) } override val expressions by lz { expressionProducer(this) }
} }
@@ -42,14 +42,14 @@ class KotlinUBlockExpression(
fun create(initializers: List<KtAnonymousInitializer>, uastParent: UElement): UBlockExpression { fun create(initializers: List<KtAnonymousInitializer>, uastParent: UElement): UBlockExpression {
val languagePlugin = uastParent.getLanguagePlugin() val languagePlugin = uastParent.getLanguagePlugin()
return KotlinLazyUBlockExpression(uastParent) { expressionParent -> return KotlinLazyUBlockExpression(uastParent) { expressionParent ->
initializers.map { languagePlugin.convertOpt<UExpression>(it.body, expressionParent) ?: UastEmptyExpression(null) } initializers.map { languagePlugin.convertOpt<UExpression>(it.body, expressionParent) ?: UastEmptyExpression(expressionParent) }
} }
} }
} }
override fun convertParent(): UElement? { override fun convertParent(): UElement? {
val directParent = super.convertParent() val directParent = super.convertParent()
if (directParent is UnknownKotlinExpression && directParent.psi is KtAnonymousInitializer) { if (directParent is UnknownKotlinExpression && directParent.sourcePsi is KtAnonymousInitializer) {
val containingUClass = directParent.getContainingUClass() ?: return directParent val containingUClass = directParent.getContainingUClass() ?: return directParent
containingUClass.methods containingUClass.methods
.find { it is KotlinConstructorUMethod && it.isPrimary || it is KotlinSecondaryConstructorWithInitializersUMethod }?.let { .find { it is KotlinConstructorUMethod && it.isPrimary || it is KotlinSecondaryConstructorWithInitializersUMethod }?.let {
@@ -22,9 +22,9 @@ import org.jetbrains.uast.UElement
import org.jetbrains.uast.kotlin.KotlinAbstractUExpression import org.jetbrains.uast.kotlin.KotlinAbstractUExpression
class KotlinUBreakExpression( class KotlinUBreakExpression(
override val psi: KtBreakExpression, override val sourcePsi: KtBreakExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UBreakExpression { ) : KotlinAbstractUExpression(givenParent), UBreakExpression {
override val label: String? override val label: String?
get() = psi.getLabelName() get() = sourcePsi.getLabelName()
} }
@@ -24,29 +24,29 @@ import org.jetbrains.uast.*
import org.jetbrains.uast.kotlin.internal.getResolveResultVariants import org.jetbrains.uast.kotlin.internal.getResolveResultVariants
class KotlinUCallableReferenceExpression( class KotlinUCallableReferenceExpression(
override val psi: KtCallableReferenceExpression, override val sourcePsi: KtCallableReferenceExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UCallableReferenceExpression, UMultiResolvable, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), UCallableReferenceExpression, UMultiResolvable, KotlinUElementWithType {
override val qualifierExpression: UExpression? override val qualifierExpression: UExpression?
get() { get() {
if (qualifierType != null) return null if (qualifierType != null) return null
val receiverExpression = psi.receiverExpression ?: return null val receiverExpression = sourcePsi.receiverExpression ?: return null
return KotlinConverter.convertExpression(receiverExpression, this, DEFAULT_EXPRESSION_TYPES_LIST) return KotlinConverter.convertExpression(receiverExpression, this, DEFAULT_EXPRESSION_TYPES_LIST)
} }
override val qualifierType by lz { override val qualifierType by lz {
val ktType = psi.analyze()[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null val ktType = sourcePsi.analyze()[DOUBLE_COLON_LHS, sourcePsi.receiverExpression]?.type ?: return@lz null
ktType.toPsiType(this, psi, boxed = true) ktType.toPsiType(this, sourcePsi, boxed = true)
} }
override val callableName: String override val callableName: String
get() = psi.callableReference.getReferencedName() get() = sourcePsi.callableReference.getReferencedName()
override val resolvedName: String? override val resolvedName: String?
get() = (resolve() as? PsiNamedElement)?.name get() = (resolve() as? PsiNamedElement)?.name
override fun resolve() = psi.callableReference.resolveCallToDeclaration() override fun resolve() = sourcePsi.callableReference.resolveCallToDeclaration()
override fun multiResolve(): Iterable<ResolveResult> = getResolveResultVariants(psi.callableReference) override fun multiResolve(): Iterable<ResolveResult> = getResolveResultVariants(sourcePsi.callableReference)
} }
@@ -24,26 +24,26 @@ import org.jetbrains.uast.UElement
import org.jetbrains.uast.UExpression import org.jetbrains.uast.UExpression
class KotlinUCallableReferenceExpression( class KotlinUCallableReferenceExpression(
override val psi: KtCallableReferenceExpression, override val sourcePsi: KtCallableReferenceExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UCallableReferenceExpression, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), UCallableReferenceExpression, KotlinUElementWithType {
override val qualifierExpression: UExpression? override val qualifierExpression: UExpression?
get() { get() {
if (qualifierType != null) return null if (qualifierType != null) return null
val receiverExpression = psi.receiverExpression ?: return null val receiverExpression = sourcePsi.receiverExpression ?: return null
return KotlinConverter.convertExpression(receiverExpression, this) return KotlinConverter.convertExpression(receiverExpression, this)
} }
override val qualifierType by lz { override val qualifierType by lz {
val ktType = psi.analyze()[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null val ktType = sourcePsi.analyze()[DOUBLE_COLON_LHS, sourcePsi.receiverExpression]?.type ?: return@lz null
ktType.toPsiType(this, psi, boxed = true) ktType.toPsiType(this, sourcePsi, boxed = true)
} }
override val callableName: String override val callableName: String
get() = psi.callableReference.getReferencedName() get() = sourcePsi.callableReference.getReferencedName()
override val resolvedName: String? override val resolvedName: String?
get() = (resolve() as? PsiNamedElement)?.name get() = (resolve() as? PsiNamedElement)?.name
override fun resolve() = psi.callableReference.resolveCallToDeclaration() override fun resolve() = sourcePsi.callableReference.resolveCallToDeclaration()
} }
@@ -27,29 +27,29 @@ import org.jetbrains.uast.UMultiResolvable
import org.jetbrains.uast.kotlin.internal.getResolveResultVariants import org.jetbrains.uast.kotlin.internal.getResolveResultVariants
class KotlinUCallableReferenceExpression( class KotlinUCallableReferenceExpression(
override val psi: KtCallableReferenceExpression, override val sourcePsi: KtCallableReferenceExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UCallableReferenceExpression, UMultiResolvable, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), UCallableReferenceExpression, UMultiResolvable, KotlinUElementWithType {
override val qualifierExpression: UExpression? override val qualifierExpression: UExpression?
get() { get() {
if (qualifierType != null) return null if (qualifierType != null) return null
val receiverExpression = psi.receiverExpression ?: return null val receiverExpression = sourcePsi.receiverExpression ?: return null
return KotlinConverter.convertExpression(receiverExpression, this) return KotlinConverter.convertExpression(receiverExpression, this)
} }
override val qualifierType by lz { override val qualifierType by lz {
val ktType = psi.analyze()[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null val ktType = sourcePsi.analyze()[DOUBLE_COLON_LHS, sourcePsi.receiverExpression]?.type ?: return@lz null
ktType.toPsiType(this, psi, boxed = true) ktType.toPsiType(this, sourcePsi, boxed = true)
} }
override val callableName: String override val callableName: String
get() = psi.callableReference.getReferencedName() get() = sourcePsi.callableReference.getReferencedName()
override val resolvedName: String? override val resolvedName: String?
get() = (resolve() as? PsiNamedElement)?.name get() = (resolve() as? PsiNamedElement)?.name
override fun resolve() = psi.callableReference.resolveCallToDeclaration() override fun resolve() = sourcePsi.callableReference.resolveCallToDeclaration()
override fun multiResolve(): Iterable<ResolveResult> = getResolveResultVariants(psi.callableReference) override fun multiResolve(): Iterable<ResolveResult> = getResolveResultVariants(sourcePsi.callableReference)
} }
@@ -16,6 +16,7 @@
package org.jetbrains.uast.kotlin package org.jetbrains.uast.kotlin
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.psi.KtCatchClause import org.jetbrains.kotlin.psi.KtCatchClause
import org.jetbrains.uast.UCatchClause import org.jetbrains.uast.UCatchClause
import org.jetbrains.uast.UElement import org.jetbrains.uast.UElement
@@ -24,22 +25,23 @@ import org.jetbrains.uast.UTypeReferenceExpression
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
class KotlinUCatchClause( class KotlinUCatchClause(
override val psi: KtCatchClause, override val sourcePsi: KtCatchClause,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUElement(givenParent), UCatchClause { ) : KotlinAbstractUElement(givenParent), UCatchClause {
override val psi: PsiElement?
get() = sourcePsi
override val javaPsi = null override val javaPsi: PsiElement? get() = null
override val sourcePsi = psi
override val body by lz { KotlinConverter.convertOrEmpty(psi.catchBody, this) } override val body by lz { KotlinConverter.convertOrEmpty(sourcePsi.catchBody, this) }
override val parameters by lz { override val parameters by lz {
val parameter = psi.catchParameter ?: return@lz emptyList<UParameter>() val parameter = sourcePsi.catchParameter ?: return@lz emptyList<UParameter>()
listOf(KotlinUParameter(UastKotlinPsiParameter.create(parameter, psi, this, 0), psi, this)) listOf(KotlinUParameter(UastKotlinPsiParameter.create(parameter, sourcePsi, this, 0), sourcePsi, this))
} }
override val typeReferences by lz { override val typeReferences by lz {
val parameter = psi.catchParameter ?: return@lz emptyList<UTypeReferenceExpression>() val parameter = sourcePsi.catchParameter ?: return@lz emptyList<UTypeReferenceExpression>()
val typeReference = parameter.typeReference ?: return@lz emptyList<UTypeReferenceExpression>() val typeReference = parameter.typeReference ?: return@lz emptyList<UTypeReferenceExpression>()
listOf(LazyKotlinUTypeReferenceExpression(typeReference, this) { typeReference.toPsiType(this, boxed = true) } ) listOf(LazyKotlinUTypeReferenceExpression(typeReference, this) { typeReference.toPsiType(this, boxed = true) } )
} }
@@ -24,18 +24,18 @@ import org.jetbrains.uast.UElement
import org.jetbrains.uast.UExpression import org.jetbrains.uast.UExpression
class KotlinUClassLiteralExpression( class KotlinUClassLiteralExpression(
override val psi: KtClassLiteralExpression, override val sourcePsi: KtClassLiteralExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UClassLiteralExpression, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), UClassLiteralExpression, KotlinUElementWithType {
override val type by lz { override val type by lz {
val ktType = psi.analyze()[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null val ktType = sourcePsi.analyze()[DOUBLE_COLON_LHS, sourcePsi.receiverExpression]?.type ?: return@lz null
ktType.toPsiType(this, psi, boxed = true) ktType.toPsiType(this, sourcePsi, boxed = true)
} }
override val expression: UExpression? override val expression: UExpression?
get() { get() {
if (type != null) return null if (type != null) return null
val receiverExpression = psi.receiverExpression ?: return null val receiverExpression = sourcePsi.receiverExpression ?: return null
return KotlinConverter.convertExpression(receiverExpression, this, DEFAULT_EXPRESSION_TYPES_LIST) return KotlinConverter.convertExpression(receiverExpression, this, DEFAULT_EXPRESSION_TYPES_LIST)
} }
} }
@@ -23,18 +23,18 @@ import org.jetbrains.uast.UElement
import org.jetbrains.uast.UExpression import org.jetbrains.uast.UExpression
class KotlinUClassLiteralExpression( class KotlinUClassLiteralExpression(
override val psi: KtClassLiteralExpression, override val sourcePsi: KtClassLiteralExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UClassLiteralExpression, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), UClassLiteralExpression, KotlinUElementWithType {
override val type by lz { override val type by lz {
val ktType = psi.analyze()[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null val ktType = sourcePsi.analyze()[DOUBLE_COLON_LHS, sourcePsi.receiverExpression]?.type ?: return@lz null
ktType.toPsiType(this, psi, boxed = true) ktType.toPsiType(this, sourcePsi, boxed = true)
} }
override val expression: UExpression? override val expression: UExpression?
get() { get() {
if (type != null) return null if (type != null) return null
val receiverExpression = psi.receiverExpression ?: return null val receiverExpression = sourcePsi.receiverExpression ?: return null
return KotlinConverter.convertExpression(receiverExpression, this) return KotlinConverter.convertExpression(receiverExpression, this)
} }
} }
@@ -22,9 +22,9 @@ import org.jetbrains.uast.UElement
import org.jetbrains.uast.kotlin.KotlinAbstractUExpression import org.jetbrains.uast.kotlin.KotlinAbstractUExpression
class KotlinUContinueExpression( class KotlinUContinueExpression(
override val psi: KtContinueExpression, override val sourcePsi: KtContinueExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UContinueExpression { ) : KotlinAbstractUExpression(givenParent), UContinueExpression {
override val label: String? override val label: String?
get() = psi.getLabelName() get() = sourcePsi.getLabelName()
} }
@@ -23,11 +23,11 @@ import org.jetbrains.uast.UIdentifier
import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
class KotlinUDoWhileExpression( class KotlinUDoWhileExpression(
override val psi: KtDoWhileExpression, override val sourcePsi: KtDoWhileExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UDoWhileExpression { ) : KotlinAbstractUExpression(givenParent), UDoWhileExpression {
override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) } override val condition by lz { KotlinConverter.convertOrEmpty(sourcePsi.condition, this) }
override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) } override val body by lz { KotlinConverter.convertOrEmpty(sourcePsi.body, this) }
override val doIdentifier: UIdentifier override val doIdentifier: UIdentifier
get() = KotlinUIdentifier(null, this) get() = KotlinUIdentifier(null, this)
@@ -25,7 +25,7 @@ import org.jetbrains.uast.UExpression
interface KotlinUElementWithType : UExpression { interface KotlinUElementWithType : UExpression {
override fun getExpressionType(): PsiType? { override fun getExpressionType(): PsiType? {
val ktElement = psi as? KtExpression ?: return null val ktElement = sourcePsi as? KtExpression ?: return null
val ktType = ktElement.analyze()[BindingContext.EXPRESSION_TYPE_INFO, ktElement]?.type ?: return null val ktType = ktElement.analyze()[BindingContext.EXPRESSION_TYPE_INFO, ktElement]?.type ?: return null
return ktType.toPsiType(this, ktElement, boxed = false) return ktType.toPsiType(this, ktElement, boxed = false)
} }
@@ -33,7 +33,7 @@ interface KotlinUElementWithType : UExpression {
interface KotlinEvaluatableUElement : UExpression { interface KotlinEvaluatableUElement : UExpression {
override fun evaluate(): Any? { override fun evaluate(): Any? {
val ktElement = psi as? KtExpression ?: return null val ktElement = sourcePsi as? KtExpression ?: return null
val compileTimeConst = ktElement.analyze()[BindingContext.COMPILE_TIME_VALUE, ktElement] val compileTimeConst = ktElement.analyze()[BindingContext.COMPILE_TIME_VALUE, ktElement]
if (compileTimeConst is UnsignedErrorValueTypeConstant) return null if (compileTimeConst is UnsignedErrorValueTypeConstant) return null
@@ -27,7 +27,7 @@ import org.jetbrains.uast.UastSpecialExpressionKind
import org.jetbrains.uast.kotlin.kinds.KotlinSpecialExpressionKinds import org.jetbrains.uast.kotlin.kinds.KotlinSpecialExpressionKinds
open class KotlinUExpressionList( open class KotlinUExpressionList(
override val psi: PsiElement?, override val sourcePsi: PsiElement?,
override val kind: UastSpecialExpressionKind, // original element override val kind: UastSpecialExpressionKind, // original element
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UExpressionList, KotlinUElementWithType, KotlinEvaluatableUElement { ) : KotlinAbstractUExpression(givenParent), UExpressionList, KotlinUElementWithType, KotlinEvaluatableUElement {
@@ -35,7 +35,7 @@ open class KotlinUExpressionList(
internal set internal set
override fun evaluate(): Any? { override fun evaluate(): Any? {
val ktElement = psi as? KtExpression ?: return null val ktElement = sourcePsi as? KtExpression ?: return null
val compileTimeConst = ktElement.analyze()[BindingContext.COMPILE_TIME_VALUE, ktElement] val compileTimeConst = ktElement.analyze()[BindingContext.COMPILE_TIME_VALUE, ktElement]
return compileTimeConst?.getValue(TypeUtils.NO_EXPECTED_TYPE) return compileTimeConst?.getValue(TypeUtils.NO_EXPECTED_TYPE)
} }
@@ -26,16 +26,16 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
import org.jetbrains.uast.psi.UastPsiParameterNotResolved import org.jetbrains.uast.psi.UastPsiParameterNotResolved
class KotlinUForEachExpression( class KotlinUForEachExpression(
override val psi: KtForExpression, override val sourcePsi: KtForExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UForEachExpression { ) : KotlinAbstractUExpression(givenParent), UForEachExpression {
override val iteratedValue by lz { KotlinConverter.convertOrEmpty(psi.loopRange, this) } override val iteratedValue by lz { KotlinConverter.convertOrEmpty(sourcePsi.loopRange, this) }
override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) } override val body by lz { KotlinConverter.convertOrEmpty(sourcePsi.body, this) }
override val variable by lz { override val variable by lz {
val parameter = psi.loopParameter?.let { UastKotlinPsiParameter.create(it, psi, this, 0) } val parameter = sourcePsi.loopParameter?.let { UastKotlinPsiParameter.create(it, sourcePsi, this, 0) }
?: UastPsiParameterNotResolved(psi, KotlinLanguage.INSTANCE) ?: UastPsiParameterNotResolved(sourcePsi, KotlinLanguage.INSTANCE)
KotlinUParameter(parameter, psi, this) KotlinUParameter(parameter, sourcePsi, this)
} }
override val forIdentifier: UIdentifier override val forIdentifier: UIdentifier
@@ -44,7 +44,7 @@ import org.jetbrains.uast.kotlin.internal.multiResolveResults
import org.jetbrains.uast.visitor.UastVisitor import org.jetbrains.uast.visitor.UastVisitor
class KotlinUFunctionCallExpression( class KotlinUFunctionCallExpression(
override val psi: KtCallElement, override val sourcePsi: KtCallElement,
givenParent: UElement?, givenParent: UElement?,
private val _resolvedCall: ResolvedCall<*>? private val _resolvedCall: ResolvedCall<*>?
) : KotlinAbstractUExpression(givenParent), UCallExpressionEx, KotlinUElementWithType, UMultiResolvable { ) : KotlinAbstractUExpression(givenParent), UCallExpressionEx, KotlinUElementWithType, UMultiResolvable {
@@ -52,22 +52,22 @@ class KotlinUFunctionCallExpression(
constructor(psi: KtCallElement, uastParent: UElement?) : this(psi, uastParent, null) constructor(psi: KtCallElement, uastParent: UElement?) : this(psi, uastParent, null)
private val resolvedCall private val resolvedCall
get() = _resolvedCall ?: psi.getResolvedCall(psi.analyze()) get() = _resolvedCall ?: sourcePsi.getResolvedCall(sourcePsi.analyze())
override val receiverType by lz { override val receiverType by lz {
val resolvedCall = this.resolvedCall ?: return@lz null val resolvedCall = this.resolvedCall ?: return@lz null
val receiver = resolvedCall.dispatchReceiver ?: resolvedCall.extensionReceiver ?: return@lz null val receiver = resolvedCall.dispatchReceiver ?: resolvedCall.extensionReceiver ?: return@lz null
receiver.type.toPsiType(this, psi, boxed = true) receiver.type.toPsiType(this, sourcePsi, boxed = true)
} }
override val methodName by lz { resolvedCall?.resultingDescriptor?.name?.asString() } override val methodName by lz { resolvedCall?.resultingDescriptor?.name?.asString() }
override val classReference by lz { override val classReference by lz {
KotlinClassViaConstructorUSimpleReferenceExpression(psi, methodName.orAnonymous("class"), this) KotlinClassViaConstructorUSimpleReferenceExpression(sourcePsi, methodName.orAnonymous("class"), this)
} }
override val methodIdentifier by lz { override val methodIdentifier by lz {
val calleeExpression = psi.calleeExpression val calleeExpression = sourcePsi.calleeExpression
when (calleeExpression) { when (calleeExpression) {
null -> null null -> null
is KtNameReferenceExpression -> is KtNameReferenceExpression ->
@@ -83,9 +83,9 @@ class KotlinUFunctionCallExpression(
} }
override val valueArgumentCount: Int override val valueArgumentCount: Int
get() = psi.valueArguments.size get() = sourcePsi.valueArguments.size
override val valueArguments by lz { psi.valueArguments.map { KotlinConverter.convertOrEmpty(it.getArgumentExpression(), this) } } override val valueArguments by lz { sourcePsi.valueArguments.map { KotlinConverter.convertOrEmpty(it.getArgumentExpression(), this) } }
override fun getArgumentForParameter(i: Int): UExpression? { override fun getArgumentForParameter(i: Int): UExpression? {
val resolvedCall = resolvedCall val resolvedCall = resolvedCall
@@ -121,9 +121,9 @@ class KotlinUFunctionCallExpression(
} }
override val typeArgumentCount: Int override val typeArgumentCount: Int
get() = psi.typeArguments.size get() = sourcePsi.typeArguments.size
override val typeArguments by lz { psi.typeArguments.map { it.typeReference.toPsiType(this, boxed = true) } } override val typeArguments by lz { sourcePsi.typeArguments.map { it.typeReference.toPsiType(this, boxed = true) } }
override val returnType: PsiType? override val returnType: PsiType?
get() = getExpressionType() get() = getExpressionType()
@@ -143,7 +143,7 @@ class KotlinUFunctionCallExpression(
if (it.selector == this) return it.receiver if (it.selector == this) return it.receiver
} }
val ktNameReferenceExpression = psi.calleeExpression as? KtNameReferenceExpression ?: return null val ktNameReferenceExpression = sourcePsi.calleeExpression as? KtNameReferenceExpression ?: return null
val variableCallDescriptor = val variableCallDescriptor =
(resolvedCall as? VariableAsFunctionResolvedCall)?.variableCall?.resultingDescriptor (resolvedCall as? VariableAsFunctionResolvedCall)?.variableCall?.resultingDescriptor
?: (resolvedCall?.resultingDescriptor as? FunctionDescriptor)?.takeIf { it.visibility == Visibilities.LOCAL } ?: (resolvedCall?.resultingDescriptor as? FunctionDescriptor)?.takeIf { it.visibility == Visibilities.LOCAL }
@@ -165,7 +165,7 @@ class KotlinUFunctionCallExpression(
} }
private val multiResolved by lazy(fun(): Iterable<TypedResolveResult<PsiMethod>> { private val multiResolved by lazy(fun(): Iterable<TypedResolveResult<PsiMethod>> {
val contextElement = psi val contextElement = sourcePsi
if (!Registry.`is`("kotlin.uast.multiresolve.enabled", true)) { if (!Registry.`is`("kotlin.uast.multiresolve.enabled", true)) {
val calleeExpression = contextElement.calleeExpression ?: return emptyList() val calleeExpression = contextElement.calleeExpression ?: return emptyList()
@@ -180,7 +180,7 @@ class KotlinUFunctionCallExpression(
return variants.flatMap { return variants.flatMap {
when (val source = it.toSource()) { when (val source = it.toSource()) {
is KtClass -> source.toLightClass()?.constructors?.asSequence().orEmpty() is KtClass -> source.toLightClass()?.constructors?.asSequence().orEmpty()
else -> resolveSource(psi, it, source)?.let { sequenceOf(it) }.orEmpty() else -> resolveSource(sourcePsi, it, source)?.let { sequenceOf(it) }.orEmpty()
} }
}.map { TypedResolveResult(it) }.asIterable() }.map { TypedResolveResult(it) }.asIterable()
}) })
@@ -191,7 +191,7 @@ class KotlinUFunctionCallExpression(
override fun resolve(): PsiMethod? { override fun resolve(): PsiMethod? {
val descriptor = resolvedCall?.resultingDescriptor ?: return null val descriptor = resolvedCall?.resultingDescriptor ?: return null
val source = descriptor.toSource() val source = descriptor.toSource()
return resolveSource(psi, descriptor, source) return resolveSource(sourcePsi, descriptor, source)
} }
override fun accept(visitor: UastVisitor) { override fun accept(visitor: UastVisitor) {
@@ -205,7 +205,7 @@ class KotlinUFunctionCallExpression(
private fun isAnnotationArgumentArrayInitializer(): Boolean { private fun isAnnotationArgumentArrayInitializer(): Boolean {
// KtAnnotationEntry (or KtCallExpression when annotation is nested) -> KtValueArgumentList -> KtValueArgument -> arrayOf call // KtAnnotationEntry (or KtCallExpression when annotation is nested) -> KtValueArgumentList -> KtValueArgument -> arrayOf call
val isAnnotationArgument = when (val elementAt2 = psi.parents.elementAtOrNull(2)) { val isAnnotationArgument = when (val elementAt2 = sourcePsi.parents.elementAtOrNull(2)) {
is KtAnnotationEntry -> true is KtAnnotationEntry -> true
is KtCallExpression -> elementAt2.getParentOfType<KtAnnotationEntry>(true, KtDeclaration::class.java) != null is KtCallExpression -> elementAt2.getParentOfType<KtAnnotationEntry>(true, KtDeclaration::class.java) != null
else -> false else -> false
@@ -37,7 +37,7 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
import org.jetbrains.uast.visitor.UastVisitor import org.jetbrains.uast.visitor.UastVisitor
class KotlinUFunctionCallExpression( class KotlinUFunctionCallExpression(
override val psi: KtCallElement, override val sourcePsi: KtCallElement,
givenParent: UElement?, givenParent: UElement?,
private val _resolvedCall: ResolvedCall<*>? private val _resolvedCall: ResolvedCall<*>?
) : KotlinAbstractUExpression(givenParent), UCallExpressionEx, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), UCallExpressionEx, KotlinUElementWithType {
@@ -45,22 +45,22 @@ class KotlinUFunctionCallExpression(
constructor(psi: KtCallElement, uastParent: UElement?) : this(psi, uastParent, null) constructor(psi: KtCallElement, uastParent: UElement?) : this(psi, uastParent, null)
private val resolvedCall private val resolvedCall
get() = _resolvedCall ?: psi.getResolvedCall(psi.analyze()) get() = _resolvedCall ?: sourcePsi.getResolvedCall(sourcePsi.analyze())
override val receiverType by lz { override val receiverType by lz {
val resolvedCall = this.resolvedCall ?: return@lz null val resolvedCall = this.resolvedCall ?: return@lz null
val receiver = resolvedCall.dispatchReceiver ?: resolvedCall.extensionReceiver ?: return@lz null val receiver = resolvedCall.dispatchReceiver ?: resolvedCall.extensionReceiver ?: return@lz null
receiver.type.toPsiType(this, psi, boxed = true) receiver.type.toPsiType(this, sourcePsi, boxed = true)
} }
override val methodName by lz { resolvedCall?.resultingDescriptor?.name?.asString() } override val methodName by lz { resolvedCall?.resultingDescriptor?.name?.asString() }
override val classReference by lz { override val classReference by lz {
KotlinClassViaConstructorUSimpleReferenceExpression(psi, methodName.orAnonymous("class"), this) KotlinClassViaConstructorUSimpleReferenceExpression(sourcePsi, methodName.orAnonymous("class"), this)
} }
override val methodIdentifier by lz { override val methodIdentifier by lz {
val calleeExpression = psi.calleeExpression val calleeExpression = sourcePsi.calleeExpression
when (calleeExpression) { when (calleeExpression) {
null -> null null -> null
is KtNameReferenceExpression -> is KtNameReferenceExpression ->
@@ -76,9 +76,9 @@ class KotlinUFunctionCallExpression(
} }
override val valueArgumentCount: Int override val valueArgumentCount: Int
get() = psi.valueArguments.size get() = sourcePsi.valueArguments.size
override val valueArguments by lz { psi.valueArguments.map { KotlinConverter.convertOrEmpty(it.getArgumentExpression(), this) } } override val valueArguments by lz { sourcePsi.valueArguments.map { KotlinConverter.convertOrEmpty(it.getArgumentExpression(), this) } }
override fun getArgumentForParameter(i: Int): UExpression? { override fun getArgumentForParameter(i: Int): UExpression? {
val resolvedCall = resolvedCall ?: return null val resolvedCall = resolvedCall ?: return null
@@ -89,9 +89,9 @@ class KotlinUFunctionCallExpression(
override val typeArgumentCount: Int override val typeArgumentCount: Int
get() = psi.typeArguments.size get() = sourcePsi.typeArguments.size
override val typeArguments by lz { psi.typeArguments.map { it.typeReference.toPsiType(this, boxed = true) } } override val typeArguments by lz { sourcePsi.typeArguments.map { it.typeReference.toPsiType(this, boxed = true) } }
override val returnType: PsiType? override val returnType: PsiType?
get() = getExpressionType() get() = getExpressionType()
@@ -111,7 +111,7 @@ class KotlinUFunctionCallExpression(
if (it.selector == this) return it.receiver if (it.selector == this) return it.receiver
} }
val ktNameReferenceExpression = psi.calleeExpression as? KtNameReferenceExpression ?: return null val ktNameReferenceExpression = sourcePsi.calleeExpression as? KtNameReferenceExpression ?: return null
val variableCallDescriptor = val variableCallDescriptor =
(resolvedCall as? VariableAsFunctionResolvedCall)?.variableCall?.resultingDescriptor (resolvedCall as? VariableAsFunctionResolvedCall)?.variableCall?.resultingDescriptor
?: (resolvedCall?.resultingDescriptor as? FunctionDescriptor)?.takeIf { it.visibility == Visibilities.LOCAL } ?: (resolvedCall?.resultingDescriptor as? FunctionDescriptor)?.takeIf { it.visibility == Visibilities.LOCAL }
@@ -135,7 +135,7 @@ class KotlinUFunctionCallExpression(
override fun resolve(): PsiMethod? { override fun resolve(): PsiMethod? {
val descriptor = resolvedCall?.resultingDescriptor ?: return null val descriptor = resolvedCall?.resultingDescriptor ?: return null
val source = descriptor.toSource() val source = descriptor.toSource()
return resolveSource(psi, descriptor, source) return resolveSource(sourcePsi, descriptor, source)
} }
override fun accept(visitor: UastVisitor) { override fun accept(visitor: UastVisitor) {
@@ -149,7 +149,7 @@ class KotlinUFunctionCallExpression(
private fun isAnnotationArgumentArrayInitializer(): Boolean { private fun isAnnotationArgumentArrayInitializer(): Boolean {
// KtAnnotationEntry (or KtCallExpression when annotation is nested) -> KtValueArgumentList -> KtValueArgument -> arrayOf call // KtAnnotationEntry (or KtCallExpression when annotation is nested) -> KtValueArgumentList -> KtValueArgument -> arrayOf call
val isAnnotationArgument = when (val elementAt2 = psi.parents.elementAtOrNull(2)) { val isAnnotationArgument = when (val elementAt2 = sourcePsi.parents.elementAtOrNull(2)) {
is KtAnnotationEntry -> true is KtAnnotationEntry -> true
is KtCallExpression -> elementAt2.getParentOfType<KtAnnotationEntry>(true, KtDeclaration::class.java) != null is KtCallExpression -> elementAt2.getParentOfType<KtAnnotationEntry>(true, KtDeclaration::class.java) != null
else -> false else -> false
@@ -22,12 +22,12 @@ import org.jetbrains.uast.UIdentifier
import org.jetbrains.uast.UIfExpression import org.jetbrains.uast.UIfExpression
class KotlinUIfExpression( class KotlinUIfExpression(
override val psi: KtIfExpression, override val sourcePsi: KtIfExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UIfExpression, KotlinUElementWithType, KotlinEvaluatableUElement { ) : KotlinAbstractUExpression(givenParent), UIfExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) } override val condition by lz { KotlinConverter.convertOrEmpty(sourcePsi.condition, this) }
override val thenExpression by lz { KotlinConverter.convertOrNull(psi.then, this) } override val thenExpression by lz { KotlinConverter.convertOrNull(sourcePsi.then, this) }
override val elseExpression by lz { KotlinConverter.convertOrNull(psi.`else`, this) } override val elseExpression by lz { KotlinConverter.convertOrNull(sourcePsi.`else`, this) }
override val isTernary = false override val isTernary = false
override val ifIdentifier: UIdentifier override val ifIdentifier: UIdentifier
@@ -23,14 +23,14 @@ import org.jetbrains.uast.ULabeledExpression
import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
class KotlinULabeledExpression( class KotlinULabeledExpression(
override val psi: KtLabeledExpression, override val sourcePsi: KtLabeledExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), ULabeledExpression { ) : KotlinAbstractUExpression(givenParent), ULabeledExpression {
override val label: String override val label: String
get() = psi.getLabelName().orAnonymous("label") get() = sourcePsi.getLabelName().orAnonymous("label")
override val labelIdentifier: UIdentifier? override val labelIdentifier: UIdentifier?
get() = psi.getTargetLabel()?.let { KotlinUIdentifier(it, this) } get() = sourcePsi.getTargetLabel()?.let { KotlinUIdentifier(it, this) }
override val expression by lz { KotlinConverter.convertOrEmpty(psi.baseExpression, this) } override val expression by lz { KotlinConverter.convertOrEmpty(sourcePsi.baseExpression, this) }
} }
@@ -25,17 +25,17 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
import org.jetbrains.uast.withMargin import org.jetbrains.uast.withMargin
class KotlinULambdaExpression( class KotlinULambdaExpression(
override val psi: KtLambdaExpression, override val sourcePsi: KtLambdaExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), ULambdaExpression, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), ULambdaExpression, KotlinUElementWithType {
override val functionalInterfaceType: PsiType? override val functionalInterfaceType: PsiType?
get() = getFunctionalInterfaceType() get() = getFunctionalInterfaceType()
override val body by lz { KotlinConverter.convertOrEmpty(psi.bodyExpression, this) } override val body by lz { KotlinConverter.convertOrEmpty(sourcePsi.bodyExpression, this) }
override val valueParameters by lz { override val valueParameters by lz {
psi.valueParameters.mapIndexed { i, p -> sourcePsi.valueParameters.mapIndexed { i, p ->
KotlinUParameter(UastKotlinPsiParameter.create(p, psi, this, i), psi, this) KotlinUParameter(UastKotlinPsiParameter.create(p, sourcePsi, this, i), sourcePsi, this)
} }
} }
@@ -25,17 +25,17 @@ import org.jetbrains.uast.UElement
import org.jetbrains.uast.ULiteralExpression import org.jetbrains.uast.ULiteralExpression
class KotlinULiteralExpression( class KotlinULiteralExpression(
override val psi: KtConstantExpression, override val sourcePsi: KtConstantExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), ULiteralExpression, KotlinUElementWithType, KotlinEvaluatableUElement { ) : KotlinAbstractUExpression(givenParent), ULiteralExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
override val isNull: Boolean override val isNull: Boolean
get() = psi.unwrapBlockOrParenthesis().node?.elementType == KtNodeTypes.NULL get() = sourcePsi.unwrapBlockOrParenthesis().node?.elementType == KtNodeTypes.NULL
override val value by lz { evaluate() } override val value by lz { evaluate() }
} }
class KotlinStringULiteralExpression( class KotlinStringULiteralExpression(
override val psi: PsiElement, override val sourcePsi: PsiElement,
givenParent: UElement?, givenParent: UElement?,
val text: String val text: String
) : KotlinAbstractUExpression(givenParent), ULiteralExpression, KotlinUElementWithType{ ) : KotlinAbstractUExpression(givenParent), ULiteralExpression, KotlinUElementWithType{
@@ -47,5 +47,5 @@ class KotlinStringULiteralExpression(
override fun evaluate() = value override fun evaluate() = value
override fun getExpressionType(): PsiType? = PsiType.getJavaLangString(psi.manager, psi.resolveScope) override fun getExpressionType(): PsiType? = PsiType.getJavaLangString(sourcePsi.manager, sourcePsi.resolveScope)
} }
@@ -68,7 +68,7 @@ class KotlinUVarargExpression(
valueArgs.map { valueArgs.map {
it.getArgumentExpression()?.let { argumentExpression -> it.getArgumentExpression()?.let { argumentExpression ->
getLanguagePlugin().convert<UExpression>(argumentExpression, this) getLanguagePlugin().convert<UExpression>(argumentExpression, this)
} ?: UastEmptyExpression(null) } ?: UastEmptyExpression(this)
} }
} }
@@ -16,6 +16,7 @@
package org.jetbrains.uast.kotlin package org.jetbrains.uast.kotlin
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiMethod import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiType import com.intellij.psi.PsiType
import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.asJava.toLightClass
@@ -27,20 +28,20 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
class KotlinUObjectLiteralExpression( class KotlinUObjectLiteralExpression(
override val psi: KtObjectLiteralExpression, override val sourcePsi: KtObjectLiteralExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UObjectLiteralExpression, UCallExpressionEx, DelegatedMultiResolve, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), UObjectLiteralExpression, UCallExpressionEx, DelegatedMultiResolve, KotlinUElementWithType {
override val declaration: UClass by lz { override val declaration: UClass by lz {
psi.objectDeclaration.toLightClass() sourcePsi.objectDeclaration.toLightClass()
?.let { getLanguagePlugin().convert<UClass>(it, this) } ?.let { getLanguagePlugin().convert<UClass>(it, this) }
?: KotlinInvalidUClass("<invalid object code>", psi, this) ?: KotlinInvalidUClass("<invalid object code>", sourcePsi, this)
} }
override fun getExpressionType() = psi.objectDeclaration.toPsiType() override fun getExpressionType() = sourcePsi.objectDeclaration.toPsiType()
private val superClassConstructorCall by lz { private val superClassConstructorCall by lz {
psi.objectDeclaration.superTypeListEntries.firstOrNull { it is KtSuperTypeCallEntry } as? KtSuperTypeCallEntry sourcePsi.objectDeclaration.superTypeListEntries.firstOrNull { it is KtSuperTypeCallEntry } as? KtSuperTypeCallEntry
} }
override val classReference: UReferenceExpression? by lz { superClassConstructorCall?.let { ObjectLiteralClassReference(it, this) } } override val classReference: UReferenceExpression? by lz { superClassConstructorCall?.let { ObjectLiteralClassReference(it, this) } }
@@ -67,14 +68,14 @@ class KotlinUObjectLiteralExpression(
superClassConstructorCall?.let { it.getResolvedCall(it.analyze()) }?.let { getArgumentExpressionByIndex(i, it, this) } superClassConstructorCall?.let { it.getResolvedCall(it.analyze()) }?.let { getArgumentExpressionByIndex(i, it, this) }
private class ObjectLiteralClassReference( private class ObjectLiteralClassReference(
override val psi: KtSuperTypeCallEntry, override val sourcePsi: KtSuperTypeCallEntry,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUElement(givenParent), USimpleNameReferenceExpression { ) : KotlinAbstractUElement(givenParent), USimpleNameReferenceExpression {
override val javaPsi = null override val javaPsi: PsiElement? get() = null
override val sourcePsi = psi override val psi: KtSuperTypeCallEntry get() = sourcePsi
override fun resolve() = (psi.resolveCallToDeclaration() as? PsiMethod)?.containingClass override fun resolve() = (sourcePsi.resolveCallToDeclaration() as? PsiMethod)?.containingClass
override val annotations: List<UAnnotation> override val annotations: List<UAnnotation>
get() = emptyList() get() = emptyList()
@@ -16,6 +16,7 @@
package org.jetbrains.uast.kotlin package org.jetbrains.uast.kotlin
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiMethod import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiType import com.intellij.psi.PsiType
import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.asJava.toLightClass
@@ -26,20 +27,20 @@ import org.jetbrains.uast.*
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
class KotlinUObjectLiteralExpression( class KotlinUObjectLiteralExpression(
override val psi: KtObjectLiteralExpression, override val sourcePsi: KtObjectLiteralExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UObjectLiteralExpression, UCallExpressionEx, DelegatedMultiResolve, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), UObjectLiteralExpression, UCallExpressionEx, DelegatedMultiResolve, KotlinUElementWithType {
override val declaration: UClass by lz { override val declaration: UClass by lz {
psi.objectDeclaration.toLightClass() sourcePsi.objectDeclaration.toLightClass()
?.let { getLanguagePlugin().convert<UClass>(it, this) } ?.let { getLanguagePlugin().convert<UClass>(it, this) }
?: KotlinInvalidUClass("<invalid object code>", psi, this) ?: KotlinInvalidUClass("<invalid object code>", sourcePsi, this)
} }
override fun getExpressionType() = psi.objectDeclaration.toPsiType() override fun getExpressionType() = sourcePsi.objectDeclaration.toPsiType()
private val superClassConstructorCall by lz { private val superClassConstructorCall by lz {
psi.objectDeclaration.superTypeListEntries.firstOrNull { it is KtSuperTypeCallEntry } as? KtSuperTypeCallEntry sourcePsi.objectDeclaration.superTypeListEntries.firstOrNull { it is KtSuperTypeCallEntry } as? KtSuperTypeCallEntry
} }
override val classReference: UReferenceExpression? by lz { superClassConstructorCall?.let { ObjectLiteralClassReference(it, this) } } override val classReference: UReferenceExpression? by lz { superClassConstructorCall?.let { ObjectLiteralClassReference(it, this) } }
@@ -66,14 +67,14 @@ class KotlinUObjectLiteralExpression(
superClassConstructorCall?.let { it.getResolvedCall(it.analyze()) }?.let { getArgumentExpressionByIndex(i, it, this) } superClassConstructorCall?.let { it.getResolvedCall(it.analyze()) }?.let { getArgumentExpressionByIndex(i, it, this) }
private class ObjectLiteralClassReference( private class ObjectLiteralClassReference(
override val psi: KtSuperTypeCallEntry, override val sourcePsi: KtSuperTypeCallEntry,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUElement(givenParent), USimpleNameReferenceExpression { ) : KotlinAbstractUElement(givenParent), USimpleNameReferenceExpression {
override val javaPsi = null override val javaPsi: PsiElement? get() = null
override val sourcePsi = psi override val psi: KtSuperTypeCallEntry get() = sourcePsi
override fun resolve() = (psi.resolveCallToDeclaration() as? PsiMethod)?.containingClass override fun resolve() = (sourcePsi.resolveCallToDeclaration() as? PsiMethod)?.containingClass
override val annotations: List<UAnnotation> override val annotations: List<UAnnotation>
get() = emptyList() get() = emptyList()
@@ -21,8 +21,8 @@ import org.jetbrains.uast.UElement
import org.jetbrains.uast.UParenthesizedExpression import org.jetbrains.uast.UParenthesizedExpression
class KotlinUParenthesizedExpression( class KotlinUParenthesizedExpression(
override val psi: KtParenthesizedExpression, override val sourcePsi: KtParenthesizedExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UParenthesizedExpression, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), UParenthesizedExpression, KotlinUElementWithType {
override val expression by lz { KotlinConverter.convertOrEmpty(psi.expression, this) } override val expression by lz { KotlinConverter.convertOrEmpty(sourcePsi.expression, this) }
} }
@@ -24,13 +24,13 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
class KotlinUPostfixExpression( class KotlinUPostfixExpression(
override val psi: KtPostfixExpression, override val sourcePsi: KtPostfixExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UPostfixExpression, KotlinUElementWithType, KotlinEvaluatableUElement, ) : KotlinAbstractUExpression(givenParent), UPostfixExpression, KotlinUElementWithType, KotlinEvaluatableUElement,
UResolvable, DelegatedMultiResolve { UResolvable, DelegatedMultiResolve {
override val operand by lz { KotlinConverter.convertOrEmpty(psi.baseExpression, this) } override val operand by lz { KotlinConverter.convertOrEmpty(sourcePsi.baseExpression, this) }
override val operator = when (psi.operationToken) { override val operator = when (sourcePsi.operationToken) {
KtTokens.PLUSPLUS -> UastPostfixOperator.INC KtTokens.PLUSPLUS -> UastPostfixOperator.INC
KtTokens.MINUSMINUS -> UastPostfixOperator.DEC KtTokens.MINUSMINUS -> UastPostfixOperator.DEC
KtTokens.EXCLEXCL -> KotlinPostfixOperators.EXCLEXCL KtTokens.EXCLEXCL -> KotlinPostfixOperators.EXCLEXCL
@@ -38,11 +38,11 @@ class KotlinUPostfixExpression(
} }
override val operatorIdentifier: UIdentifier? override val operatorIdentifier: UIdentifier?
get() = KotlinUIdentifier(psi.operationReference, this) get() = KotlinUIdentifier(sourcePsi.operationReference, this)
override fun resolveOperator() = psi.operationReference.resolveCallToDeclaration() as? PsiMethod override fun resolveOperator() = sourcePsi.operationReference.resolveCallToDeclaration() as? PsiMethod
override fun resolve(): PsiMethod? = when (psi.operationToken) { override fun resolve(): PsiMethod? = when (sourcePsi.operationToken) {
KtTokens.EXCLEXCL -> operand.tryResolve() as? PsiMethod KtTokens.EXCLEXCL -> operand.tryResolve() as? PsiMethod
else -> null else -> null
} }
@@ -26,17 +26,17 @@ import org.jetbrains.uast.UastPrefixOperator
import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
class KotlinUPrefixExpression( class KotlinUPrefixExpression(
override val psi: KtPrefixExpression, override val sourcePsi: KtPrefixExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UPrefixExpression, KotlinUElementWithType, KotlinEvaluatableUElement { ) : KotlinAbstractUExpression(givenParent), UPrefixExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
override val operand by lz { KotlinConverter.convertOrEmpty(psi.baseExpression, this) } override val operand by lz { KotlinConverter.convertOrEmpty(sourcePsi.baseExpression, this) }
override val operatorIdentifier: UIdentifier? override val operatorIdentifier: UIdentifier?
get() = KotlinUIdentifier(psi.operationReference, this) get() = KotlinUIdentifier(sourcePsi.operationReference, this)
override fun resolveOperator() = psi.operationReference.resolveCallToDeclaration() as? PsiMethod override fun resolveOperator() = sourcePsi.operationReference.resolveCallToDeclaration() as? PsiMethod
override val operator = when (psi.operationToken) { override val operator = when (sourcePsi.operationToken) {
KtTokens.EXCL -> UastPrefixOperator.LOGICAL_NOT KtTokens.EXCL -> UastPrefixOperator.LOGICAL_NOT
KtTokens.PLUS -> UastPrefixOperator.UNARY_PLUS KtTokens.PLUS -> UastPrefixOperator.UNARY_PLUS
KtTokens.MINUS -> UastPrefixOperator.UNARY_MINUS KtTokens.MINUS -> UastPrefixOperator.UNARY_MINUS
@@ -25,15 +25,15 @@ import org.jetbrains.uast.UastQualifiedExpressionAccessType
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
class KotlinUQualifiedReferenceExpression( class KotlinUQualifiedReferenceExpression(
override val psi: KtDotQualifiedExpression, override val sourcePsi: KtDotQualifiedExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UQualifiedReferenceExpression, DelegatedMultiResolve, ) : KotlinAbstractUExpression(givenParent), UQualifiedReferenceExpression, DelegatedMultiResolve,
KotlinUElementWithType, KotlinEvaluatableUElement { KotlinUElementWithType, KotlinEvaluatableUElement {
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.receiverExpression, this) } override val receiver by lz { KotlinConverter.convertOrEmpty(sourcePsi.receiverExpression, this) }
override val selector by lz { KotlinConverter.convertOrEmpty(psi.selectorExpression, this) } override val selector by lz { KotlinConverter.convertOrEmpty(sourcePsi.selectorExpression, this) }
override val accessType = UastQualifiedExpressionAccessType.SIMPLE override val accessType = UastQualifiedExpressionAccessType.SIMPLE
override fun resolve() = psi.selectorExpression?.resolveCallToDeclaration() override fun resolve() = sourcePsi.selectorExpression?.resolveCallToDeclaration()
override val resolvedName: String? override val resolvedName: String?
get() = (resolve() as? PsiNamedElement)?.name get() = (resolve() as? PsiNamedElement)?.name
@@ -24,15 +24,15 @@ import org.jetbrains.uast.UastQualifiedExpressionAccessType
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
class KotlinUQualifiedReferenceExpression( class KotlinUQualifiedReferenceExpression(
override val psi: KtDotQualifiedExpression, override val sourcePsi: KtDotQualifiedExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UQualifiedReferenceExpression, DelegatedMultiResolve, ) : KotlinAbstractUExpression(givenParent), UQualifiedReferenceExpression, DelegatedMultiResolve,
KotlinUElementWithType, KotlinEvaluatableUElement { KotlinUElementWithType, KotlinEvaluatableUElement {
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.receiverExpression, this) } override val receiver by lz { KotlinConverter.convertOrEmpty(sourcePsi.receiverExpression, this) }
override val selector by lz { KotlinConverter.convertOrEmpty(psi.selectorExpression, this) } override val selector by lz { KotlinConverter.convertOrEmpty(sourcePsi.selectorExpression, this) }
override val accessType = UastQualifiedExpressionAccessType.SIMPLE override val accessType = UastQualifiedExpressionAccessType.SIMPLE
override fun resolve() = psi.selectorExpression?.resolveCallToDeclaration() override fun resolve() = sourcePsi.selectorExpression?.resolveCallToDeclaration()
override val resolvedName: String? override val resolvedName: String?
get() = (resolve() as? PsiNamedElement)?.name get() = (resolve() as? PsiNamedElement)?.name
@@ -23,10 +23,10 @@ import org.jetbrains.uast.UExpression
import org.jetbrains.uast.UReturnExpression import org.jetbrains.uast.UReturnExpression
class KotlinUReturnExpression( class KotlinUReturnExpression(
override val psi: KtReturnExpression, override val sourcePsi: KtReturnExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UReturnExpression, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), UReturnExpression, KotlinUElementWithType {
override val returnExpression by lz { KotlinConverter.convertOrNull(psi.returnedExpression, this) } override val returnExpression by lz { KotlinConverter.convertOrNull(sourcePsi.returnedExpression, this) }
} }
class KotlinUImplicitReturnExpression( class KotlinUImplicitReturnExpression(
@@ -25,17 +25,17 @@ import org.jetbrains.uast.UQualifiedReferenceExpression
import org.jetbrains.uast.kotlin.internal.getResolveResultVariants import org.jetbrains.uast.kotlin.internal.getResolveResultVariants
class KotlinUSafeQualifiedExpression( class KotlinUSafeQualifiedExpression(
override val psi: KtSafeQualifiedExpression, override val sourcePsi: KtSafeQualifiedExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UQualifiedReferenceExpression, UMultiResolvable, ) : KotlinAbstractUExpression(givenParent), UQualifiedReferenceExpression, UMultiResolvable,
KotlinUElementWithType, KotlinEvaluatableUElement { KotlinUElementWithType, KotlinEvaluatableUElement {
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.receiverExpression, this) } override val receiver by lz { KotlinConverter.convertOrEmpty(sourcePsi.receiverExpression, this) }
override val selector by lz { KotlinConverter.convertOrEmpty(psi.selectorExpression, this) } override val selector by lz { KotlinConverter.convertOrEmpty(sourcePsi.selectorExpression, this) }
override val accessType = KotlinQualifiedExpressionAccessTypes.SAFE override val accessType = KotlinQualifiedExpressionAccessTypes.SAFE
override val resolvedName: String? override val resolvedName: String?
get() = (resolve() as? PsiNamedElement)?.name get() = (resolve() as? PsiNamedElement)?.name
override fun resolve() = psi.selectorExpression?.resolveCallToDeclaration() override fun resolve() = sourcePsi.selectorExpression?.resolveCallToDeclaration()
override fun multiResolve(): Iterable<ResolveResult> = getResolveResultVariants(psi.selectorExpression) override fun multiResolve(): Iterable<ResolveResult> = getResolveResultVariants(sourcePsi.selectorExpression)
} }
@@ -22,16 +22,16 @@ import org.jetbrains.uast.UElement
import org.jetbrains.uast.UQualifiedReferenceExpression import org.jetbrains.uast.UQualifiedReferenceExpression
class KotlinUSafeQualifiedExpression( class KotlinUSafeQualifiedExpression(
override val psi: KtSafeQualifiedExpression, override val sourcePsi: KtSafeQualifiedExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UQualifiedReferenceExpression, ) : KotlinAbstractUExpression(givenParent), UQualifiedReferenceExpression,
KotlinUElementWithType, KotlinEvaluatableUElement { KotlinUElementWithType, KotlinEvaluatableUElement {
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.receiverExpression, this) } override val receiver by lz { KotlinConverter.convertOrEmpty(sourcePsi.receiverExpression, this) }
override val selector by lz { KotlinConverter.convertOrEmpty(psi.selectorExpression, this) } override val selector by lz { KotlinConverter.convertOrEmpty(sourcePsi.selectorExpression, this) }
override val accessType = KotlinQualifiedExpressionAccessTypes.SAFE override val accessType = KotlinQualifiedExpressionAccessTypes.SAFE
override val resolvedName: String? override val resolvedName: String?
get() = (resolve() as? PsiNamedElement)?.name get() = (resolve() as? PsiNamedElement)?.name
override fun resolve() = psi.selectorExpression?.resolveCallToDeclaration() override fun resolve() = sourcePsi.selectorExpression?.resolveCallToDeclaration()
} }
@@ -38,18 +38,18 @@ import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
import org.jetbrains.uast.visitor.UastVisitor import org.jetbrains.uast.visitor.UastVisitor
open class KotlinUSimpleReferenceExpression( open class KotlinUSimpleReferenceExpression(
override val psi: KtSimpleNameExpression, override val sourcePsi: KtSimpleNameExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), USimpleNameReferenceExpression, KotlinUElementWithType, KotlinEvaluatableUElement { ) : KotlinAbstractUExpression(givenParent), USimpleNameReferenceExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
private val resolvedDeclaration: PsiElement? by lz { private val resolvedDeclaration: PsiElement? by lz {
psi.resolveCallToDeclaration()?.let { return@lz it } sourcePsi.resolveCallToDeclaration()?.let { return@lz it }
var declarationDescriptor = psi.analyze()[BindingContext.REFERENCE_TARGET, psi] ?: return@lz null var declarationDescriptor = sourcePsi.analyze()[BindingContext.REFERENCE_TARGET, sourcePsi] ?: return@lz null
if (declarationDescriptor is ImportedFromObjectCallableDescriptor<*>) { if (declarationDescriptor is ImportedFromObjectCallableDescriptor<*>) {
declarationDescriptor = declarationDescriptor.callableFromObject declarationDescriptor = declarationDescriptor.callableFromObject
} }
if (declarationDescriptor is SyntheticJavaPropertyDescriptor) { if (declarationDescriptor is SyntheticJavaPropertyDescriptor) {
declarationDescriptor = when (psi.readWriteAccess()) { declarationDescriptor = when (sourcePsi.readWriteAccess()) {
ReferenceAccess.WRITE, ReferenceAccess.READ_WRITE -> ReferenceAccess.WRITE, ReferenceAccess.READ_WRITE ->
declarationDescriptor.setMethod ?: declarationDescriptor.getMethod declarationDescriptor.setMethod ?: declarationDescriptor.getMethod
ReferenceAccess.READ -> declarationDescriptor.getMethod ReferenceAccess.READ -> declarationDescriptor.getMethod
@@ -57,17 +57,17 @@ open class KotlinUSimpleReferenceExpression(
} }
if (declarationDescriptor is PackageViewDescriptor) { if (declarationDescriptor is PackageViewDescriptor) {
return@lz JavaPsiFacade.getInstance(psi.project).findPackage(declarationDescriptor.fqName.asString()) return@lz JavaPsiFacade.getInstance(sourcePsi.project).findPackage(declarationDescriptor.fqName.asString())
} }
resolveToPsiClass(this, declarationDescriptor, psi)?.let { return@lz it } resolveToPsiClass(this, declarationDescriptor, sourcePsi)?.let { return@lz it }
if (declarationDescriptor is DeclarationDescriptorWithSource) { if (declarationDescriptor is DeclarationDescriptorWithSource) {
declarationDescriptor.source.getPsi()?.let { it.getMaybeLightElement() ?: it }?.let { return@lz it } declarationDescriptor.source.getPsi()?.let { it.getMaybeLightElement() ?: it }?.let { return@lz it }
} }
return@lz resolveDeserialized(psi, declarationDescriptor, psi.readWriteAccess()) return@lz resolveDeserialized(sourcePsi, declarationDescriptor, sourcePsi.readWriteAccess())
} }
override val identifier get() = psi.getReferencedName() override val identifier get() = sourcePsi.getReferencedName()
override fun resolve() = resolvedDeclaration override fun resolve() = resolvedDeclaration
@@ -77,24 +77,24 @@ open class KotlinUSimpleReferenceExpression(
override fun accept(visitor: UastVisitor) { override fun accept(visitor: UastVisitor) {
visitor.visitSimpleNameReferenceExpression(this) visitor.visitSimpleNameReferenceExpression(this)
if (psi.parent.destructuringDeclarationInitializer != true) { if (sourcePsi.parent.destructuringDeclarationInitializer != true) {
visitAccessorCalls(visitor) visitAccessorCalls(visitor)
} }
visitor.afterVisitSimpleNameReferenceExpression(this) visitor.afterVisitSimpleNameReferenceExpression(this)
} }
override val referenceNameElement: UElement? by lz { psi.getIdentifier()?.toUElement() } override val referenceNameElement: UElement? by lz { sourcePsi.getIdentifier()?.toUElement() }
private fun visitAccessorCalls(visitor: UastVisitor) { private fun visitAccessorCalls(visitor: UastVisitor) {
// Visit Kotlin get-set synthetic Java property calls as function calls // Visit Kotlin get-set synthetic Java property calls as function calls
val bindingContext = psi.analyze() val bindingContext = sourcePsi.analyze()
val access = psi.readWriteAccess() val access = sourcePsi.readWriteAccess()
val resolvedCall = psi.getResolvedCall(bindingContext) val resolvedCall = sourcePsi.getResolvedCall(bindingContext)
val resultingDescriptor = resolvedCall?.resultingDescriptor as? SyntheticJavaPropertyDescriptor val resultingDescriptor = resolvedCall?.resultingDescriptor as? SyntheticJavaPropertyDescriptor
if (resultingDescriptor != null) { if (resultingDescriptor != null) {
val setterValue = if (access.isWrite) { val setterValue = if (access.isWrite) {
findAssignment(psi, psi.parent)?.right ?: run { findAssignment(sourcePsi, sourcePsi.parent)?.right ?: run {
visitor.afterVisitSimpleNameReferenceExpression(this) visitor.afterVisitSimpleNameReferenceExpression(this)
return return
} }
@@ -104,13 +104,13 @@ open class KotlinUSimpleReferenceExpression(
if (access.isRead) { if (access.isRead) {
val getDescriptor = resultingDescriptor.getMethod val getDescriptor = resultingDescriptor.getMethod
KotlinAccessorCallExpression(psi, this, resolvedCall, getDescriptor, null).accept(visitor) KotlinAccessorCallExpression(sourcePsi, this, resolvedCall, getDescriptor, null).accept(visitor)
} }
if (access.isWrite && setterValue != null) { if (access.isWrite && setterValue != null) {
val setDescriptor = resultingDescriptor.setMethod val setDescriptor = resultingDescriptor.setMethod
if (setDescriptor != null) { if (setDescriptor != null) {
KotlinAccessorCallExpression(psi, this, resolvedCall, setDescriptor, setterValue).accept(visitor) KotlinAccessorCallExpression(sourcePsi, this, resolvedCall, setDescriptor, setterValue).accept(visitor)
} }
} }
} }
@@ -124,7 +124,7 @@ open class KotlinUSimpleReferenceExpression(
} }
class KotlinAccessorCallExpression( class KotlinAccessorCallExpression(
override val psi: KtSimpleNameExpression, override val sourcePsi: KtSimpleNameExpression,
override val uastParent: KotlinUSimpleReferenceExpression, override val uastParent: KotlinUSimpleReferenceExpression,
private val resolvedCall: ResolvedCall<*>, private val resolvedCall: ResolvedCall<*>,
private val accessorDescriptor: DeclarationDescriptor, private val accessorDescriptor: DeclarationDescriptor,
@@ -142,18 +142,18 @@ open class KotlinUSimpleReferenceExpression(
null null
} }
override val javaPsi: PsiElement? = null override val javaPsi: PsiElement? get() = null
override val sourcePsi: PsiElement? = psi override val psi: PsiElement? get() = sourcePsi
override val annotations: List<UAnnotation> override val annotations: List<UAnnotation>
get() = emptyList() get() = emptyList()
override val receiverType by lz { override val receiverType by lz {
val type = (resolvedCall.dispatchReceiver ?: resolvedCall.extensionReceiver)?.type ?: return@lz null val type = (resolvedCall.dispatchReceiver ?: resolvedCall.extensionReceiver)?.type ?: return@lz null
type.toPsiType(this, psi, boxed = true) type.toPsiType(this, sourcePsi, boxed = true)
} }
override val methodIdentifier: UIdentifier? by lazy { KotlinUIdentifier(psi.getReferencedNameElement(), this) } override val methodIdentifier: UIdentifier? by lazy { KotlinUIdentifier(sourcePsi.getReferencedNameElement(), this) }
override val classReference: UReferenceExpression? override val classReference: UReferenceExpression?
get() = null get() = null
@@ -174,11 +174,11 @@ open class KotlinUSimpleReferenceExpression(
get() = resolvedCall.typeArguments.size get() = resolvedCall.typeArguments.size
override val typeArguments by lz { override val typeArguments by lz {
resolvedCall.typeArguments.values.map { it.toPsiType(this, psi, true) } resolvedCall.typeArguments.values.map { it.toPsiType(this, sourcePsi, true) }
} }
override val returnType by lz { override val returnType by lz {
(accessorDescriptor as? CallableDescriptor)?.returnType?.toPsiType(this, psi, boxed = false) (accessorDescriptor as? CallableDescriptor)?.returnType?.toPsiType(this, sourcePsi, boxed = false)
} }
override val kind: UastCallKind override val kind: UastCallKind
@@ -186,7 +186,7 @@ open class KotlinUSimpleReferenceExpression(
override fun resolve(): PsiMethod? { override fun resolve(): PsiMethod? {
val source = accessorDescriptor.toSource() val source = accessorDescriptor.toSource()
return resolveSource(psi, accessorDescriptor, source) return resolveSource(sourcePsi, accessorDescriptor, source)
} }
} }
@@ -218,7 +218,7 @@ open class KotlinUSimpleReferenceExpression(
} }
class KotlinClassViaConstructorUSimpleReferenceExpression( class KotlinClassViaConstructorUSimpleReferenceExpression(
override val psi: KtCallElement, override val sourcePsi: KtCallElement,
override val identifier: String, override val identifier: String,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), USimpleNameReferenceExpression, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), USimpleNameReferenceExpression, KotlinUElementWithType {
@@ -226,13 +226,13 @@ class KotlinClassViaConstructorUSimpleReferenceExpression(
get() = (resolved as? PsiNamedElement)?.name get() = (resolved as? PsiNamedElement)?.name
private val resolved by lazy { private val resolved by lazy {
when (val resultingDescriptor = psi.getResolvedCall(psi.analyze())?.resultingDescriptor) { when (val resultingDescriptor = sourcePsi.getResolvedCall(sourcePsi.analyze())?.resultingDescriptor) {
is ConstructorDescriptor -> { is ConstructorDescriptor -> {
resultingDescriptor.constructedClass.toSource()?.getMaybeLightElement() resultingDescriptor.constructedClass.toSource()?.getMaybeLightElement()
?: (resultingDescriptor as? DeserializedCallableMemberDescriptor)?.let { resolveContainingDeserializedClass(psi, it) } ?: (resultingDescriptor as? DeserializedCallableMemberDescriptor)?.let { resolveContainingDeserializedClass(sourcePsi, it) }
} }
is SamConstructorDescriptor -> is SamConstructorDescriptor ->
(resultingDescriptor.returnType?.getFunctionalInterfaceType(this, psi) as? PsiClassType)?.resolve() (resultingDescriptor.returnType?.getFunctionalInterfaceType(this, sourcePsi) as? PsiClassType)?.resolve()
else -> null else -> null
} }
} }
@@ -38,18 +38,18 @@ import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
import org.jetbrains.uast.visitor.UastVisitor import org.jetbrains.uast.visitor.UastVisitor
open class KotlinUSimpleReferenceExpression( open class KotlinUSimpleReferenceExpression(
override val psi: KtSimpleNameExpression, override val sourcePsi: KtSimpleNameExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), USimpleNameReferenceExpression, KotlinUElementWithType, KotlinEvaluatableUElement { ) : KotlinAbstractUExpression(givenParent), USimpleNameReferenceExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
private val resolvedDeclaration: PsiElement? by lz { private val resolvedDeclaration: PsiElement? by lz {
psi.resolveCallToDeclaration()?.let { return@lz it } sourcePsi.resolveCallToDeclaration()?.let { return@lz it }
var declarationDescriptor = psi.analyze()[BindingContext.REFERENCE_TARGET, psi] ?: return@lz null var declarationDescriptor = sourcePsi.analyze()[BindingContext.REFERENCE_TARGET, sourcePsi] ?: return@lz null
if (declarationDescriptor is ImportedFromObjectCallableDescriptor<*>) { if (declarationDescriptor is ImportedFromObjectCallableDescriptor<*>) {
declarationDescriptor = declarationDescriptor.callableFromObject declarationDescriptor = declarationDescriptor.callableFromObject
} }
if (declarationDescriptor is SyntheticJavaPropertyDescriptor) { if (declarationDescriptor is SyntheticJavaPropertyDescriptor) {
declarationDescriptor = when (psi.readWriteAccess()) { declarationDescriptor = when (sourcePsi.readWriteAccess()) {
ReferenceAccess.WRITE, ReferenceAccess.READ_WRITE -> ReferenceAccess.WRITE, ReferenceAccess.READ_WRITE ->
declarationDescriptor.setMethod ?: declarationDescriptor.getMethod declarationDescriptor.setMethod ?: declarationDescriptor.getMethod
ReferenceAccess.READ -> declarationDescriptor.getMethod ReferenceAccess.READ -> declarationDescriptor.getMethod
@@ -57,17 +57,17 @@ open class KotlinUSimpleReferenceExpression(
} }
if (declarationDescriptor is PackageViewDescriptor) { if (declarationDescriptor is PackageViewDescriptor) {
return@lz JavaPsiFacade.getInstance(psi.project).findPackage(declarationDescriptor.fqName.asString()) return@lz JavaPsiFacade.getInstance(sourcePsi.project).findPackage(declarationDescriptor.fqName.asString())
} }
resolveToPsiClass(this, declarationDescriptor, psi)?.let { return@lz it } resolveToPsiClass(this, declarationDescriptor, sourcePsi)?.let { return@lz it }
if (declarationDescriptor is DeclarationDescriptorWithSource) { if (declarationDescriptor is DeclarationDescriptorWithSource) {
declarationDescriptor.source.getPsi()?.let { it.getMaybeLightElement() ?: it }?.let { return@lz it } declarationDescriptor.source.getPsi()?.let { it.getMaybeLightElement() ?: it }?.let { return@lz it }
} }
return@lz resolveDeserialized(psi, declarationDescriptor, psi.readWriteAccess()) return@lz resolveDeserialized(sourcePsi, declarationDescriptor, sourcePsi.readWriteAccess())
} }
override val identifier get() = psi.getReferencedName() override val identifier get() = sourcePsi.getReferencedName()
override fun resolve() = resolvedDeclaration override fun resolve() = resolvedDeclaration
@@ -77,7 +77,7 @@ open class KotlinUSimpleReferenceExpression(
override fun accept(visitor: UastVisitor) { override fun accept(visitor: UastVisitor) {
visitor.visitSimpleNameReferenceExpression(this) visitor.visitSimpleNameReferenceExpression(this)
if (psi.parent.destructuringDeclarationInitializer != true) { if (sourcePsi.parent.destructuringDeclarationInitializer != true) {
visitAccessorCalls(visitor) visitAccessorCalls(visitor)
} }
@@ -86,13 +86,13 @@ open class KotlinUSimpleReferenceExpression(
private fun visitAccessorCalls(visitor: UastVisitor) { private fun visitAccessorCalls(visitor: UastVisitor) {
// Visit Kotlin get-set synthetic Java property calls as function calls // Visit Kotlin get-set synthetic Java property calls as function calls
val bindingContext = psi.analyze() val bindingContext = sourcePsi.analyze()
val access = psi.readWriteAccess() val access = sourcePsi.readWriteAccess()
val resolvedCall = psi.getResolvedCall(bindingContext) val resolvedCall = sourcePsi.getResolvedCall(bindingContext)
val resultingDescriptor = resolvedCall?.resultingDescriptor as? SyntheticJavaPropertyDescriptor val resultingDescriptor = resolvedCall?.resultingDescriptor as? SyntheticJavaPropertyDescriptor
if (resultingDescriptor != null) { if (resultingDescriptor != null) {
val setterValue = if (access.isWrite) { val setterValue = if (access.isWrite) {
findAssignment(psi, psi.parent)?.right ?: run { findAssignment(sourcePsi, sourcePsi.parent)?.right ?: run {
visitor.afterVisitSimpleNameReferenceExpression(this) visitor.afterVisitSimpleNameReferenceExpression(this)
return return
} }
@@ -103,13 +103,13 @@ open class KotlinUSimpleReferenceExpression(
if (resolvedCall != null) { if (resolvedCall != null) {
if (access.isRead) { if (access.isRead) {
val getDescriptor = resultingDescriptor.getMethod val getDescriptor = resultingDescriptor.getMethod
KotlinAccessorCallExpression(psi, this, resolvedCall, getDescriptor, null).accept(visitor) KotlinAccessorCallExpression(sourcePsi, this, resolvedCall, getDescriptor, null).accept(visitor)
} }
if (access.isWrite && setterValue != null) { if (access.isWrite && setterValue != null) {
val setDescriptor = resultingDescriptor.setMethod val setDescriptor = resultingDescriptor.setMethod
if (setDescriptor != null) { if (setDescriptor != null) {
KotlinAccessorCallExpression(psi, this, resolvedCall, setDescriptor, setterValue).accept(visitor) KotlinAccessorCallExpression(sourcePsi, this, resolvedCall, setDescriptor, setterValue).accept(visitor)
} }
} }
} }
@@ -124,7 +124,7 @@ open class KotlinUSimpleReferenceExpression(
} }
class KotlinAccessorCallExpression( class KotlinAccessorCallExpression(
override val psi: KtSimpleNameExpression, override val sourcePsi: KtSimpleNameExpression,
override val uastParent: KotlinUSimpleReferenceExpression, override val uastParent: KotlinUSimpleReferenceExpression,
private val resolvedCall: ResolvedCall<*>, private val resolvedCall: ResolvedCall<*>,
private val accessorDescriptor: DeclarationDescriptor, private val accessorDescriptor: DeclarationDescriptor,
@@ -142,18 +142,18 @@ open class KotlinUSimpleReferenceExpression(
null null
} }
override val javaPsi: PsiElement? = null override val javaPsi: PsiElement? get() = null
override val sourcePsi: PsiElement? = psi override val psi: PsiElement? get() = sourcePsi
override val annotations: List<UAnnotation> override val annotations: List<UAnnotation>
get() = emptyList() get() = emptyList()
override val receiverType by lz { override val receiverType by lz {
val type = (resolvedCall.dispatchReceiver ?: resolvedCall.extensionReceiver)?.type ?: return@lz null val type = (resolvedCall.dispatchReceiver ?: resolvedCall.extensionReceiver)?.type ?: return@lz null
type.toPsiType(this, psi, boxed = true) type.toPsiType(this, sourcePsi, boxed = true)
} }
override val methodIdentifier: UIdentifier? by lazy { KotlinUIdentifier(psi.getReferencedNameElement(), this) } override val methodIdentifier: UIdentifier? by lazy { KotlinUIdentifier(sourcePsi.getReferencedNameElement(), this) }
override val classReference: UReferenceExpression? override val classReference: UReferenceExpression?
get() = null get() = null
@@ -174,11 +174,11 @@ open class KotlinUSimpleReferenceExpression(
get() = resolvedCall.typeArguments.size get() = resolvedCall.typeArguments.size
override val typeArguments by lz { override val typeArguments by lz {
resolvedCall.typeArguments.values.map { it.toPsiType(this, psi, true) } resolvedCall.typeArguments.values.map { it.toPsiType(this, sourcePsi, true) }
} }
override val returnType by lz { override val returnType by lz {
(accessorDescriptor as? CallableDescriptor)?.returnType?.toPsiType(this, psi, boxed = false) (accessorDescriptor as? CallableDescriptor)?.returnType?.toPsiType(this, sourcePsi, boxed = false)
} }
override val kind: UastCallKind override val kind: UastCallKind
@@ -186,7 +186,7 @@ open class KotlinUSimpleReferenceExpression(
override fun resolve(): PsiMethod? { override fun resolve(): PsiMethod? {
val source = accessorDescriptor.toSource() val source = accessorDescriptor.toSource()
return resolveSource(psi, accessorDescriptor, source) return resolveSource(sourcePsi, accessorDescriptor, source)
} }
} }
@@ -218,7 +218,7 @@ open class KotlinUSimpleReferenceExpression(
} }
class KotlinClassViaConstructorUSimpleReferenceExpression( class KotlinClassViaConstructorUSimpleReferenceExpression(
override val psi: KtCallElement, override val sourcePsi: KtCallElement,
override val identifier: String, override val identifier: String,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), USimpleNameReferenceExpression, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), USimpleNameReferenceExpression, KotlinUElementWithType {
@@ -226,13 +226,13 @@ class KotlinClassViaConstructorUSimpleReferenceExpression(
get() = (resolved as? PsiNamedElement)?.name get() = (resolved as? PsiNamedElement)?.name
private val resolved by lazy { private val resolved by lazy {
when (val resultingDescriptor = psi.getResolvedCall(psi.analyze())?.resultingDescriptor) { when (val resultingDescriptor = sourcePsi.getResolvedCall(sourcePsi.analyze())?.resultingDescriptor) {
is ConstructorDescriptor -> { is ConstructorDescriptor -> {
resultingDescriptor.constructedClass.toSource()?.getMaybeLightElement() resultingDescriptor.constructedClass.toSource()?.getMaybeLightElement()
?: (resultingDescriptor as? DeserializedCallableMemberDescriptor)?.let { resolveContainingDeserializedClass(psi, it) } ?: (resultingDescriptor as? DeserializedCallableMemberDescriptor)?.let { resolveContainingDeserializedClass(sourcePsi, it) }
} }
is SamConstructorDescriptor -> is SamConstructorDescriptor ->
(resultingDescriptor.returnType?.getFunctionalInterfaceType(this, psi) as? PsiClassType)?.resolve() (resultingDescriptor.returnType?.getFunctionalInterfaceType(this, sourcePsi) as? PsiClassType)?.resolve()
else -> null else -> null
} }
} }
@@ -25,14 +25,14 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
class KotlinUSuperExpression( class KotlinUSuperExpression(
override val psi: KtSuperExpression, override val sourcePsi: KtSuperExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), USuperExpression, DelegatedMultiResolve, KotlinUElementWithType, KotlinEvaluatableUElement { ) : KotlinAbstractUExpression(givenParent), USuperExpression, DelegatedMultiResolve, KotlinUElementWithType, KotlinEvaluatableUElement {
override val label: String? override val label: String?
get() = psi.getLabelName() get() = sourcePsi.getLabelName()
override val labelIdentifier: UIdentifier? override val labelIdentifier: UIdentifier?
get() = psi.getTargetLabel()?.let { KotlinUIdentifier(it, this) } get() = sourcePsi.getTargetLabel()?.let { KotlinUIdentifier(it, this) }
override fun resolve() = psi.analyze()[BindingContext.LABEL_TARGET, psi.getTargetLabel()] override fun resolve() = sourcePsi.analyze()[BindingContext.LABEL_TARGET, sourcePsi.getTargetLabel()]
} }
@@ -25,16 +25,16 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
import org.jetbrains.uast.kotlin.kinds.KotlinSpecialExpressionKinds import org.jetbrains.uast.kotlin.kinds.KotlinSpecialExpressionKinds
class KotlinUSwitchExpression( class KotlinUSwitchExpression(
override val psi: KtWhenExpression, override val sourcePsi: KtWhenExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), USwitchExpression, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), USwitchExpression, KotlinUElementWithType {
override val expression by lz { KotlinConverter.convertOrNull(psi.subjectExpression, this) } override val expression by lz { KotlinConverter.convertOrNull(sourcePsi.subjectExpression, this) }
override val body: UExpressionList by lz { override val body: UExpressionList by lz {
object : KotlinUExpressionList(psi, KotlinSpecialExpressionKinds.WHEN, this@KotlinUSwitchExpression) { object : KotlinUExpressionList(sourcePsi, KotlinSpecialExpressionKinds.WHEN, this@KotlinUSwitchExpression) {
override fun asRenderString() = expressions.joinToString("\n") { it.asRenderString().withMargin } override fun asRenderString() = expressions.joinToString("\n") { it.asRenderString().withMargin }
}.apply { }.apply {
expressions = this@KotlinUSwitchExpression.psi.entries.map { KotlinUSwitchEntry(it, this) } expressions = this@KotlinUSwitchExpression.sourcePsi.entries.map { KotlinUSwitchEntry(it, this) }
} }
} }
@@ -50,22 +50,22 @@ class KotlinUSwitchExpression(
} }
class KotlinUSwitchEntry( class KotlinUSwitchEntry(
override val psi: KtWhenEntry, override val sourcePsi: KtWhenEntry,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), USwitchClauseExpressionWithBody { ) : KotlinAbstractUExpression(givenParent), USwitchClauseExpressionWithBody {
override val caseValues by lz { override val caseValues by lz {
psi.conditions.map { KotlinConverter.convertWhenCondition(it, this, DEFAULT_EXPRESSION_TYPES_LIST) ?: UastEmptyExpression(null) } sourcePsi.conditions.map { KotlinConverter.convertWhenCondition(it, this, DEFAULT_EXPRESSION_TYPES_LIST) ?: UastEmptyExpression(null) }
} }
override val body: UExpressionList by lz { override val body: UExpressionList by lz {
object : KotlinUExpressionList(psi, KotlinSpecialExpressionKinds.WHEN_ENTRY, this@KotlinUSwitchEntry) { object : KotlinUExpressionList(sourcePsi, KotlinSpecialExpressionKinds.WHEN_ENTRY, this@KotlinUSwitchEntry) {
override fun asRenderString() = buildString { override fun asRenderString() = buildString {
appendln("{") appendln("{")
expressions.forEach { appendln(it.asRenderString().withMargin) } expressions.forEach { appendln(it.asRenderString().withMargin) }
appendln("}") appendln("}")
} }
}.apply { }.apply {
val exprPsi = this@KotlinUSwitchEntry.psi.expression val exprPsi = this@KotlinUSwitchEntry.sourcePsi.expression
val userExpressions = when (exprPsi) { val userExpressions = when (exprPsi) {
is KtBlockExpression -> exprPsi.statements.map { KotlinConverter.convertOrEmpty(it, this) } is KtBlockExpression -> exprPsi.statements.map { KotlinConverter.convertOrEmpty(it, this) }
else -> listOf(KotlinConverter.convertOrEmpty(exprPsi, this)) else -> listOf(KotlinConverter.convertOrEmpty(exprPsi, this))
@@ -86,7 +86,7 @@ class KotlinUSwitchEntry(
} }
override fun convertParent(): UElement? { override fun convertParent(): UElement? {
val result = KotlinConverter.unwrapElements(psi.parent)?.let { parentUnwrapped -> val result = KotlinConverter.unwrapElements(sourcePsi.parent)?.let { parentUnwrapped ->
KotlinUastLanguagePlugin().convertElementWithParent(parentUnwrapped, null) KotlinUastLanguagePlugin().convertElementWithParent(parentUnwrapped, null)
} }
return (result as? KotlinUSwitchExpression)?.body ?: result return (result as? KotlinUSwitchExpression)?.body ?: result
@@ -25,16 +25,16 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
import org.jetbrains.uast.kotlin.kinds.KotlinSpecialExpressionKinds import org.jetbrains.uast.kotlin.kinds.KotlinSpecialExpressionKinds
class KotlinUSwitchExpression( class KotlinUSwitchExpression(
override val psi: KtWhenExpression, override val sourcePsi: KtWhenExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), USwitchExpression, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), USwitchExpression, KotlinUElementWithType {
override val expression by lz { KotlinConverter.convertOrNull(psi.subjectExpression, this) } override val expression by lz { KotlinConverter.convertOrNull(sourcePsi.subjectExpression, this) }
override val body: UExpressionList by lz { override val body: UExpressionList by lz {
object : KotlinUExpressionList(psi, KotlinSpecialExpressionKinds.WHEN, this@KotlinUSwitchExpression) { object : KotlinUExpressionList(sourcePsi, KotlinSpecialExpressionKinds.WHEN, this@KotlinUSwitchExpression) {
override fun asRenderString() = expressions.joinToString("\n") { it.asRenderString().withMargin } override fun asRenderString() = expressions.joinToString("\n") { it.asRenderString().withMargin }
}.apply { }.apply {
expressions = this@KotlinUSwitchExpression.psi.entries.map { KotlinUSwitchEntry(it, this) } expressions = this@KotlinUSwitchExpression.sourcePsi.entries.map { KotlinUSwitchEntry(it, this) }
} }
} }
@@ -50,22 +50,22 @@ class KotlinUSwitchExpression(
} }
class KotlinUSwitchEntry( class KotlinUSwitchEntry(
override val psi: KtWhenEntry, override val sourcePsi: KtWhenEntry,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), USwitchClauseExpressionWithBody { ) : KotlinAbstractUExpression(givenParent), USwitchClauseExpressionWithBody {
override val caseValues by lz { override val caseValues by lz {
psi.conditions.map { KotlinConverter.convertWhenCondition(it, this) ?: UastEmptyExpression } sourcePsi.conditions.map { KotlinConverter.convertWhenCondition(it, this) ?: UastEmptyExpression }
} }
override val body: UExpressionList by lz { override val body: UExpressionList by lz {
object : KotlinUExpressionList(psi, KotlinSpecialExpressionKinds.WHEN_ENTRY, this@KotlinUSwitchEntry) { object : KotlinUExpressionList(sourcePsi, KotlinSpecialExpressionKinds.WHEN_ENTRY, this@KotlinUSwitchEntry) {
override fun asRenderString() = buildString { override fun asRenderString() = buildString {
appendln("{") appendln("{")
expressions.forEach { appendln(it.asRenderString().withMargin) } expressions.forEach { appendln(it.asRenderString().withMargin) }
appendln("}") appendln("}")
} }
}.apply { }.apply {
val exprPsi = this@KotlinUSwitchEntry.psi.expression val exprPsi = this@KotlinUSwitchEntry.sourcePsi.expression
val userExpressions = when (exprPsi) { val userExpressions = when (exprPsi) {
is KtBlockExpression -> exprPsi.statements.map { KotlinConverter.convertOrEmpty(it, this) } is KtBlockExpression -> exprPsi.statements.map { KotlinConverter.convertOrEmpty(it, this) }
else -> listOf(KotlinConverter.convertOrEmpty(exprPsi, this)) else -> listOf(KotlinConverter.convertOrEmpty(exprPsi, this))
@@ -86,7 +86,7 @@ class KotlinUSwitchEntry(
} }
override fun convertParent(): UElement? { override fun convertParent(): UElement? {
val result = KotlinConverter.unwrapElements(psi.parent)?.let { parentUnwrapped -> val result = KotlinConverter.unwrapElements(sourcePsi.parent)?.let { parentUnwrapped ->
KotlinUastLanguagePlugin().convertElementWithParent(parentUnwrapped, null) KotlinUastLanguagePlugin().convertElementWithParent(parentUnwrapped, null)
} }
return (result as? KotlinUSwitchExpression)?.body ?: result return (result as? KotlinUSwitchExpression)?.body ?: result
@@ -25,14 +25,14 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
class KotlinUThisExpression( class KotlinUThisExpression(
override val psi: KtThisExpression, override val sourcePsi: KtThisExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UThisExpression, DelegatedMultiResolve, KotlinUElementWithType, KotlinEvaluatableUElement { ) : KotlinAbstractUExpression(givenParent), UThisExpression, DelegatedMultiResolve, KotlinUElementWithType, KotlinEvaluatableUElement {
override val label: String? override val label: String?
get() = psi.getLabelName() get() = sourcePsi.getLabelName()
override val labelIdentifier: UIdentifier? override val labelIdentifier: UIdentifier?
get() = psi.getTargetLabel()?.let { KotlinUIdentifier(it, this) } get() = sourcePsi.getTargetLabel()?.let { KotlinUIdentifier(it, this) }
override fun resolve() = psi.analyze()[BindingContext.LABEL_TARGET, psi.getTargetLabel()] override fun resolve() = sourcePsi.analyze()[BindingContext.LABEL_TARGET, sourcePsi.getTargetLabel()]
} }
@@ -25,14 +25,14 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
class KotlinUThisExpression( class KotlinUThisExpression(
override val psi: KtThisExpression, override val sourcePsi: KtThisExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UThisExpression, DelegatedMultiResolve, KotlinUElementWithType, KotlinEvaluatableUElement { ) : KotlinAbstractUExpression(givenParent), UThisExpression, DelegatedMultiResolve, KotlinUElementWithType, KotlinEvaluatableUElement {
override val label: String? override val label: String?
get() = psi.getLabelName() get() = sourcePsi.getLabelName()
override val labelIdentifier: UIdentifier? override val labelIdentifier: UIdentifier?
get() = psi.getTargetLabel()?.let { KotlinUIdentifier(it, this) } get() = sourcePsi.getTargetLabel()?.let { KotlinUIdentifier(it, this) }
override fun resolve() = psi.analyze()[BindingContext.LABEL_TARGET, psi.getTargetLabel()] override fun resolve() = sourcePsi.analyze()[BindingContext.LABEL_TARGET, sourcePsi.getTargetLabel()]
} }
@@ -21,8 +21,8 @@ import org.jetbrains.uast.UElement
import org.jetbrains.uast.UThrowExpression import org.jetbrains.uast.UThrowExpression
class KotlinUThrowExpression( class KotlinUThrowExpression(
override val psi: KtThrowExpression, override val sourcePsi: KtThrowExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UThrowExpression, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), UThrowExpression, KotlinUElementWithType {
override val thrownExpression by lz { KotlinConverter.convertOrEmpty(psi.thrownExpression, this) } override val thrownExpression by lz { KotlinConverter.convertOrEmpty(sourcePsi.thrownExpression, this) }
} }
@@ -21,13 +21,13 @@ import org.jetbrains.uast.*
import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
class KotlinUTryExpression( class KotlinUTryExpression(
override val psi: KtTryExpression, override val sourcePsi: KtTryExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UTryExpression, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), UTryExpression, KotlinUElementWithType {
override val tryClause by lz { KotlinConverter.convertOrEmpty(psi.tryBlock, this) } override val tryClause by lz { KotlinConverter.convertOrEmpty(sourcePsi.tryBlock, this) }
override val catchClauses by lz { psi.catchClauses.map { KotlinUCatchClause(it, this) } } override val catchClauses by lz { sourcePsi.catchClauses.map { KotlinUCatchClause(it, this) } }
override val finallyClause by lz { override val finallyClause by lz {
psi.finallyBlock?.finalExpression?.let { sourcePsi.finallyBlock?.finalExpression?.let {
KotlinConverter.convertExpression( KotlinConverter.convertExpression(
it, it,
this, this,
@@ -24,12 +24,12 @@ import org.jetbrains.uast.UVariable
import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
class KotlinUTryExpression( class KotlinUTryExpression(
override val psi: KtTryExpression, override val sourcePsi: KtTryExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UTryExpression, KotlinUElementWithType { ) : KotlinAbstractUExpression(givenParent), UTryExpression, KotlinUElementWithType {
override val tryClause by lz { KotlinConverter.convertOrEmpty(psi.tryBlock, this) } override val tryClause by lz { KotlinConverter.convertOrEmpty(sourcePsi.tryBlock, this) }
override val catchClauses by lz { psi.catchClauses.map { KotlinUCatchClause(it, this) } } override val catchClauses by lz { sourcePsi.catchClauses.map { KotlinUCatchClause(it, this) } }
override val finallyClause by lz { psi.finallyBlock?.finalExpression?.let { KotlinConverter.convertExpression(it, this) } } override val finallyClause by lz { sourcePsi.finallyBlock?.finalExpression?.let { KotlinConverter.convertExpression(it, this) } }
override val resourceVariables: List<UVariable> override val resourceVariables: List<UVariable>
get() = emptyList() get() = emptyList()
@@ -22,19 +22,19 @@ import org.jetbrains.uast.UElement
import org.jetbrains.uast.UastBinaryExpressionWithTypeKind import org.jetbrains.uast.UastBinaryExpressionWithTypeKind
class KotlinUTypeCheckExpression( class KotlinUTypeCheckExpression(
override val psi: KtIsExpression, override val sourcePsi: KtIsExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UBinaryExpressionWithType, KotlinUElementWithType, KotlinEvaluatableUElement { ) : KotlinAbstractUExpression(givenParent), UBinaryExpressionWithType, KotlinUElementWithType, KotlinEvaluatableUElement {
override val operand by lz { KotlinConverter.convertOrEmpty(psi.leftHandSide, this) } override val operand by lz { KotlinConverter.convertOrEmpty(sourcePsi.leftHandSide, this) }
override val type by lz { psi.typeReference.toPsiType(this) } override val type by lz { sourcePsi.typeReference.toPsiType(this) }
override val typeReference = psi.typeReference?.let { override val typeReference = sourcePsi.typeReference?.let {
LazyKotlinUTypeReferenceExpression(it, this) { it.toPsiType(this) } LazyKotlinUTypeReferenceExpression(it, this) { it.toPsiType(this) }
} }
override val operationKind = override val operationKind =
if(psi.isNegated) if(sourcePsi.isNegated)
KotlinBinaryExpressionWithTypeKinds.NEGATED_INSTANCE_CHECK KotlinBinaryExpressionWithTypeKinds.NEGATED_INSTANCE_CHECK
else else
UastBinaryExpressionWithTypeKind.INSTANCE_CHECK UastBinaryExpressionWithTypeKind.INSTANCE_CHECK
@@ -14,11 +14,11 @@ open class KotlinUTypeReferenceExpression(
class LazyKotlinUTypeReferenceExpression( class LazyKotlinUTypeReferenceExpression(
override val psi: KtTypeReference, override val sourcePsi: KtTypeReference,
givenParent: UElement?, givenParent: UElement?,
private val typeSupplier: (() -> PsiType)? = null private val typeSupplier: (() -> PsiType)? = null
) : KotlinAbstractUExpression(givenParent), UTypeReferenceExpression { ) : KotlinAbstractUExpression(givenParent), UTypeReferenceExpression {
override val type: PsiType by lz { override val type: PsiType by lz {
typeSupplier?.invoke() ?: psi.toPsiType(uastParent ?: this) typeSupplier?.invoke() ?: sourcePsi.toPsiType(uastParent ?: this)
} }
} }
@@ -23,11 +23,11 @@ import org.jetbrains.uast.UWhileExpression
import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
class KotlinUWhileExpression( class KotlinUWhileExpression(
override val psi: KtWhileExpression, override val sourcePsi: KtWhileExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UWhileExpression { ) : KotlinAbstractUExpression(givenParent), UWhileExpression {
override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) } override val condition by lz { KotlinConverter.convertOrEmpty(sourcePsi.condition, this) }
override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) } override val body by lz { KotlinConverter.convertOrEmpty(sourcePsi.body, this) }
override val whileIdentifier: UIdentifier override val whileIdentifier: UIdentifier
get() = KotlinUIdentifier(null, this) get() = KotlinUIdentifier(null, this)
@@ -13,12 +13,12 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
internal class KotlinLocalFunctionUVariable( internal class KotlinLocalFunctionUVariable(
val function: KtFunction, val function: KtFunction,
override val psi: PsiVariable, override val javaPsi: PsiVariable,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUElement(givenParent), UVariableExPlaceHolder, PsiVariable by psi { ) : KotlinAbstractUElement(givenParent), UVariableExPlaceHolder, PsiVariable by javaPsi {
override val javaPsi = psi override val psi get() = javaPsi
override val sourcePsi: PsiElement? = (psi as? UastKotlinPsiVariable?)?.ktElement ?: psi override val sourcePsi: PsiElement? = (javaPsi as? UastKotlinPsiVariable?)?.ktElement ?: javaPsi
override val uastInitializer: UExpression? by lz { override val uastInitializer: UExpression? by lz {
createLocalFunctionLambdaExpression(function, this) createLocalFunctionLambdaExpression(function, this)
@@ -37,16 +37,16 @@ internal class KotlinLocalFunctionUVariable(
private class KotlinLocalFunctionULambdaExpression( private class KotlinLocalFunctionULambdaExpression(
override val psi: KtFunction, override val sourcePsi: KtFunction,
givenParent: UElement? givenParent: UElement?
): KotlinAbstractUExpression(givenParent), ULambdaExpression { ): KotlinAbstractUExpression(givenParent), ULambdaExpression {
override val functionalInterfaceType: PsiType? = null override val functionalInterfaceType: PsiType? = null
override val body by lz { KotlinConverter.convertOrEmpty(psi.bodyExpression, this) } override val body by lz { KotlinConverter.convertOrEmpty(sourcePsi.bodyExpression, this) }
override val valueParameters by lz { override val valueParameters by lz {
psi.valueParameters.mapIndexed { i, p -> sourcePsi.valueParameters.mapIndexed { i, p ->
KotlinUParameter(UastKotlinPsiParameter.create(p, psi, this, i), p, this) KotlinUParameter(UastKotlinPsiParameter.create(p, sourcePsi, this, i), p, this)
} }
} }
@@ -21,8 +21,8 @@ import org.jetbrains.uast.UElement
import org.jetbrains.uast.UExpression import org.jetbrains.uast.UExpression
class UnknownKotlinExpression( class UnknownKotlinExpression(
override val psi: KtExpression, override val sourcePsi: KtExpression,
givenParent: UElement? givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UExpression { ) : KotlinAbstractUExpression(givenParent), UExpression {
override fun asLogString() = "[!] UnknownKotlinExpression ($psi)" override fun asLogString() = "[!] UnknownKotlinExpression ($sourcePsi)"
} }
@@ -28,7 +28,7 @@ interface KotlinUElementWithComments : JvmDeclarationUElementPlaceholder {
override val comments: List<UComment> override val comments: List<UComment>
get() { get() {
val psi = psi ?: return emptyList() val psi = sourcePsi ?: return emptyList()
val childrenComments = psi.children.filterIsInstance<PsiComment>().map { UComment(it, this) } val childrenComments = psi.children.filterIsInstance<PsiComment>().map { UComment(it, this) }
if (this !is UExpression) return childrenComments if (this !is UExpression) return childrenComments
val childrenAndSiblingComments = childrenComments + val childrenAndSiblingComments = childrenComments +
@@ -223,7 +223,7 @@ private fun getMethodSignatureFromDescriptor(context: KtElement, descriptor: Cal
internal fun <T> lz(initializer: () -> T) = lazy(LazyThreadSafetyMode.SYNCHRONIZED, initializer) internal fun <T> lz(initializer: () -> T) = lazy(LazyThreadSafetyMode.SYNCHRONIZED, initializer)
internal fun KotlinType.toPsiType(source: UElement, element: KtElement, boxed: Boolean): PsiType = internal fun KotlinType.toPsiType(source: UElement, element: KtElement, boxed: Boolean): PsiType =
toPsiType(source.getParentOfType<UDeclaration>(false)?.psi, element, boxed) toPsiType(source.getParentOfType<UDeclaration>(false)?.javaPsi as? PsiModifierListOwner, element, boxed)
internal fun KotlinType.toPsiType(lightDeclaration: PsiModifierListOwner?, context: KtElement, boxed: Boolean): PsiType { internal fun KotlinType.toPsiType(lightDeclaration: PsiModifierListOwner?, context: KtElement, boxed: Boolean): PsiType {
if (this.isError) return UastErrorType if (this.isError) return UastErrorType
@@ -363,7 +363,7 @@ internal fun KtElement.analyze(): BindingContext {
} }
internal inline fun <reified T : UDeclaration, reified P : PsiElement> unwrap(element: P): P { internal inline fun <reified T : UDeclaration, reified P : PsiElement> unwrap(element: P): P {
val unwrapped = if (element is T) element.psi else element val unwrapped = if (element is T) element.javaPsi else element
assert(unwrapped !is UElement) assert(unwrapped !is UElement)
return unwrapped as P return unwrapped as P
} }
@@ -381,23 +381,23 @@ internal fun KotlinType.getFunctionalInterfaceType(source: UElement, element: Kt
takeIf { it.isInterface() && !it.isBuiltinFunctionalTypeOrSubtype }?.toPsiType(source, element, false) takeIf { it.isInterface() && !it.isBuiltinFunctionalTypeOrSubtype }?.toPsiType(source, element, false)
internal fun KotlinULambdaExpression.getFunctionalInterfaceType(): PsiType? { internal fun KotlinULambdaExpression.getFunctionalInterfaceType(): PsiType? {
val parent = psi.parent val parent = sourcePsi.parent
if (parent is KtBinaryExpressionWithTypeRHS) return parent.right?.getType()?.getFunctionalInterfaceType(this, psi) if (parent is KtBinaryExpressionWithTypeRHS) return parent.right?.getType()?.getFunctionalInterfaceType(this, sourcePsi)
if (parent is KtValueArgument) run { if (parent is KtValueArgument) run {
val callExpression = parent.parents.take(2).firstIsInstanceOrNull<KtCallExpression>() ?: return@run val callExpression = parent.parents.take(2).firstIsInstanceOrNull<KtCallExpression>() ?: return@run
val resolvedCall = callExpression.getResolvedCall(callExpression.analyze()) ?: return@run val resolvedCall = callExpression.getResolvedCall(callExpression.analyze()) ?: return@run
val candidateDescriptor = resolvedCall.candidateDescriptor as? SyntheticMemberDescriptor<*> ?: return@run val candidateDescriptor = resolvedCall.candidateDescriptor as? SyntheticMemberDescriptor<*> ?: return@run
when (candidateDescriptor) { when (candidateDescriptor) {
is SamConstructorDescriptor -> return candidateDescriptor.returnType?.getFunctionalInterfaceType(this, psi) is SamConstructorDescriptor -> return candidateDescriptor.returnType?.getFunctionalInterfaceType(this, sourcePsi)
is SamAdapterDescriptor<*>, is SamAdapterExtensionFunctionDescriptor -> { is SamAdapterDescriptor<*>, is SamAdapterExtensionFunctionDescriptor -> {
val index = (resolvedCall.getArgumentMapping(parent) as? ArgumentMatch)?.valueParameter?.index ?: return@run val index = (resolvedCall.getArgumentMapping(parent) as? ArgumentMatch)?.valueParameter?.index ?: return@run
val functionDescriptor = candidateDescriptor.baseDescriptorForSynthetic as? FunctionDescriptor ?: return@run val functionDescriptor = candidateDescriptor.baseDescriptorForSynthetic as? FunctionDescriptor ?: return@run
val parameterDescriptor = functionDescriptor.valueParameters.getOrNull(index) ?: return@run val parameterDescriptor = functionDescriptor.valueParameters.getOrNull(index) ?: return@run
return parameterDescriptor.type.getFunctionalInterfaceType(this, psi) return parameterDescriptor.type.getFunctionalInterfaceType(this, sourcePsi)
} }
} }
} }
return psi.getExpectedType()?.getFunctionalInterfaceType(this, psi) return sourcePsi.getExpectedType()?.getFunctionalInterfaceType(this, sourcePsi)
} }
internal fun unwrapFakeFileForLightClass(file: PsiFile): PsiFile = (file as? FakeFileForLightClass)?.ktFile ?: file internal fun unwrapFakeFileForLightClass(file: PsiFile): PsiFile = (file as? FakeFileForLightClass)?.ktFile ?: file
@@ -29,7 +29,7 @@ class UastKotlinPsiParameter(
) : LightParameter(name, type, parent, language, isVarArgs) { ) : LightParameter(name, type, parent, language, isVarArgs) {
companion object { companion object {
fun create(parameter: KtParameter, parent: PsiElement, containingElement: UElement, index: Int): PsiParameter { fun create(parameter: KtParameter, parent: PsiElement, containingElement: UElement, index: Int): PsiParameter {
val psiParent = containingElement.getParentOfType<UDeclaration>()?.psi ?: parent val psiParent = containingElement.getParentOfType<UDeclaration>()?.javaPsi ?: parent
return UastKotlinPsiParameter( return UastKotlinPsiParameter(
parameter.name ?: "p$index", parameter.name ?: "p$index",
(parameter.analyze()[BindingContext.DECLARATION_TO_DESCRIPTOR, parameter] as? VariableDescriptor) (parameter.analyze()[BindingContext.DECLARATION_TO_DESCRIPTOR, parameter] as? VariableDescriptor)
@@ -76,7 +76,7 @@ class UastKotlinPsiVariable private constructor(
containingElement: KotlinUDeclarationsExpression, containingElement: KotlinUDeclarationsExpression,
initializer: KtExpression? = null initializer: KtExpression? = null
): PsiLocalVariable { ): PsiLocalVariable {
val psi = containingElement.psiAnchor ?: containingElement.psi val psi = containingElement.psiAnchor ?: containingElement.sourcePsi
val psiParent = psi?.getNonStrictParentOfType<KtDeclaration>() ?: parent val psiParent = psi?.getNonStrictParentOfType<KtDeclaration>() ?: parent
val initializerExpression = initializer ?: declaration.initializer val initializerExpression = initializer ?: declaration.initializer
return UastKotlinPsiVariable( return UastKotlinPsiVariable(