[FE] Fix source element duplication in object literal expressions

This commit is contained in:
Yan Zhulanow
2022-09-27 02:24:54 +09:00
committed by teamcity
parent ea3f550b58
commit 61ce9fe524
14 changed files with 63 additions and 64 deletions
@@ -45,7 +45,6 @@ internal fun KtExpression.unwrap(): KtExpression {
return when (this) {
is KtLabeledExpression -> baseExpression?.unwrap()
is KtAnnotatedExpression -> baseExpression?.unwrap()
is KtObjectLiteralExpression -> objectDeclaration
is KtFunctionLiteral -> (parent as? KtLambdaExpression)?.unwrap()
else -> this
} ?: this
@@ -44,7 +44,6 @@ internal class FirElementBuilder(
// null will be return in case of invalid KtValueArgument
deparenthesized.getArgumentExpression()
}
deparenthesized is KtObjectLiteralExpression -> deparenthesized.objectDeclaration
deparenthesized is KtStringTemplateEntryWithExpression -> deparenthesized.expression
deparenthesized is KtUserType && deparenthesized.parent is KtNullableType -> deparenthesized.parent as KtNullableType
else -> deparenthesized
@@ -0,0 +1,5 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtObjectDeclaration
fun test() {
<expr>object {}</expr>
}
@@ -0,0 +1,11 @@
KT element: KtObjectDeclaration
FIR element: FirAnonymousObjectImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
object : R|kotlin/Any| {
private constructor(): R|<anonymous>| {
super<R|kotlin/Any|>()
}
}
@@ -0,0 +1,5 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtObjectLiteralExpression
fun test() {
<expr>object {}</expr>
}
@@ -0,0 +1,11 @@
KT element: KtObjectLiteralExpression
FIR element: FirAnonymousObjectExpressionImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
object : R|kotlin/Any| {
private constructor(): R|<anonymous>| {
super<R|kotlin/Any|>()
}
}
@@ -215,6 +215,18 @@ public class GetOrBuildFirTestGenerated extends AbstractGetOrBuildFirTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("objectLiteral.kt")
public void testObjectLiteral() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/objectLiteral.kt");
}
@Test
@TestMetadata("objectLiteralExpression.kt")
public void testObjectLiteralExpression() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/objectLiteralExpression.kt");
}
@Test
@TestMetadata("propertyDelegate.kt")
public void testPropertyDelegate() throws Exception {