Uast: cleaunp warnings (but some still remains)
This commit is contained in:
@@ -40,7 +40,8 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : Kotl
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
if (psi is KtLightClassForLocalDeclaration) {
|
||||
@@ -221,12 +222,12 @@ abstract class KotlinAbstractUExpression(givenParent: UElement?) :
|
||||
|
||||
override val javaPsi: PsiElement? = null
|
||||
|
||||
override val sourcePsi
|
||||
get() = psi
|
||||
override val psi
|
||||
get() = sourcePsi
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() {
|
||||
val annotatedExpression = psi?.parent as? KtAnnotatedExpression ?: return emptyList()
|
||||
val annotatedExpression = sourcePsi?.parent as? KtAnnotatedExpression ?: return emptyList()
|
||||
return annotatedExpression.annotationEntries.map { KotlinUAnnotation(it, this) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : Kotl
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
if (psi is KtLightClassForLocalDeclaration) {
|
||||
@@ -110,7 +111,7 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : Kotl
|
||||
|
||||
val result = doConvertParent(this, parent)
|
||||
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
|
||||
@@ -217,12 +218,12 @@ abstract class KotlinAbstractUExpression(givenParent: UElement?) :
|
||||
|
||||
override val javaPsi: PsiElement? = null
|
||||
|
||||
override val sourcePsi
|
||||
get() = psi
|
||||
override val psi
|
||||
get() = sourcePsi
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() {
|
||||
val annotatedExpression = psi?.parent as? KtAnnotatedExpression ?: return emptyList()
|
||||
val annotatedExpression = sourcePsi?.parent as? KtAnnotatedExpression ?: return emptyList()
|
||||
return annotatedExpression.annotationEntries.map { KotlinUAnnotation(it, this) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin {
|
||||
return when (element) {
|
||||
is KotlinUSimpleReferenceExpression.KotlinAccessorCallExpression -> element.setterValue != null
|
||||
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
|
||||
}
|
||||
else -> false
|
||||
@@ -239,7 +239,7 @@ internal object KotlinConverter {
|
||||
}
|
||||
}
|
||||
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 KtWhenCondition -> convertWhenCondition(element, givenParent, expectedTypes)
|
||||
is KtTypeReference -> el<UTypeReferenceExpression> { LazyKotlinUTypeReferenceExpression(element, givenParent) }
|
||||
@@ -341,7 +341,7 @@ internal object KotlinConverter {
|
||||
val initializer = psiFactory.createAnalyzableExpression("${tempAssignment.name}.component${i + 1}()",
|
||||
expression.containingFile)
|
||||
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
|
||||
}
|
||||
@@ -387,7 +387,7 @@ internal object KotlinConverter {
|
||||
KotlinUDeclarationsExpression(givenParent).apply {
|
||||
declarations = listOf(KotlinUClass.create(lightClass, this))
|
||||
}
|
||||
} ?: UastEmptyExpression(null)
|
||||
} ?: UastEmptyExpression(givenParent)
|
||||
}
|
||||
is KtFunction -> if (expression.name.isNullOrEmpty()) {
|
||||
expr<ULambdaExpression>(build(::createLocalFunctionLambdaExpression))
|
||||
@@ -433,7 +433,7 @@ internal object KotlinConverter {
|
||||
is KtWhenConditionWithExpression ->
|
||||
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 {
|
||||
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? {
|
||||
@@ -656,7 +656,7 @@ private fun convertVariablesDeclaration(
|
||||
val declarationsExpression = parent as? KotlinUDeclarationsExpression
|
||||
?: psi.parent.toUElementOfType<UDeclarationsExpression>() as? KotlinUDeclarationsExpression
|
||||
?: 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(
|
||||
UastKotlinPsiVariable.create(psi, parentPsiElement, declarationsExpression), psi, declarationsExpression) { annotationParent ->
|
||||
psi.annotationEntries.map { KotlinUAnnotation(it, annotationParent) }
|
||||
|
||||
@@ -128,7 +128,7 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin {
|
||||
return when (element) {
|
||||
is KotlinUSimpleReferenceExpression.KotlinAccessorCallExpression -> element.setterValue != null
|
||||
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
|
||||
}
|
||||
else -> false
|
||||
@@ -166,7 +166,10 @@ internal object KotlinConverter {
|
||||
givenParent: UElement?,
|
||||
requiredType: Class<out 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) {
|
||||
@@ -266,7 +269,10 @@ internal object KotlinConverter {
|
||||
givenParent: UElement?,
|
||||
requiredType: Class<out UElement>? = null): 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) {
|
||||
@@ -292,7 +298,7 @@ internal object KotlinConverter {
|
||||
val initializer = psiFactory.createAnalyzableExpression("${tempAssignment.name}.component${i + 1}()",
|
||||
expression.containingFile)
|
||||
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
|
||||
}
|
||||
@@ -338,7 +344,7 @@ internal object KotlinConverter {
|
||||
KotlinUDeclarationsExpression(givenParent).apply {
|
||||
declarations = listOf(KotlinUClass.create(lightClass, this))
|
||||
}
|
||||
} ?: UastEmptyExpression
|
||||
} ?: UastEmptyExpression(givenParent)
|
||||
}
|
||||
is KtFunction -> if (expression.name.isNullOrEmpty()) {
|
||||
expr<ULambdaExpression>(build(::createLocalFunctionLambdaExpression))
|
||||
@@ -384,7 +390,7 @@ internal object KotlinConverter {
|
||||
is KtWhenConditionWithExpression ->
|
||||
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?,
|
||||
requiredType: Class<out 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? =
|
||||
{ ctor(element as P, ktElement, givenParent) }
|
||||
fun <P : PsiElement, K : KtElement> buildKt(ktElement: K, ctor: (P, K, UElement?) -> UElement): () -> UElement? = {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
ctor(element as P, ktElement, givenParent)
|
||||
}
|
||||
|
||||
fun <P : PsiElement, K : KtElement> buildKtOpt(ktElement: K?, ctor: (P, K?, UElement?) -> UElement): () -> UElement? =
|
||||
{ ctor(element as P, ktElement, givenParent) }
|
||||
fun <P : PsiElement, K : KtElement> buildKtOpt(ktElement: K?, ctor: (P, K?, UElement?) -> UElement): () -> UElement? = {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
ctor(element as P, ktElement, givenParent)
|
||||
}
|
||||
|
||||
val original = element.originalElement
|
||||
return with(requiredType) {
|
||||
@@ -552,6 +565,7 @@ internal object KotlinConverter {
|
||||
val file = createAnalyzableFile("dummy.kt", text, context)
|
||||
val declarations = file.declarations
|
||||
assert(declarations.size == 1) { "${declarations.size} declarations in $text" }
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return declarations.first() as TDeclaration
|
||||
}
|
||||
}
|
||||
@@ -563,7 +577,7 @@ private fun convertVariablesDeclaration(
|
||||
val declarationsExpression = parent as? KotlinUDeclarationsExpression
|
||||
?: psi.parent.toUElementOfType<UDeclarationsExpression>() as? KotlinUDeclarationsExpression
|
||||
?: 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(
|
||||
UastKotlinPsiVariable.create(psi, parentPsiElement, declarationsExpression), psi, declarationsExpression) { annotationParent ->
|
||||
psi.annotationEntries.map { KotlinUAnnotation(it, annotationParent) }
|
||||
|
||||
@@ -130,7 +130,7 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin {
|
||||
return when (element) {
|
||||
is KotlinUSimpleReferenceExpression.KotlinAccessorCallExpression -> element.setterValue != null
|
||||
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
|
||||
}
|
||||
else -> false
|
||||
@@ -168,7 +168,10 @@ internal object KotlinConverter {
|
||||
givenParent: UElement?,
|
||||
requiredType: Class<out 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) {
|
||||
@@ -268,7 +271,10 @@ internal object KotlinConverter {
|
||||
givenParent: UElement?,
|
||||
requiredType: Class<out UElement>? = null): 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) {
|
||||
@@ -294,7 +300,7 @@ internal object KotlinConverter {
|
||||
val initializer = psiFactory.createAnalyzableExpression("${tempAssignment.name}.component${i + 1}()",
|
||||
expression.containingFile)
|
||||
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
|
||||
}
|
||||
@@ -340,7 +346,7 @@ internal object KotlinConverter {
|
||||
KotlinUDeclarationsExpression(givenParent).apply {
|
||||
declarations = listOf(KotlinUClass.create(lightClass, this))
|
||||
}
|
||||
} ?: UastEmptyExpression
|
||||
} ?: UastEmptyExpression(givenParent)
|
||||
}
|
||||
is KtFunction -> if (expression.name.isNullOrEmpty()) {
|
||||
expr<ULambdaExpression>(build(::createLocalFunctionLambdaExpression))
|
||||
@@ -386,7 +392,7 @@ internal object KotlinConverter {
|
||||
is KtWhenConditionWithExpression ->
|
||||
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?,
|
||||
requiredType: Class<out 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? =
|
||||
{ ctor(element as P, ktElement, givenParent) }
|
||||
fun <P : PsiElement, K : KtElement> buildKt(ktElement: K, ctor: (P, K, UElement?) -> UElement): () -> UElement? = {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
ctor(element as P, ktElement, givenParent)
|
||||
}
|
||||
|
||||
fun <P : PsiElement, K : KtElement> buildKtOpt(ktElement: K?, ctor: (P, K?, UElement?) -> UElement): () -> UElement? =
|
||||
{ ctor(element as P, ktElement, givenParent) }
|
||||
fun <P : PsiElement, K : KtElement> buildKtOpt(ktElement: K?, ctor: (P, K?, UElement?) -> UElement): () -> UElement? = {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
ctor(element as P, ktElement, givenParent)
|
||||
}
|
||||
|
||||
val original = element.originalElement
|
||||
return with(requiredType) {
|
||||
@@ -554,6 +567,7 @@ internal object KotlinConverter {
|
||||
val file = createAnalyzableFile("dummy.kt", text, context)
|
||||
val declarations = file.declarations
|
||||
assert(declarations.size == 1) { "${declarations.size} declarations in $text" }
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return declarations.first() as TDeclaration
|
||||
}
|
||||
}
|
||||
@@ -565,7 +579,7 @@ private fun convertVariablesDeclaration(
|
||||
val declarationsExpression = parent as? KotlinUDeclarationsExpression
|
||||
?: psi.parent.toUElementOfType<UDeclarationsExpression>() as? KotlinUDeclarationsExpression
|
||||
?: 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(
|
||||
UastKotlinPsiVariable.create(psi, parentPsiElement, declarationsExpression), psi, declarationsExpression) { annotationParent ->
|
||||
psi.annotationEntries.map { KotlinUAnnotation(it, annotationParent) }
|
||||
|
||||
@@ -78,8 +78,8 @@ private fun createElvisExpressions(
|
||||
}
|
||||
|
||||
fun createElvisExpression(elvisExpression: KtBinaryExpression, givenParent: UElement?): UExpression {
|
||||
val left = elvisExpression.left ?: return UastEmptyExpression(null)
|
||||
val right = elvisExpression.right ?: return UastEmptyExpression(null)
|
||||
val left = elvisExpression.left ?: return UastEmptyExpression(givenParent)
|
||||
val right = elvisExpression.right ?: return UastEmptyExpression(givenParent)
|
||||
|
||||
return KotlinUElvisExpression(elvisExpression, left, right, givenParent)
|
||||
}
|
||||
|
||||
+2
-2
@@ -78,8 +78,8 @@ private fun createElvisExpressions(
|
||||
}
|
||||
|
||||
fun createElvisExpression(elvisExpression: KtBinaryExpression, givenParent: UElement?): UExpression {
|
||||
val left = elvisExpression.left ?: return UastEmptyExpression
|
||||
val right = elvisExpression.right ?: return UastEmptyExpression
|
||||
val left = elvisExpression.left ?: return UastEmptyExpression(givenParent)
|
||||
val right = elvisExpression.right ?: return UastEmptyExpression(givenParent)
|
||||
|
||||
return KotlinUElvisExpression(elvisExpression, left, right, givenParent)
|
||||
}
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.expressions.UInjectionHost
|
||||
|
||||
class KotlinStringTemplateUPolyadicExpression(
|
||||
override val psi: KtStringTemplateExpression,
|
||||
override val sourcePsi: KtStringTemplateExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent),
|
||||
UPolyadicExpression,
|
||||
@@ -30,7 +30,7 @@ class KotlinStringTemplateUPolyadicExpression(
|
||||
KotlinEvaluatableUElement,
|
||||
UInjectionHost {
|
||||
override val operands: List<UExpression> by lz {
|
||||
psi.entries.map {
|
||||
sourcePsi.entries.map {
|
||||
KotlinConverter.convertEntry(
|
||||
it,
|
||||
this,
|
||||
@@ -40,7 +40,7 @@ class KotlinStringTemplateUPolyadicExpression(
|
||||
}
|
||||
override val operator = UastBinaryOperator.PLUS
|
||||
|
||||
override val psiLanguageInjectionHost: PsiLanguageInjectionHost get() = psi
|
||||
override val psiLanguageInjectionHost: PsiLanguageInjectionHost get() = sourcePsi
|
||||
override val isString: Boolean get() = true
|
||||
|
||||
override fun asRenderString(): String = if (operands.isEmpty()) "\"\"" else super<UPolyadicExpression>.asRenderString()
|
||||
|
||||
+2
-2
@@ -23,12 +23,12 @@ import org.jetbrains.uast.UPolyadicExpression
|
||||
import org.jetbrains.uast.UastBinaryOperator
|
||||
|
||||
class KotlinStringTemplateUPolyadicExpression(
|
||||
override val psi: KtStringTemplateExpression,
|
||||
override val sourcePsi: KtStringTemplateExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent),
|
||||
UPolyadicExpression,
|
||||
KotlinUElementWithType,
|
||||
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
|
||||
}
|
||||
+3
-3
@@ -21,9 +21,9 @@ import org.jetbrains.uast.UArrayAccessExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
|
||||
class KotlinUArrayAccessExpression(
|
||||
override val psi: KtArrayAccessExpression,
|
||||
override val sourcePsi: KtArrayAccessExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UArrayAccessExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.arrayExpression, this) }
|
||||
override val indices by lz { psi.indexExpressions.map { KotlinConverter.convertOrEmpty(it, this) } }
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(sourcePsi.arrayExpression, this) }
|
||||
override val indices by lz { sourcePsi.indexExpressions.map { KotlinConverter.convertOrEmpty(it, this) } }
|
||||
}
|
||||
+8
-8
@@ -28,7 +28,7 @@ import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
|
||||
class KotlinUBinaryExpression(
|
||||
override val psi: KtBinaryExpression,
|
||||
override val sourcePsi: KtBinaryExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UBinaryExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
private companion object {
|
||||
@@ -39,15 +39,15 @@ class KotlinUBinaryExpression(
|
||||
)
|
||||
}
|
||||
|
||||
override val leftOperand by lz { KotlinConverter.convertOrEmpty(psi.left, this) }
|
||||
override val rightOperand by lz { KotlinConverter.convertOrEmpty(psi.right, this) }
|
||||
override val leftOperand by lz { KotlinConverter.convertOrEmpty(sourcePsi.left, this) }
|
||||
override val rightOperand by lz { KotlinConverter.convertOrEmpty(sourcePsi.right, this) }
|
||||
|
||||
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.PLUS -> UastBinaryOperator.PLUS
|
||||
KtTokens.MINUS -> UastBinaryOperator.MINUS
|
||||
@@ -74,8 +74,8 @@ class KotlinUBinaryExpression(
|
||||
KtTokens.RANGE -> KotlinBinaryOperators.RANGE_TO
|
||||
else -> run { // Handle bitwise operators
|
||||
val other = UastBinaryOperator.OTHER
|
||||
val ref = psi.operationReference
|
||||
val resolvedCall = psi.operationReference.getResolvedCall(ref.analyze()) ?: return@run other
|
||||
val ref = sourcePsi.operationReference
|
||||
val resolvedCall = sourcePsi.operationReference.getResolvedCall(ref.analyze()) ?: return@run other
|
||||
val resultingDescriptor = resolvedCall.resultingDescriptor as? FunctionDescriptor ?: return@run other
|
||||
val applicableOperator = BITWISE_OPERATORS[resultingDescriptor.name.asString()] ?: return@run other
|
||||
|
||||
|
||||
+6
-6
@@ -23,19 +23,19 @@ import org.jetbrains.kotlin.psi.KtBinaryExpressionWithTypeRHS
|
||||
import org.jetbrains.uast.*
|
||||
|
||||
class KotlinUBinaryExpressionWithType(
|
||||
override val psi: KtBinaryExpressionWithTypeRHS,
|
||||
override val sourcePsi: KtBinaryExpressionWithTypeRHS,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UBinaryExpressionWithType,
|
||||
KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
|
||||
override val operand by lz { KotlinConverter.convertOrEmpty(psi.left, this) }
|
||||
override val type by lz { psi.right.toPsiType(this) }
|
||||
override val operand by lz { KotlinConverter.convertOrEmpty(sourcePsi.left, this) }
|
||||
override val type by lz { sourcePsi.right.toPsiType(this) }
|
||||
|
||||
override val typeReference by lz {
|
||||
psi.right?.let { LazyKotlinUTypeReferenceExpression(it, this) }
|
||||
override val typeReference by lz {
|
||||
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_SAFE -> KotlinBinaryExpressionWithTypeKinds.SAFE_TYPE_CAST
|
||||
else -> UastBinaryExpressionWithTypeKind.UNKNOWN
|
||||
|
||||
+8
-8
@@ -22,18 +22,18 @@ import org.jetbrains.kotlin.psi.KtBlockExpression
|
||||
import org.jetbrains.uast.*
|
||||
|
||||
class KotlinUBlockExpression(
|
||||
override val psi: KtBlockExpression,
|
||||
givenParent: UElement?
|
||||
override val sourcePsi: KtBlockExpression,
|
||||
givenParent: UElement?
|
||||
) : 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(
|
||||
override val uastParent: UElement?,
|
||||
expressionProducer: (expressionParent: UElement) -> List<UExpression>
|
||||
) : UBlockExpression, JvmDeclarationUElementPlaceholder {
|
||||
override val psi: PsiElement? = null
|
||||
override val javaPsi: PsiElement? = null
|
||||
override val sourcePsi: PsiElement? = null
|
||||
override val psi: PsiElement? get() = null
|
||||
override val javaPsi: PsiElement? get() = null
|
||||
override val sourcePsi: PsiElement? get() = null
|
||||
override val annotations: List<UAnnotation> = emptyList()
|
||||
override val expressions by lz { expressionProducer(this) }
|
||||
}
|
||||
@@ -42,14 +42,14 @@ class KotlinUBlockExpression(
|
||||
fun create(initializers: List<KtAnonymousInitializer>, uastParent: UElement): UBlockExpression {
|
||||
val languagePlugin = uastParent.getLanguagePlugin()
|
||||
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? {
|
||||
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
|
||||
containingUClass.methods
|
||||
.find { it is KotlinConstructorUMethod && it.isPrimary || it is KotlinSecondaryConstructorWithInitializersUMethod }?.let {
|
||||
|
||||
+2
-2
@@ -22,9 +22,9 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.kotlin.KotlinAbstractUExpression
|
||||
|
||||
class KotlinUBreakExpression(
|
||||
override val psi: KtBreakExpression,
|
||||
override val sourcePsi: KtBreakExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UBreakExpression {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
get() = sourcePsi.getLabelName()
|
||||
}
|
||||
+7
-7
@@ -24,29 +24,29 @@ import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.kotlin.internal.getResolveResultVariants
|
||||
|
||||
class KotlinUCallableReferenceExpression(
|
||||
override val psi: KtCallableReferenceExpression,
|
||||
override val sourcePsi: KtCallableReferenceExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UCallableReferenceExpression, UMultiResolvable, KotlinUElementWithType {
|
||||
override val qualifierExpression: UExpression?
|
||||
get() {
|
||||
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)
|
||||
}
|
||||
|
||||
override val qualifierType by lz {
|
||||
val ktType = psi.analyze()[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null
|
||||
ktType.toPsiType(this, psi, boxed = true)
|
||||
val ktType = sourcePsi.analyze()[DOUBLE_COLON_LHS, sourcePsi.receiverExpression]?.type ?: return@lz null
|
||||
ktType.toPsiType(this, sourcePsi, boxed = true)
|
||||
}
|
||||
|
||||
override val callableName: String
|
||||
get() = psi.callableReference.getReferencedName()
|
||||
get() = sourcePsi.callableReference.getReferencedName()
|
||||
|
||||
override val resolvedName: String?
|
||||
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)
|
||||
|
||||
}
|
||||
+6
-6
@@ -24,26 +24,26 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
|
||||
class KotlinUCallableReferenceExpression(
|
||||
override val psi: KtCallableReferenceExpression,
|
||||
override val sourcePsi: KtCallableReferenceExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UCallableReferenceExpression, KotlinUElementWithType {
|
||||
override val qualifierExpression: UExpression?
|
||||
get() {
|
||||
if (qualifierType != null) return null
|
||||
val receiverExpression = psi.receiverExpression ?: return null
|
||||
val receiverExpression = sourcePsi.receiverExpression ?: return null
|
||||
return KotlinConverter.convertExpression(receiverExpression, this)
|
||||
}
|
||||
|
||||
override val qualifierType by lz {
|
||||
val ktType = psi.analyze()[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null
|
||||
ktType.toPsiType(this, psi, boxed = true)
|
||||
val ktType = sourcePsi.analyze()[DOUBLE_COLON_LHS, sourcePsi.receiverExpression]?.type ?: return@lz null
|
||||
ktType.toPsiType(this, sourcePsi, boxed = true)
|
||||
}
|
||||
|
||||
override val callableName: String
|
||||
get() = psi.callableReference.getReferencedName()
|
||||
get() = sourcePsi.callableReference.getReferencedName()
|
||||
|
||||
override val resolvedName: String?
|
||||
get() = (resolve() as? PsiNamedElement)?.name
|
||||
|
||||
override fun resolve() = psi.callableReference.resolveCallToDeclaration()
|
||||
override fun resolve() = sourcePsi.callableReference.resolveCallToDeclaration()
|
||||
}
|
||||
+7
-7
@@ -27,29 +27,29 @@ import org.jetbrains.uast.UMultiResolvable
|
||||
import org.jetbrains.uast.kotlin.internal.getResolveResultVariants
|
||||
|
||||
class KotlinUCallableReferenceExpression(
|
||||
override val psi: KtCallableReferenceExpression,
|
||||
override val sourcePsi: KtCallableReferenceExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UCallableReferenceExpression, UMultiResolvable, KotlinUElementWithType {
|
||||
override val qualifierExpression: UExpression?
|
||||
get() {
|
||||
if (qualifierType != null) return null
|
||||
val receiverExpression = psi.receiverExpression ?: return null
|
||||
val receiverExpression = sourcePsi.receiverExpression ?: return null
|
||||
return KotlinConverter.convertExpression(receiverExpression, this)
|
||||
}
|
||||
|
||||
override val qualifierType by lz {
|
||||
val ktType = psi.analyze()[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null
|
||||
ktType.toPsiType(this, psi, boxed = true)
|
||||
val ktType = sourcePsi.analyze()[DOUBLE_COLON_LHS, sourcePsi.receiverExpression]?.type ?: return@lz null
|
||||
ktType.toPsiType(this, sourcePsi, boxed = true)
|
||||
}
|
||||
|
||||
override val callableName: String
|
||||
get() = psi.callableReference.getReferencedName()
|
||||
get() = sourcePsi.callableReference.getReferencedName()
|
||||
|
||||
override val resolvedName: String?
|
||||
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
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.psi.KtCatchClause
|
||||
import org.jetbrains.uast.UCatchClause
|
||||
import org.jetbrains.uast.UElement
|
||||
@@ -24,22 +25,23 @@ import org.jetbrains.uast.UTypeReferenceExpression
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
|
||||
class KotlinUCatchClause(
|
||||
override val psi: KtCatchClause,
|
||||
override val sourcePsi: KtCatchClause,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUElement(givenParent), UCatchClause {
|
||||
override val psi: PsiElement?
|
||||
get() = sourcePsi
|
||||
|
||||
override val javaPsi = null
|
||||
override val sourcePsi = psi
|
||||
override val javaPsi: PsiElement? get() = null
|
||||
|
||||
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 {
|
||||
val parameter = psi.catchParameter ?: return@lz emptyList<UParameter>()
|
||||
listOf(KotlinUParameter(UastKotlinPsiParameter.create(parameter, psi, this, 0), psi, this))
|
||||
val parameter = sourcePsi.catchParameter ?: return@lz emptyList<UParameter>()
|
||||
listOf(KotlinUParameter(UastKotlinPsiParameter.create(parameter, sourcePsi, this, 0), sourcePsi, this))
|
||||
}
|
||||
|
||||
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>()
|
||||
listOf(LazyKotlinUTypeReferenceExpression(typeReference, this) { typeReference.toPsiType(this, boxed = true) } )
|
||||
}
|
||||
|
||||
+4
-4
@@ -24,18 +24,18 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
|
||||
class KotlinUClassLiteralExpression(
|
||||
override val psi: KtClassLiteralExpression,
|
||||
override val sourcePsi: KtClassLiteralExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UClassLiteralExpression, KotlinUElementWithType {
|
||||
override val type by lz {
|
||||
val ktType = psi.analyze()[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null
|
||||
ktType.toPsiType(this, psi, boxed = true)
|
||||
val ktType = sourcePsi.analyze()[DOUBLE_COLON_LHS, sourcePsi.receiverExpression]?.type ?: return@lz null
|
||||
ktType.toPsiType(this, sourcePsi, boxed = true)
|
||||
}
|
||||
|
||||
override val expression: UExpression?
|
||||
get() {
|
||||
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)
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -23,18 +23,18 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
|
||||
class KotlinUClassLiteralExpression(
|
||||
override val psi: KtClassLiteralExpression,
|
||||
override val sourcePsi: KtClassLiteralExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UClassLiteralExpression, KotlinUElementWithType {
|
||||
override val type by lz {
|
||||
val ktType = psi.analyze()[DOUBLE_COLON_LHS, psi.receiverExpression]?.type ?: return@lz null
|
||||
ktType.toPsiType(this, psi, boxed = true)
|
||||
val ktType = sourcePsi.analyze()[DOUBLE_COLON_LHS, sourcePsi.receiverExpression]?.type ?: return@lz null
|
||||
ktType.toPsiType(this, sourcePsi, boxed = true)
|
||||
}
|
||||
|
||||
override val expression: UExpression?
|
||||
get() {
|
||||
if (type != null) return null
|
||||
val receiverExpression = psi.receiverExpression ?: return null
|
||||
val receiverExpression = sourcePsi.receiverExpression ?: return null
|
||||
return KotlinConverter.convertExpression(receiverExpression, this)
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -22,9 +22,9 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.kotlin.KotlinAbstractUExpression
|
||||
|
||||
class KotlinUContinueExpression(
|
||||
override val psi: KtContinueExpression,
|
||||
override val sourcePsi: KtContinueExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UContinueExpression {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
get() = sourcePsi.getLabelName()
|
||||
}
|
||||
+3
-3
@@ -23,11 +23,11 @@ import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
|
||||
class KotlinUDoWhileExpression(
|
||||
override val psi: KtDoWhileExpression,
|
||||
override val sourcePsi: KtDoWhileExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UDoWhileExpression {
|
||||
override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) }
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) }
|
||||
override val condition by lz { KotlinConverter.convertOrEmpty(sourcePsi.condition, this) }
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(sourcePsi.body, this) }
|
||||
|
||||
override val doIdentifier: UIdentifier
|
||||
get() = KotlinUIdentifier(null, this)
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.uast.UExpression
|
||||
|
||||
interface KotlinUElementWithType : UExpression {
|
||||
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
|
||||
return ktType.toPsiType(this, ktElement, boxed = false)
|
||||
}
|
||||
@@ -33,7 +33,7 @@ interface KotlinUElementWithType : UExpression {
|
||||
|
||||
interface KotlinEvaluatableUElement : UExpression {
|
||||
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]
|
||||
if (compileTimeConst is UnsignedErrorValueTypeConstant) return null
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ import org.jetbrains.uast.UastSpecialExpressionKind
|
||||
import org.jetbrains.uast.kotlin.kinds.KotlinSpecialExpressionKinds
|
||||
|
||||
open class KotlinUExpressionList(
|
||||
override val psi: PsiElement?,
|
||||
override val sourcePsi: PsiElement?,
|
||||
override val kind: UastSpecialExpressionKind, // original element
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UExpressionList, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
@@ -35,7 +35,7 @@ open class KotlinUExpressionList(
|
||||
internal set
|
||||
|
||||
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]
|
||||
return compileTimeConst?.getValue(TypeUtils.NO_EXPECTED_TYPE)
|
||||
}
|
||||
|
||||
+6
-6
@@ -26,16 +26,16 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
import org.jetbrains.uast.psi.UastPsiParameterNotResolved
|
||||
|
||||
class KotlinUForEachExpression(
|
||||
override val psi: KtForExpression,
|
||||
override val sourcePsi: KtForExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UForEachExpression {
|
||||
override val iteratedValue by lz { KotlinConverter.convertOrEmpty(psi.loopRange, this) }
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) }
|
||||
override val iteratedValue by lz { KotlinConverter.convertOrEmpty(sourcePsi.loopRange, this) }
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(sourcePsi.body, this) }
|
||||
|
||||
override val variable by lz {
|
||||
val parameter = psi.loopParameter?.let { UastKotlinPsiParameter.create(it, psi, this, 0) }
|
||||
?: UastPsiParameterNotResolved(psi, KotlinLanguage.INSTANCE)
|
||||
KotlinUParameter(parameter, psi, this)
|
||||
val parameter = sourcePsi.loopParameter?.let { UastKotlinPsiParameter.create(it, sourcePsi, this, 0) }
|
||||
?: UastPsiParameterNotResolved(sourcePsi, KotlinLanguage.INSTANCE)
|
||||
KotlinUParameter(parameter, sourcePsi, this)
|
||||
}
|
||||
|
||||
override val forIdentifier: UIdentifier
|
||||
|
||||
+14
-14
@@ -44,7 +44,7 @@ import org.jetbrains.uast.kotlin.internal.multiResolveResults
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
class KotlinUFunctionCallExpression(
|
||||
override val psi: KtCallElement,
|
||||
override val sourcePsi: KtCallElement,
|
||||
givenParent: UElement?,
|
||||
private val _resolvedCall: ResolvedCall<*>?
|
||||
) : KotlinAbstractUExpression(givenParent), UCallExpressionEx, KotlinUElementWithType, UMultiResolvable {
|
||||
@@ -52,22 +52,22 @@ class KotlinUFunctionCallExpression(
|
||||
constructor(psi: KtCallElement, uastParent: UElement?) : this(psi, uastParent, null)
|
||||
|
||||
private val resolvedCall
|
||||
get() = _resolvedCall ?: psi.getResolvedCall(psi.analyze())
|
||||
get() = _resolvedCall ?: sourcePsi.getResolvedCall(sourcePsi.analyze())
|
||||
|
||||
override val receiverType by lz {
|
||||
val resolvedCall = this.resolvedCall ?: 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 classReference by lz {
|
||||
KotlinClassViaConstructorUSimpleReferenceExpression(psi, methodName.orAnonymous("class"), this)
|
||||
KotlinClassViaConstructorUSimpleReferenceExpression(sourcePsi, methodName.orAnonymous("class"), this)
|
||||
}
|
||||
|
||||
override val methodIdentifier by lz {
|
||||
val calleeExpression = psi.calleeExpression
|
||||
val calleeExpression = sourcePsi.calleeExpression
|
||||
when (calleeExpression) {
|
||||
null -> null
|
||||
is KtNameReferenceExpression ->
|
||||
@@ -83,9 +83,9 @@ class KotlinUFunctionCallExpression(
|
||||
}
|
||||
|
||||
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? {
|
||||
val resolvedCall = resolvedCall
|
||||
@@ -121,9 +121,9 @@ class KotlinUFunctionCallExpression(
|
||||
}
|
||||
|
||||
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?
|
||||
get() = getExpressionType()
|
||||
@@ -143,7 +143,7 @@ class KotlinUFunctionCallExpression(
|
||||
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 =
|
||||
(resolvedCall as? VariableAsFunctionResolvedCall)?.variableCall?.resultingDescriptor
|
||||
?: (resolvedCall?.resultingDescriptor as? FunctionDescriptor)?.takeIf { it.visibility == Visibilities.LOCAL }
|
||||
@@ -165,7 +165,7 @@ class KotlinUFunctionCallExpression(
|
||||
}
|
||||
|
||||
private val multiResolved by lazy(fun(): Iterable<TypedResolveResult<PsiMethod>> {
|
||||
val contextElement = psi
|
||||
val contextElement = sourcePsi
|
||||
|
||||
if (!Registry.`is`("kotlin.uast.multiresolve.enabled", true)) {
|
||||
val calleeExpression = contextElement.calleeExpression ?: return emptyList()
|
||||
@@ -180,7 +180,7 @@ class KotlinUFunctionCallExpression(
|
||||
return variants.flatMap {
|
||||
when (val source = it.toSource()) {
|
||||
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()
|
||||
})
|
||||
@@ -191,7 +191,7 @@ class KotlinUFunctionCallExpression(
|
||||
override fun resolve(): PsiMethod? {
|
||||
val descriptor = resolvedCall?.resultingDescriptor ?: return null
|
||||
val source = descriptor.toSource()
|
||||
return resolveSource(psi, descriptor, source)
|
||||
return resolveSource(sourcePsi, descriptor, source)
|
||||
}
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
@@ -205,7 +205,7 @@ class KotlinUFunctionCallExpression(
|
||||
|
||||
private fun isAnnotationArgumentArrayInitializer(): Boolean {
|
||||
// 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 KtCallExpression -> elementAt2.getParentOfType<KtAnnotationEntry>(true, KtDeclaration::class.java) != null
|
||||
else -> false
|
||||
|
||||
+12
-12
@@ -37,7 +37,7 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
class KotlinUFunctionCallExpression(
|
||||
override val psi: KtCallElement,
|
||||
override val sourcePsi: KtCallElement,
|
||||
givenParent: UElement?,
|
||||
private val _resolvedCall: ResolvedCall<*>?
|
||||
) : KotlinAbstractUExpression(givenParent), UCallExpressionEx, KotlinUElementWithType {
|
||||
@@ -45,22 +45,22 @@ class KotlinUFunctionCallExpression(
|
||||
constructor(psi: KtCallElement, uastParent: UElement?) : this(psi, uastParent, null)
|
||||
|
||||
private val resolvedCall
|
||||
get() = _resolvedCall ?: psi.getResolvedCall(psi.analyze())
|
||||
get() = _resolvedCall ?: sourcePsi.getResolvedCall(sourcePsi.analyze())
|
||||
|
||||
override val receiverType by lz {
|
||||
val resolvedCall = this.resolvedCall ?: 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 classReference by lz {
|
||||
KotlinClassViaConstructorUSimpleReferenceExpression(psi, methodName.orAnonymous("class"), this)
|
||||
KotlinClassViaConstructorUSimpleReferenceExpression(sourcePsi, methodName.orAnonymous("class"), this)
|
||||
}
|
||||
|
||||
override val methodIdentifier by lz {
|
||||
val calleeExpression = psi.calleeExpression
|
||||
val calleeExpression = sourcePsi.calleeExpression
|
||||
when (calleeExpression) {
|
||||
null -> null
|
||||
is KtNameReferenceExpression ->
|
||||
@@ -76,9 +76,9 @@ class KotlinUFunctionCallExpression(
|
||||
}
|
||||
|
||||
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? {
|
||||
val resolvedCall = resolvedCall ?: return null
|
||||
@@ -89,9 +89,9 @@ class KotlinUFunctionCallExpression(
|
||||
|
||||
|
||||
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?
|
||||
get() = getExpressionType()
|
||||
@@ -111,7 +111,7 @@ class KotlinUFunctionCallExpression(
|
||||
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 =
|
||||
(resolvedCall as? VariableAsFunctionResolvedCall)?.variableCall?.resultingDescriptor
|
||||
?: (resolvedCall?.resultingDescriptor as? FunctionDescriptor)?.takeIf { it.visibility == Visibilities.LOCAL }
|
||||
@@ -135,7 +135,7 @@ class KotlinUFunctionCallExpression(
|
||||
override fun resolve(): PsiMethod? {
|
||||
val descriptor = resolvedCall?.resultingDescriptor ?: return null
|
||||
val source = descriptor.toSource()
|
||||
return resolveSource(psi, descriptor, source)
|
||||
return resolveSource(sourcePsi, descriptor, source)
|
||||
}
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
@@ -149,7 +149,7 @@ class KotlinUFunctionCallExpression(
|
||||
|
||||
private fun isAnnotationArgumentArrayInitializer(): Boolean {
|
||||
// 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 KtCallExpression -> elementAt2.getParentOfType<KtAnnotationEntry>(true, KtDeclaration::class.java) != null
|
||||
else -> false
|
||||
|
||||
+4
-4
@@ -22,12 +22,12 @@ import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.UIfExpression
|
||||
|
||||
class KotlinUIfExpression(
|
||||
override val psi: KtIfExpression,
|
||||
override val sourcePsi: KtIfExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UIfExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) }
|
||||
override val thenExpression by lz { KotlinConverter.convertOrNull(psi.then, this) }
|
||||
override val elseExpression by lz { KotlinConverter.convertOrNull(psi.`else`, this) }
|
||||
override val condition by lz { KotlinConverter.convertOrEmpty(sourcePsi.condition, this) }
|
||||
override val thenExpression by lz { KotlinConverter.convertOrNull(sourcePsi.then, this) }
|
||||
override val elseExpression by lz { KotlinConverter.convertOrNull(sourcePsi.`else`, this) }
|
||||
override val isTernary = false
|
||||
|
||||
override val ifIdentifier: UIdentifier
|
||||
|
||||
+4
-4
@@ -23,14 +23,14 @@ import org.jetbrains.uast.ULabeledExpression
|
||||
import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
|
||||
class KotlinULabeledExpression(
|
||||
override val psi: KtLabeledExpression,
|
||||
override val sourcePsi: KtLabeledExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), ULabeledExpression {
|
||||
override val label: String
|
||||
get() = psi.getLabelName().orAnonymous("label")
|
||||
get() = sourcePsi.getLabelName().orAnonymous("label")
|
||||
|
||||
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) }
|
||||
}
|
||||
+4
-4
@@ -25,17 +25,17 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
import org.jetbrains.uast.withMargin
|
||||
|
||||
class KotlinULambdaExpression(
|
||||
override val psi: KtLambdaExpression,
|
||||
override val sourcePsi: KtLambdaExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), ULambdaExpression, KotlinUElementWithType {
|
||||
override val functionalInterfaceType: PsiType?
|
||||
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 {
|
||||
psi.valueParameters.mapIndexed { i, p ->
|
||||
KotlinUParameter(UastKotlinPsiParameter.create(p, psi, this, i), psi, this)
|
||||
sourcePsi.valueParameters.mapIndexed { i, p ->
|
||||
KotlinUParameter(UastKotlinPsiParameter.create(p, sourcePsi, this, i), sourcePsi, this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -25,17 +25,17 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.ULiteralExpression
|
||||
|
||||
class KotlinULiteralExpression(
|
||||
override val psi: KtConstantExpression,
|
||||
override val sourcePsi: KtConstantExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), ULiteralExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val isNull: Boolean
|
||||
get() = psi.unwrapBlockOrParenthesis().node?.elementType == KtNodeTypes.NULL
|
||||
get() = sourcePsi.unwrapBlockOrParenthesis().node?.elementType == KtNodeTypes.NULL
|
||||
|
||||
override val value by lz { evaluate() }
|
||||
}
|
||||
|
||||
class KotlinStringULiteralExpression(
|
||||
override val psi: PsiElement,
|
||||
override val sourcePsi: PsiElement,
|
||||
givenParent: UElement?,
|
||||
val text: String
|
||||
) : KotlinAbstractUExpression(givenParent), ULiteralExpression, KotlinUElementWithType{
|
||||
@@ -47,5 +47,5 @@ class KotlinStringULiteralExpression(
|
||||
|
||||
override fun evaluate() = value
|
||||
|
||||
override fun getExpressionType(): PsiType? = PsiType.getJavaLangString(psi.manager, psi.resolveScope)
|
||||
override fun getExpressionType(): PsiType? = PsiType.getJavaLangString(sourcePsi.manager, sourcePsi.resolveScope)
|
||||
}
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ class KotlinUVarargExpression(
|
||||
valueArgs.map {
|
||||
it.getArgumentExpression()?.let { argumentExpression ->
|
||||
getLanguagePlugin().convert<UExpression>(argumentExpression, this)
|
||||
} ?: UastEmptyExpression(null)
|
||||
} ?: UastEmptyExpression(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-9
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.kotlin.asJava.toLightClass
|
||||
@@ -27,20 +28,20 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
|
||||
|
||||
class KotlinUObjectLiteralExpression(
|
||||
override val psi: KtObjectLiteralExpression,
|
||||
override val sourcePsi: KtObjectLiteralExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UObjectLiteralExpression, UCallExpressionEx, DelegatedMultiResolve, KotlinUElementWithType {
|
||||
|
||||
override val declaration: UClass by lz {
|
||||
psi.objectDeclaration.toLightClass()
|
||||
sourcePsi.objectDeclaration.toLightClass()
|
||||
?.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 {
|
||||
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) } }
|
||||
@@ -67,14 +68,14 @@ class KotlinUObjectLiteralExpression(
|
||||
superClassConstructorCall?.let { it.getResolvedCall(it.analyze()) }?.let { getArgumentExpressionByIndex(i, it, this) }
|
||||
|
||||
private class ObjectLiteralClassReference(
|
||||
override val psi: KtSuperTypeCallEntry,
|
||||
override val sourcePsi: KtSuperTypeCallEntry,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUElement(givenParent), USimpleNameReferenceExpression {
|
||||
|
||||
override val javaPsi = null
|
||||
override val sourcePsi = psi
|
||||
override val javaPsi: PsiElement? get() = null
|
||||
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>
|
||||
get() = emptyList()
|
||||
|
||||
+10
-9
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.kotlin.asJava.toLightClass
|
||||
@@ -26,20 +27,20 @@ import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
|
||||
|
||||
class KotlinUObjectLiteralExpression(
|
||||
override val psi: KtObjectLiteralExpression,
|
||||
override val sourcePsi: KtObjectLiteralExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UObjectLiteralExpression, UCallExpressionEx, DelegatedMultiResolve, KotlinUElementWithType {
|
||||
|
||||
override val declaration: UClass by lz {
|
||||
psi.objectDeclaration.toLightClass()
|
||||
sourcePsi.objectDeclaration.toLightClass()
|
||||
?.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 {
|
||||
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) } }
|
||||
@@ -66,14 +67,14 @@ class KotlinUObjectLiteralExpression(
|
||||
superClassConstructorCall?.let { it.getResolvedCall(it.analyze()) }?.let { getArgumentExpressionByIndex(i, it, this) }
|
||||
|
||||
private class ObjectLiteralClassReference(
|
||||
override val psi: KtSuperTypeCallEntry,
|
||||
override val sourcePsi: KtSuperTypeCallEntry,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUElement(givenParent), USimpleNameReferenceExpression {
|
||||
|
||||
override val javaPsi = null
|
||||
override val sourcePsi = psi
|
||||
override val javaPsi: PsiElement? get() = null
|
||||
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>
|
||||
get() = emptyList()
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UParenthesizedExpression
|
||||
|
||||
class KotlinUParenthesizedExpression(
|
||||
override val psi: KtParenthesizedExpression,
|
||||
override val sourcePsi: KtParenthesizedExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UParenthesizedExpression, KotlinUElementWithType {
|
||||
override val expression by lz { KotlinConverter.convertOrEmpty(psi.expression, this) }
|
||||
override val expression by lz { KotlinConverter.convertOrEmpty(sourcePsi.expression, this) }
|
||||
}
|
||||
+6
-6
@@ -24,13 +24,13 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
|
||||
|
||||
class KotlinUPostfixExpression(
|
||||
override val psi: KtPostfixExpression,
|
||||
override val sourcePsi: KtPostfixExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UPostfixExpression, KotlinUElementWithType, KotlinEvaluatableUElement,
|
||||
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.MINUSMINUS -> UastPostfixOperator.DEC
|
||||
KtTokens.EXCLEXCL -> KotlinPostfixOperators.EXCLEXCL
|
||||
@@ -38,11 +38,11 @@ class KotlinUPostfixExpression(
|
||||
}
|
||||
|
||||
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
|
||||
else -> null
|
||||
}
|
||||
|
||||
+5
-5
@@ -26,17 +26,17 @@ import org.jetbrains.uast.UastPrefixOperator
|
||||
import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
|
||||
class KotlinUPrefixExpression(
|
||||
override val psi: KtPrefixExpression,
|
||||
override val sourcePsi: KtPrefixExpression,
|
||||
givenParent: UElement?
|
||||
) : 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?
|
||||
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.PLUS -> UastPrefixOperator.UNARY_PLUS
|
||||
KtTokens.MINUS -> UastPrefixOperator.UNARY_MINUS
|
||||
|
||||
+4
-4
@@ -25,15 +25,15 @@ import org.jetbrains.uast.UastQualifiedExpressionAccessType
|
||||
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
|
||||
|
||||
class KotlinUQualifiedReferenceExpression(
|
||||
override val psi: KtDotQualifiedExpression,
|
||||
override val sourcePsi: KtDotQualifiedExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UQualifiedReferenceExpression, DelegatedMultiResolve,
|
||||
KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.receiverExpression, this) }
|
||||
override val selector by lz { KotlinConverter.convertOrEmpty(psi.selectorExpression, this) }
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(sourcePsi.receiverExpression, this) }
|
||||
override val selector by lz { KotlinConverter.convertOrEmpty(sourcePsi.selectorExpression, this) }
|
||||
override val accessType = UastQualifiedExpressionAccessType.SIMPLE
|
||||
|
||||
override fun resolve() = psi.selectorExpression?.resolveCallToDeclaration()
|
||||
override fun resolve() = sourcePsi.selectorExpression?.resolveCallToDeclaration()
|
||||
|
||||
override val resolvedName: String?
|
||||
get() = (resolve() as? PsiNamedElement)?.name
|
||||
|
||||
+4
-4
@@ -24,15 +24,15 @@ import org.jetbrains.uast.UastQualifiedExpressionAccessType
|
||||
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
|
||||
|
||||
class KotlinUQualifiedReferenceExpression(
|
||||
override val psi: KtDotQualifiedExpression,
|
||||
override val sourcePsi: KtDotQualifiedExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UQualifiedReferenceExpression, DelegatedMultiResolve,
|
||||
KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.receiverExpression, this) }
|
||||
override val selector by lz { KotlinConverter.convertOrEmpty(psi.selectorExpression, this) }
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(sourcePsi.receiverExpression, this) }
|
||||
override val selector by lz { KotlinConverter.convertOrEmpty(sourcePsi.selectorExpression, this) }
|
||||
override val accessType = UastQualifiedExpressionAccessType.SIMPLE
|
||||
|
||||
override fun resolve() = psi.selectorExpression?.resolveCallToDeclaration()
|
||||
override fun resolve() = sourcePsi.selectorExpression?.resolveCallToDeclaration()
|
||||
|
||||
override val resolvedName: String?
|
||||
get() = (resolve() as? PsiNamedElement)?.name
|
||||
|
||||
+2
-2
@@ -23,10 +23,10 @@ import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.UReturnExpression
|
||||
|
||||
class KotlinUReturnExpression(
|
||||
override val psi: KtReturnExpression,
|
||||
override val sourcePsi: KtReturnExpression,
|
||||
givenParent: UElement?
|
||||
) : 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(
|
||||
|
||||
+5
-5
@@ -25,17 +25,17 @@ import org.jetbrains.uast.UQualifiedReferenceExpression
|
||||
import org.jetbrains.uast.kotlin.internal.getResolveResultVariants
|
||||
|
||||
class KotlinUSafeQualifiedExpression(
|
||||
override val psi: KtSafeQualifiedExpression,
|
||||
override val sourcePsi: KtSafeQualifiedExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UQualifiedReferenceExpression, UMultiResolvable,
|
||||
KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.receiverExpression, this) }
|
||||
override val selector by lz { KotlinConverter.convertOrEmpty(psi.selectorExpression, this) }
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(sourcePsi.receiverExpression, this) }
|
||||
override val selector by lz { KotlinConverter.convertOrEmpty(sourcePsi.selectorExpression, this) }
|
||||
override val accessType = KotlinQualifiedExpressionAccessTypes.SAFE
|
||||
|
||||
override val resolvedName: String?
|
||||
get() = (resolve() as? PsiNamedElement)?.name
|
||||
|
||||
override fun resolve() = psi.selectorExpression?.resolveCallToDeclaration()
|
||||
override fun multiResolve(): Iterable<ResolveResult> = getResolveResultVariants(psi.selectorExpression)
|
||||
override fun resolve() = sourcePsi.selectorExpression?.resolveCallToDeclaration()
|
||||
override fun multiResolve(): Iterable<ResolveResult> = getResolveResultVariants(sourcePsi.selectorExpression)
|
||||
}
|
||||
+4
-4
@@ -22,16 +22,16 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UQualifiedReferenceExpression
|
||||
|
||||
class KotlinUSafeQualifiedExpression(
|
||||
override val psi: KtSafeQualifiedExpression,
|
||||
override val sourcePsi: KtSafeQualifiedExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UQualifiedReferenceExpression,
|
||||
KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.receiverExpression, this) }
|
||||
override val selector by lz { KotlinConverter.convertOrEmpty(psi.selectorExpression, this) }
|
||||
override val receiver by lz { KotlinConverter.convertOrEmpty(sourcePsi.receiverExpression, this) }
|
||||
override val selector by lz { KotlinConverter.convertOrEmpty(sourcePsi.selectorExpression, this) }
|
||||
override val accessType = KotlinQualifiedExpressionAccessTypes.SAFE
|
||||
|
||||
override val resolvedName: String?
|
||||
get() = (resolve() as? PsiNamedElement)?.name
|
||||
|
||||
override fun resolve() = psi.selectorExpression?.resolveCallToDeclaration()
|
||||
override fun resolve() = sourcePsi.selectorExpression?.resolveCallToDeclaration()
|
||||
}
|
||||
+28
-28
@@ -38,18 +38,18 @@ import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
open class KotlinUSimpleReferenceExpression(
|
||||
override val psi: KtSimpleNameExpression,
|
||||
override val sourcePsi: KtSimpleNameExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), USimpleNameReferenceExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
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<*>) {
|
||||
declarationDescriptor = declarationDescriptor.callableFromObject
|
||||
}
|
||||
if (declarationDescriptor is SyntheticJavaPropertyDescriptor) {
|
||||
declarationDescriptor = when (psi.readWriteAccess()) {
|
||||
declarationDescriptor = when (sourcePsi.readWriteAccess()) {
|
||||
ReferenceAccess.WRITE, ReferenceAccess.READ_WRITE ->
|
||||
declarationDescriptor.setMethod ?: declarationDescriptor.getMethod
|
||||
ReferenceAccess.READ -> declarationDescriptor.getMethod
|
||||
@@ -57,17 +57,17 @@ open class KotlinUSimpleReferenceExpression(
|
||||
}
|
||||
|
||||
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) {
|
||||
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
|
||||
|
||||
@@ -77,24 +77,24 @@ open class KotlinUSimpleReferenceExpression(
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
visitor.visitSimpleNameReferenceExpression(this)
|
||||
|
||||
if (psi.parent.destructuringDeclarationInitializer != true) {
|
||||
if (sourcePsi.parent.destructuringDeclarationInitializer != true) {
|
||||
visitAccessorCalls(visitor)
|
||||
}
|
||||
|
||||
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) {
|
||||
// Visit Kotlin get-set synthetic Java property calls as function calls
|
||||
val bindingContext = psi.analyze()
|
||||
val access = psi.readWriteAccess()
|
||||
val resolvedCall = psi.getResolvedCall(bindingContext)
|
||||
val bindingContext = sourcePsi.analyze()
|
||||
val access = sourcePsi.readWriteAccess()
|
||||
val resolvedCall = sourcePsi.getResolvedCall(bindingContext)
|
||||
val resultingDescriptor = resolvedCall?.resultingDescriptor as? SyntheticJavaPropertyDescriptor
|
||||
if (resultingDescriptor != null) {
|
||||
val setterValue = if (access.isWrite) {
|
||||
findAssignment(psi, psi.parent)?.right ?: run {
|
||||
findAssignment(sourcePsi, sourcePsi.parent)?.right ?: run {
|
||||
visitor.afterVisitSimpleNameReferenceExpression(this)
|
||||
return
|
||||
}
|
||||
@@ -104,13 +104,13 @@ open class KotlinUSimpleReferenceExpression(
|
||||
|
||||
if (access.isRead) {
|
||||
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) {
|
||||
val setDescriptor = resultingDescriptor.setMethod
|
||||
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(
|
||||
override val psi: KtSimpleNameExpression,
|
||||
override val sourcePsi: KtSimpleNameExpression,
|
||||
override val uastParent: KotlinUSimpleReferenceExpression,
|
||||
private val resolvedCall: ResolvedCall<*>,
|
||||
private val accessorDescriptor: DeclarationDescriptor,
|
||||
@@ -142,18 +142,18 @@ open class KotlinUSimpleReferenceExpression(
|
||||
null
|
||||
}
|
||||
|
||||
override val javaPsi: PsiElement? = null
|
||||
override val sourcePsi: PsiElement? = psi
|
||||
override val javaPsi: PsiElement? get() = null
|
||||
override val psi: PsiElement? get() = sourcePsi
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
|
||||
override val receiverType by lz {
|
||||
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?
|
||||
get() = null
|
||||
@@ -174,11 +174,11 @@ open class KotlinUSimpleReferenceExpression(
|
||||
get() = resolvedCall.typeArguments.size
|
||||
|
||||
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 {
|
||||
(accessorDescriptor as? CallableDescriptor)?.returnType?.toPsiType(this, psi, boxed = false)
|
||||
(accessorDescriptor as? CallableDescriptor)?.returnType?.toPsiType(this, sourcePsi, boxed = false)
|
||||
}
|
||||
|
||||
override val kind: UastCallKind
|
||||
@@ -186,7 +186,7 @@ open class KotlinUSimpleReferenceExpression(
|
||||
|
||||
override fun resolve(): PsiMethod? {
|
||||
val source = accessorDescriptor.toSource()
|
||||
return resolveSource(psi, accessorDescriptor, source)
|
||||
return resolveSource(sourcePsi, accessorDescriptor, source)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ open class KotlinUSimpleReferenceExpression(
|
||||
}
|
||||
|
||||
class KotlinClassViaConstructorUSimpleReferenceExpression(
|
||||
override val psi: KtCallElement,
|
||||
override val sourcePsi: KtCallElement,
|
||||
override val identifier: String,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), USimpleNameReferenceExpression, KotlinUElementWithType {
|
||||
@@ -226,13 +226,13 @@ class KotlinClassViaConstructorUSimpleReferenceExpression(
|
||||
get() = (resolved as? PsiNamedElement)?.name
|
||||
|
||||
private val resolved by lazy {
|
||||
when (val resultingDescriptor = psi.getResolvedCall(psi.analyze())?.resultingDescriptor) {
|
||||
when (val resultingDescriptor = sourcePsi.getResolvedCall(sourcePsi.analyze())?.resultingDescriptor) {
|
||||
is ConstructorDescriptor -> {
|
||||
resultingDescriptor.constructedClass.toSource()?.getMaybeLightElement()
|
||||
?: (resultingDescriptor as? DeserializedCallableMemberDescriptor)?.let { resolveContainingDeserializedClass(psi, it) }
|
||||
?: (resultingDescriptor as? DeserializedCallableMemberDescriptor)?.let { resolveContainingDeserializedClass(sourcePsi, it) }
|
||||
}
|
||||
is SamConstructorDescriptor ->
|
||||
(resultingDescriptor.returnType?.getFunctionalInterfaceType(this, psi) as? PsiClassType)?.resolve()
|
||||
(resultingDescriptor.returnType?.getFunctionalInterfaceType(this, sourcePsi) as? PsiClassType)?.resolve()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
+27
-27
@@ -38,18 +38,18 @@ import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
open class KotlinUSimpleReferenceExpression(
|
||||
override val psi: KtSimpleNameExpression,
|
||||
override val sourcePsi: KtSimpleNameExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), USimpleNameReferenceExpression, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
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<*>) {
|
||||
declarationDescriptor = declarationDescriptor.callableFromObject
|
||||
}
|
||||
if (declarationDescriptor is SyntheticJavaPropertyDescriptor) {
|
||||
declarationDescriptor = when (psi.readWriteAccess()) {
|
||||
declarationDescriptor = when (sourcePsi.readWriteAccess()) {
|
||||
ReferenceAccess.WRITE, ReferenceAccess.READ_WRITE ->
|
||||
declarationDescriptor.setMethod ?: declarationDescriptor.getMethod
|
||||
ReferenceAccess.READ -> declarationDescriptor.getMethod
|
||||
@@ -57,17 +57,17 @@ open class KotlinUSimpleReferenceExpression(
|
||||
}
|
||||
|
||||
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) {
|
||||
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
|
||||
|
||||
@@ -77,7 +77,7 @@ open class KotlinUSimpleReferenceExpression(
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
visitor.visitSimpleNameReferenceExpression(this)
|
||||
|
||||
if (psi.parent.destructuringDeclarationInitializer != true) {
|
||||
if (sourcePsi.parent.destructuringDeclarationInitializer != true) {
|
||||
visitAccessorCalls(visitor)
|
||||
}
|
||||
|
||||
@@ -86,13 +86,13 @@ open class KotlinUSimpleReferenceExpression(
|
||||
|
||||
private fun visitAccessorCalls(visitor: UastVisitor) {
|
||||
// Visit Kotlin get-set synthetic Java property calls as function calls
|
||||
val bindingContext = psi.analyze()
|
||||
val access = psi.readWriteAccess()
|
||||
val resolvedCall = psi.getResolvedCall(bindingContext)
|
||||
val bindingContext = sourcePsi.analyze()
|
||||
val access = sourcePsi.readWriteAccess()
|
||||
val resolvedCall = sourcePsi.getResolvedCall(bindingContext)
|
||||
val resultingDescriptor = resolvedCall?.resultingDescriptor as? SyntheticJavaPropertyDescriptor
|
||||
if (resultingDescriptor != null) {
|
||||
val setterValue = if (access.isWrite) {
|
||||
findAssignment(psi, psi.parent)?.right ?: run {
|
||||
findAssignment(sourcePsi, sourcePsi.parent)?.right ?: run {
|
||||
visitor.afterVisitSimpleNameReferenceExpression(this)
|
||||
return
|
||||
}
|
||||
@@ -103,13 +103,13 @@ open class KotlinUSimpleReferenceExpression(
|
||||
if (resolvedCall != null) {
|
||||
if (access.isRead) {
|
||||
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) {
|
||||
val setDescriptor = resultingDescriptor.setMethod
|
||||
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(
|
||||
override val psi: KtSimpleNameExpression,
|
||||
override val sourcePsi: KtSimpleNameExpression,
|
||||
override val uastParent: KotlinUSimpleReferenceExpression,
|
||||
private val resolvedCall: ResolvedCall<*>,
|
||||
private val accessorDescriptor: DeclarationDescriptor,
|
||||
@@ -142,18 +142,18 @@ open class KotlinUSimpleReferenceExpression(
|
||||
null
|
||||
}
|
||||
|
||||
override val javaPsi: PsiElement? = null
|
||||
override val sourcePsi: PsiElement? = psi
|
||||
override val javaPsi: PsiElement? get() = null
|
||||
override val psi: PsiElement? get() = sourcePsi
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
|
||||
override val receiverType by lz {
|
||||
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?
|
||||
get() = null
|
||||
@@ -174,11 +174,11 @@ open class KotlinUSimpleReferenceExpression(
|
||||
get() = resolvedCall.typeArguments.size
|
||||
|
||||
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 {
|
||||
(accessorDescriptor as? CallableDescriptor)?.returnType?.toPsiType(this, psi, boxed = false)
|
||||
(accessorDescriptor as? CallableDescriptor)?.returnType?.toPsiType(this, sourcePsi, boxed = false)
|
||||
}
|
||||
|
||||
override val kind: UastCallKind
|
||||
@@ -186,7 +186,7 @@ open class KotlinUSimpleReferenceExpression(
|
||||
|
||||
override fun resolve(): PsiMethod? {
|
||||
val source = accessorDescriptor.toSource()
|
||||
return resolveSource(psi, accessorDescriptor, source)
|
||||
return resolveSource(sourcePsi, accessorDescriptor, source)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ open class KotlinUSimpleReferenceExpression(
|
||||
}
|
||||
|
||||
class KotlinClassViaConstructorUSimpleReferenceExpression(
|
||||
override val psi: KtCallElement,
|
||||
override val sourcePsi: KtCallElement,
|
||||
override val identifier: String,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), USimpleNameReferenceExpression, KotlinUElementWithType {
|
||||
@@ -226,13 +226,13 @@ class KotlinClassViaConstructorUSimpleReferenceExpression(
|
||||
get() = (resolved as? PsiNamedElement)?.name
|
||||
|
||||
private val resolved by lazy {
|
||||
when (val resultingDescriptor = psi.getResolvedCall(psi.analyze())?.resultingDescriptor) {
|
||||
when (val resultingDescriptor = sourcePsi.getResolvedCall(sourcePsi.analyze())?.resultingDescriptor) {
|
||||
is ConstructorDescriptor -> {
|
||||
resultingDescriptor.constructedClass.toSource()?.getMaybeLightElement()
|
||||
?: (resultingDescriptor as? DeserializedCallableMemberDescriptor)?.let { resolveContainingDeserializedClass(psi, it) }
|
||||
?: (resultingDescriptor as? DeserializedCallableMemberDescriptor)?.let { resolveContainingDeserializedClass(sourcePsi, it) }
|
||||
}
|
||||
is SamConstructorDescriptor ->
|
||||
(resultingDescriptor.returnType?.getFunctionalInterfaceType(this, psi) as? PsiClassType)?.resolve()
|
||||
(resultingDescriptor.returnType?.getFunctionalInterfaceType(this, sourcePsi) as? PsiClassType)?.resolve()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -25,14 +25,14 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
|
||||
|
||||
class KotlinUSuperExpression(
|
||||
override val psi: KtSuperExpression,
|
||||
override val sourcePsi: KtSuperExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), USuperExpression, DelegatedMultiResolve, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
get() = sourcePsi.getLabelName()
|
||||
|
||||
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()]
|
||||
}
|
||||
+9
-9
@@ -25,16 +25,16 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
import org.jetbrains.uast.kotlin.kinds.KotlinSpecialExpressionKinds
|
||||
|
||||
class KotlinUSwitchExpression(
|
||||
override val psi: KtWhenExpression,
|
||||
override val sourcePsi: KtWhenExpression,
|
||||
givenParent: UElement?
|
||||
) : 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 {
|
||||
object : KotlinUExpressionList(psi, KotlinSpecialExpressionKinds.WHEN, this@KotlinUSwitchExpression) {
|
||||
object : KotlinUExpressionList(sourcePsi, KotlinSpecialExpressionKinds.WHEN, this@KotlinUSwitchExpression) {
|
||||
override fun asRenderString() = expressions.joinToString("\n") { it.asRenderString().withMargin }
|
||||
}.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(
|
||||
override val psi: KtWhenEntry,
|
||||
override val sourcePsi: KtWhenEntry,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), USwitchClauseExpressionWithBody {
|
||||
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 {
|
||||
object : KotlinUExpressionList(psi, KotlinSpecialExpressionKinds.WHEN_ENTRY, this@KotlinUSwitchEntry) {
|
||||
object : KotlinUExpressionList(sourcePsi, KotlinSpecialExpressionKinds.WHEN_ENTRY, this@KotlinUSwitchEntry) {
|
||||
override fun asRenderString() = buildString {
|
||||
appendln("{")
|
||||
expressions.forEach { appendln(it.asRenderString().withMargin) }
|
||||
appendln("}")
|
||||
}
|
||||
}.apply {
|
||||
val exprPsi = this@KotlinUSwitchEntry.psi.expression
|
||||
val exprPsi = this@KotlinUSwitchEntry.sourcePsi.expression
|
||||
val userExpressions = when (exprPsi) {
|
||||
is KtBlockExpression -> exprPsi.statements.map { KotlinConverter.convertOrEmpty(it, this) }
|
||||
else -> listOf(KotlinConverter.convertOrEmpty(exprPsi, this))
|
||||
@@ -86,7 +86,7 @@ class KotlinUSwitchEntry(
|
||||
}
|
||||
|
||||
override fun convertParent(): UElement? {
|
||||
val result = KotlinConverter.unwrapElements(psi.parent)?.let { parentUnwrapped ->
|
||||
val result = KotlinConverter.unwrapElements(sourcePsi.parent)?.let { parentUnwrapped ->
|
||||
KotlinUastLanguagePlugin().convertElementWithParent(parentUnwrapped, null)
|
||||
}
|
||||
return (result as? KotlinUSwitchExpression)?.body ?: result
|
||||
|
||||
+9
-9
@@ -25,16 +25,16 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
import org.jetbrains.uast.kotlin.kinds.KotlinSpecialExpressionKinds
|
||||
|
||||
class KotlinUSwitchExpression(
|
||||
override val psi: KtWhenExpression,
|
||||
override val sourcePsi: KtWhenExpression,
|
||||
givenParent: UElement?
|
||||
) : 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 {
|
||||
object : KotlinUExpressionList(psi, KotlinSpecialExpressionKinds.WHEN, this@KotlinUSwitchExpression) {
|
||||
object : KotlinUExpressionList(sourcePsi, KotlinSpecialExpressionKinds.WHEN, this@KotlinUSwitchExpression) {
|
||||
override fun asRenderString() = expressions.joinToString("\n") { it.asRenderString().withMargin }
|
||||
}.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(
|
||||
override val psi: KtWhenEntry,
|
||||
override val sourcePsi: KtWhenEntry,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), USwitchClauseExpressionWithBody {
|
||||
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 {
|
||||
object : KotlinUExpressionList(psi, KotlinSpecialExpressionKinds.WHEN_ENTRY, this@KotlinUSwitchEntry) {
|
||||
object : KotlinUExpressionList(sourcePsi, KotlinSpecialExpressionKinds.WHEN_ENTRY, this@KotlinUSwitchEntry) {
|
||||
override fun asRenderString() = buildString {
|
||||
appendln("{")
|
||||
expressions.forEach { appendln(it.asRenderString().withMargin) }
|
||||
appendln("}")
|
||||
}
|
||||
}.apply {
|
||||
val exprPsi = this@KotlinUSwitchEntry.psi.expression
|
||||
val exprPsi = this@KotlinUSwitchEntry.sourcePsi.expression
|
||||
val userExpressions = when (exprPsi) {
|
||||
is KtBlockExpression -> exprPsi.statements.map { KotlinConverter.convertOrEmpty(it, this) }
|
||||
else -> listOf(KotlinConverter.convertOrEmpty(exprPsi, this))
|
||||
@@ -86,7 +86,7 @@ class KotlinUSwitchEntry(
|
||||
}
|
||||
|
||||
override fun convertParent(): UElement? {
|
||||
val result = KotlinConverter.unwrapElements(psi.parent)?.let { parentUnwrapped ->
|
||||
val result = KotlinConverter.unwrapElements(sourcePsi.parent)?.let { parentUnwrapped ->
|
||||
KotlinUastLanguagePlugin().convertElementWithParent(parentUnwrapped, null)
|
||||
}
|
||||
return (result as? KotlinUSwitchExpression)?.body ?: result
|
||||
|
||||
+4
-4
@@ -25,14 +25,14 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
|
||||
|
||||
class KotlinUThisExpression(
|
||||
override val psi: KtThisExpression,
|
||||
override val sourcePsi: KtThisExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UThisExpression, DelegatedMultiResolve, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
get() = sourcePsi.getLabelName()
|
||||
|
||||
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()]
|
||||
}
|
||||
+4
-4
@@ -25,14 +25,14 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve
|
||||
|
||||
class KotlinUThisExpression(
|
||||
override val psi: KtThisExpression,
|
||||
override val sourcePsi: KtThisExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UThisExpression, DelegatedMultiResolve, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
get() = sourcePsi.getLabelName()
|
||||
|
||||
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()]
|
||||
}
|
||||
+2
-2
@@ -21,8 +21,8 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UThrowExpression
|
||||
|
||||
class KotlinUThrowExpression(
|
||||
override val psi: KtThrowExpression,
|
||||
override val sourcePsi: KtThrowExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UThrowExpression, KotlinUElementWithType {
|
||||
override val thrownExpression by lz { KotlinConverter.convertOrEmpty(psi.thrownExpression, this) }
|
||||
override val thrownExpression by lz { KotlinConverter.convertOrEmpty(sourcePsi.thrownExpression, this) }
|
||||
}
|
||||
+4
-4
@@ -21,13 +21,13 @@ import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
|
||||
class KotlinUTryExpression(
|
||||
override val psi: KtTryExpression,
|
||||
override val sourcePsi: KtTryExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UTryExpression, KotlinUElementWithType {
|
||||
override val tryClause by lz { KotlinConverter.convertOrEmpty(psi.tryBlock, this) }
|
||||
override val catchClauses by lz { psi.catchClauses.map { KotlinUCatchClause(it, this) } }
|
||||
override val tryClause by lz { KotlinConverter.convertOrEmpty(sourcePsi.tryBlock, this) }
|
||||
override val catchClauses by lz { sourcePsi.catchClauses.map { KotlinUCatchClause(it, this) } }
|
||||
override val finallyClause by lz {
|
||||
psi.finallyBlock?.finalExpression?.let {
|
||||
sourcePsi.finallyBlock?.finalExpression?.let {
|
||||
KotlinConverter.convertExpression(
|
||||
it,
|
||||
this,
|
||||
|
||||
+4
-4
@@ -24,12 +24,12 @@ import org.jetbrains.uast.UVariable
|
||||
import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
|
||||
class KotlinUTryExpression(
|
||||
override val psi: KtTryExpression,
|
||||
override val sourcePsi: KtTryExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UTryExpression, KotlinUElementWithType {
|
||||
override val tryClause by lz { KotlinConverter.convertOrEmpty(psi.tryBlock, this) }
|
||||
override val catchClauses by lz { psi.catchClauses.map { KotlinUCatchClause(it, this) } }
|
||||
override val finallyClause by lz { psi.finallyBlock?.finalExpression?.let { KotlinConverter.convertExpression(it, this) } }
|
||||
override val tryClause by lz { KotlinConverter.convertOrEmpty(sourcePsi.tryBlock, this) }
|
||||
override val catchClauses by lz { sourcePsi.catchClauses.map { KotlinUCatchClause(it, this) } }
|
||||
override val finallyClause by lz { sourcePsi.finallyBlock?.finalExpression?.let { KotlinConverter.convertExpression(it, this) } }
|
||||
|
||||
override val resourceVariables: List<UVariable>
|
||||
get() = emptyList()
|
||||
|
||||
+5
-5
@@ -22,19 +22,19 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UastBinaryExpressionWithTypeKind
|
||||
|
||||
class KotlinUTypeCheckExpression(
|
||||
override val psi: KtIsExpression,
|
||||
override val sourcePsi: KtIsExpression,
|
||||
givenParent: UElement?
|
||||
) : 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) }
|
||||
}
|
||||
|
||||
override val operationKind =
|
||||
if(psi.isNegated)
|
||||
if(sourcePsi.isNegated)
|
||||
KotlinBinaryExpressionWithTypeKinds.NEGATED_INSTANCE_CHECK
|
||||
else
|
||||
UastBinaryExpressionWithTypeKind.INSTANCE_CHECK
|
||||
|
||||
+2
-2
@@ -14,11 +14,11 @@ open class KotlinUTypeReferenceExpression(
|
||||
|
||||
|
||||
class LazyKotlinUTypeReferenceExpression(
|
||||
override val psi: KtTypeReference,
|
||||
override val sourcePsi: KtTypeReference,
|
||||
givenParent: UElement?,
|
||||
private val typeSupplier: (() -> PsiType)? = null
|
||||
) : KotlinAbstractUExpression(givenParent), UTypeReferenceExpression {
|
||||
override val type: PsiType by lz {
|
||||
typeSupplier?.invoke() ?: psi.toPsiType(uastParent ?: this)
|
||||
typeSupplier?.invoke() ?: sourcePsi.toPsiType(uastParent ?: this)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -23,11 +23,11 @@ import org.jetbrains.uast.UWhileExpression
|
||||
import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
||||
|
||||
class KotlinUWhileExpression(
|
||||
override val psi: KtWhileExpression,
|
||||
override val sourcePsi: KtWhileExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UWhileExpression {
|
||||
override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) }
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) }
|
||||
override val condition by lz { KotlinConverter.convertOrEmpty(sourcePsi.condition, this) }
|
||||
override val body by lz { KotlinConverter.convertOrEmpty(sourcePsi.body, this) }
|
||||
|
||||
override val whileIdentifier: UIdentifier
|
||||
get() = KotlinUIdentifier(null, this)
|
||||
|
||||
@@ -13,12 +13,12 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
||||
|
||||
internal class KotlinLocalFunctionUVariable(
|
||||
val function: KtFunction,
|
||||
override val psi: PsiVariable,
|
||||
override val javaPsi: PsiVariable,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUElement(givenParent), UVariableExPlaceHolder, PsiVariable by psi {
|
||||
) : KotlinAbstractUElement(givenParent), UVariableExPlaceHolder, PsiVariable by javaPsi {
|
||||
|
||||
override val javaPsi = psi
|
||||
override val sourcePsi: PsiElement? = (psi as? UastKotlinPsiVariable?)?.ktElement ?: psi
|
||||
override val psi get() = javaPsi
|
||||
override val sourcePsi: PsiElement? = (javaPsi as? UastKotlinPsiVariable?)?.ktElement ?: javaPsi
|
||||
|
||||
override val uastInitializer: UExpression? by lz {
|
||||
createLocalFunctionLambdaExpression(function, this)
|
||||
@@ -37,16 +37,16 @@ internal class KotlinLocalFunctionUVariable(
|
||||
|
||||
|
||||
private class KotlinLocalFunctionULambdaExpression(
|
||||
override val psi: KtFunction,
|
||||
override val sourcePsi: KtFunction,
|
||||
givenParent: UElement?
|
||||
): KotlinAbstractUExpression(givenParent), ULambdaExpression {
|
||||
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 {
|
||||
psi.valueParameters.mapIndexed { i, p ->
|
||||
KotlinUParameter(UastKotlinPsiParameter.create(p, psi, this, i), p, this)
|
||||
sourcePsi.valueParameters.mapIndexed { i, p ->
|
||||
KotlinUParameter(UastKotlinPsiParameter.create(p, sourcePsi, this, i), p, this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
|
||||
class UnknownKotlinExpression(
|
||||
override val psi: KtExpression,
|
||||
override val sourcePsi: KtExpression,
|
||||
givenParent: UElement?
|
||||
) : KotlinAbstractUExpression(givenParent), UExpression {
|
||||
override fun asLogString() = "[!] UnknownKotlinExpression ($psi)"
|
||||
override fun asLogString() = "[!] UnknownKotlinExpression ($sourcePsi)"
|
||||
}
|
||||
+1
-1
@@ -28,7 +28,7 @@ interface KotlinUElementWithComments : JvmDeclarationUElementPlaceholder {
|
||||
|
||||
override val comments: List<UComment>
|
||||
get() {
|
||||
val psi = psi ?: return emptyList()
|
||||
val psi = sourcePsi ?: return emptyList()
|
||||
val childrenComments = psi.children.filterIsInstance<PsiComment>().map { UComment(it, this) }
|
||||
if (this !is UExpression) return childrenComments
|
||||
val childrenAndSiblingComments = childrenComments +
|
||||
|
||||
+7
-7
@@ -223,7 +223,7 @@ private fun getMethodSignatureFromDescriptor(context: KtElement, descriptor: Cal
|
||||
internal fun <T> lz(initializer: () -> T) = lazy(LazyThreadSafetyMode.SYNCHRONIZED, initializer)
|
||||
|
||||
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 {
|
||||
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 {
|
||||
val unwrapped = if (element is T) element.psi else element
|
||||
val unwrapped = if (element is T) element.javaPsi else element
|
||||
assert(unwrapped !is UElement)
|
||||
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)
|
||||
|
||||
internal fun KotlinULambdaExpression.getFunctionalInterfaceType(): PsiType? {
|
||||
val parent = psi.parent
|
||||
if (parent is KtBinaryExpressionWithTypeRHS) return parent.right?.getType()?.getFunctionalInterfaceType(this, psi)
|
||||
val parent = sourcePsi.parent
|
||||
if (parent is KtBinaryExpressionWithTypeRHS) return parent.right?.getType()?.getFunctionalInterfaceType(this, sourcePsi)
|
||||
if (parent is KtValueArgument) run {
|
||||
val callExpression = parent.parents.take(2).firstIsInstanceOrNull<KtCallExpression>() ?: return@run
|
||||
val resolvedCall = callExpression.getResolvedCall(callExpression.analyze()) ?: return@run
|
||||
val candidateDescriptor = resolvedCall.candidateDescriptor as? SyntheticMemberDescriptor<*> ?: return@run
|
||||
when (candidateDescriptor) {
|
||||
is SamConstructorDescriptor -> return candidateDescriptor.returnType?.getFunctionalInterfaceType(this, psi)
|
||||
is SamConstructorDescriptor -> return candidateDescriptor.returnType?.getFunctionalInterfaceType(this, sourcePsi)
|
||||
is SamAdapterDescriptor<*>, is SamAdapterExtensionFunctionDescriptor -> {
|
||||
val index = (resolvedCall.getArgumentMapping(parent) as? ArgumentMatch)?.valueParameter?.index ?: return@run
|
||||
val functionDescriptor = candidateDescriptor.baseDescriptorForSynthetic as? FunctionDescriptor ?: 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
|
||||
|
||||
@@ -29,7 +29,7 @@ class UastKotlinPsiParameter(
|
||||
) : LightParameter(name, type, parent, language, isVarArgs) {
|
||||
companion object {
|
||||
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(
|
||||
parameter.name ?: "p$index",
|
||||
(parameter.analyze()[BindingContext.DECLARATION_TO_DESCRIPTOR, parameter] as? VariableDescriptor)
|
||||
|
||||
@@ -76,7 +76,7 @@ class UastKotlinPsiVariable private constructor(
|
||||
containingElement: KotlinUDeclarationsExpression,
|
||||
initializer: KtExpression? = null
|
||||
): PsiLocalVariable {
|
||||
val psi = containingElement.psiAnchor ?: containingElement.psi
|
||||
val psi = containingElement.psiAnchor ?: containingElement.sourcePsi
|
||||
val psiParent = psi?.getNonStrictParentOfType<KtDeclaration>() ?: parent
|
||||
val initializerExpression = initializer ?: declaration.initializer
|
||||
return UastKotlinPsiVariable(
|
||||
|
||||
Reference in New Issue
Block a user