diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/api/LowLevelFirApiFacadeForResolveOnAir.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/api/LowLevelFirApiFacadeForResolveOnAir.kt index de8ffa10346..dfeef02537a 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/api/LowLevelFirApiFacadeForResolveOnAir.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/api/LowLevelFirApiFacadeForResolveOnAir.kt @@ -456,13 +456,31 @@ object LowLevelFirApiFacadeForResolveOnAir { private fun bodyResolveRequired(container: KtDeclaration, elementToReplace: PsiElement): Boolean = when { container == elementToReplace -> true - container is KtDeclarationWithBody -> container.bodyExpression.isAncestor(elementToReplace) + + container is KtDeclarationWithBody -> { + val bodyExpression = container.bodyExpression + val secondaryConstructorSuperCallArgs = (container as? KtSecondaryConstructor)?.getDelegationCallOrNull()?.valueArgumentList + + bodyExpression.isAncestor(elementToReplace) || secondaryConstructorSuperCallArgs.isAncestor(elementToReplace) + } + container is KtProperty -> container.delegateExpressionOrInitializer.isAncestor(elementToReplace) container is KtParameter -> container.defaultValue.isAncestor(elementToReplace) + container is KtEnumEntry -> { container.initializerList.isAncestor(elementToReplace) || container.body.isAncestor(elementToReplace) } + container is KtClassOrObject -> { + container.superTypeListEntries.any { superTypeEntry -> + when (superTypeEntry) { + is KtSuperTypeCallEntry -> superTypeEntry.valueArgumentList.isAncestor(elementToReplace) + is KtDelegatedSuperTypeEntry -> superTypeEntry.delegateExpression.isAncestor(elementToReplace) + else -> false + } + } + } + container is KtScript || container is KtAnonymousInitializer -> true else -> false } diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_delegatedConstructor.context.txt b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_delegatedConstructor.context.txt new file mode 100644 index 00000000000..04e43b33d8c --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_delegatedConstructor.context.txt @@ -0,0 +1,19 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirExplicitStarImportingScope + Element 2 + Scope: FirDefaultSimpleImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirPackageMemberScope + Element 5 + Scope: FirExplicitSimpleImportingScope + Element 6 + Implicit receiver: + FirRegularClassSymbol public final class MyClass : R|kotlin/Any| + Type: test.MyClass + Element 7 + Scope: FirLocalScope diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_delegatedConstructor.fir.txt b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_delegatedConstructor.fir.txt new file mode 100644 index 00000000000..da53ed4d425 --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_delegatedConstructor.fir.txt @@ -0,0 +1,6 @@ +KT element: KtNameReferenceExpression +FIR element: FirPropertyAccessExpressionImpl +FIR source kind: KtRealSourceElementKind + +FIR element rendered: +R|test/property| diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_delegatedConstructor.kt b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_delegatedConstructor.kt new file mode 100644 index 00000000000..21495eb7c6e --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_delegatedConstructor.kt @@ -0,0 +1,7 @@ +package test + +val property = 10 + +class MyClass(i: Int) { + constructor(): this(property) +} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_primaryConstructor.context.txt b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_primaryConstructor.context.txt new file mode 100644 index 00000000000..4dc874eebdb --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_primaryConstructor.context.txt @@ -0,0 +1,19 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirExplicitStarImportingScope + Element 2 + Scope: FirDefaultSimpleImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirPackageMemberScope + Element 5 + Scope: FirExplicitSimpleImportingScope + Element 6 + Implicit receiver: + FirRegularClassSymbol public final class Child : R|test/Base| + Type: test.Child + Element 7 + Scope: FirLocalScope diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_primaryConstructor.fir.txt b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_primaryConstructor.fir.txt new file mode 100644 index 00000000000..fc3814d49ac --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_primaryConstructor.fir.txt @@ -0,0 +1,6 @@ +KT element: KtNameReferenceExpression +FIR element: FirPropertyAccessExpressionImpl +FIR source kind: KtRealSourceElementKind + +FIR element rendered: +R|test/property| \ No newline at end of file diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_primaryConstructor.kt b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_primaryConstructor.kt new file mode 100644 index 00000000000..34e4225d4fe --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_primaryConstructor.kt @@ -0,0 +1,7 @@ +package test + +open class Base(action: Int) + +val property = 10 + +class Child : Base(property) \ No newline at end of file diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_secondaryConstructor.context.txt b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_secondaryConstructor.context.txt new file mode 100644 index 00000000000..4dc874eebdb --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_secondaryConstructor.context.txt @@ -0,0 +1,19 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirExplicitStarImportingScope + Element 2 + Scope: FirDefaultSimpleImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirPackageMemberScope + Element 5 + Scope: FirExplicitSimpleImportingScope + Element 6 + Implicit receiver: + FirRegularClassSymbol public final class Child : R|test/Base| + Type: test.Child + Element 7 + Scope: FirLocalScope diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_secondaryConstructor.fir.txt b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_secondaryConstructor.fir.txt new file mode 100644 index 00000000000..fc3814d49ac --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_secondaryConstructor.fir.txt @@ -0,0 +1,6 @@ +KT element: KtNameReferenceExpression +FIR element: FirPropertyAccessExpressionImpl +FIR source kind: KtRealSourceElementKind + +FIR element rendered: +R|test/property| \ No newline at end of file diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_secondaryConstructor.kt b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_secondaryConstructor.kt new file mode 100644 index 00000000000..a5cdfce64d9 --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_secondaryConstructor.kt @@ -0,0 +1,9 @@ +package test + +open class Base(i: Int) + +val property = 10 + +class Child : Base { + constructor(): super(property) +} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation.context.txt b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation.context.txt new file mode 100644 index 00000000000..7ce4937ed8e --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation.context.txt @@ -0,0 +1,19 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirExplicitStarImportingScope + Element 2 + Scope: FirDefaultSimpleImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirPackageMemberScope + Element 5 + Scope: FirExplicitSimpleImportingScope + Element 6 + Implicit receiver: + FirRegularClassSymbol public final class MyClass : R|test/MyInterface| + Type: test.MyClass + Element 7 + Scope: FirLocalScope diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation.fir.txt b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation.fir.txt new file mode 100644 index 00000000000..fc3814d49ac --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation.fir.txt @@ -0,0 +1,6 @@ +KT element: KtNameReferenceExpression +FIR element: FirPropertyAccessExpressionImpl +FIR source kind: KtRealSourceElementKind + +FIR element rendered: +R|test/property| \ No newline at end of file diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation.kt b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation.kt new file mode 100644 index 00000000000..becad2415f8 --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation.kt @@ -0,0 +1,7 @@ +package test + +interface MyInterface + +val property: MyInterface = object : MyInterface {} + +class MyClass: MyInterface by property \ No newline at end of file diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toCompanion.context.txt b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toCompanion.context.txt new file mode 100644 index 00000000000..e20bbaa2817 --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toCompanion.context.txt @@ -0,0 +1,27 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirExplicitStarImportingScope + Element 2 + Scope: FirDefaultSimpleImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirPackageMemberScope + Element 5 + Scope: FirExplicitSimpleImportingScope + Element 6 + Implicit receiver: + FirRegularClassSymbol public final companion object Companion : R|test/MyInterface| + Type: test.MyClass.Companion + Element 7 + Scope: FirNestedClassifierScopeImpl + Classifiers: + FirRegularClassSymbol public final companion object Companion : R|test/MyInterface| + Element 8 + Implicit receiver: + FirRegularClassSymbol public final class MyClass : R|test/MyInterface| + Type: test.MyClass + Element 9 + Scope: FirLocalScope diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toCompanion.fir.txt b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toCompanion.fir.txt new file mode 100644 index 00000000000..154a32d3083 --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toCompanion.fir.txt @@ -0,0 +1,6 @@ +KT element: KtNameReferenceExpression +FIR element: FirResolvedQualifierImpl +FIR source kind: KtRealSourceElementKind + +FIR element rendered: +Q|test/MyClass.Companion| diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toCompanion.kt b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toCompanion.kt new file mode 100644 index 00000000000..9c402009b78 --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toCompanion.kt @@ -0,0 +1,7 @@ +package test + +interface MyInterface + +class MyClass: MyInterface by Companion { + companion object : MyInterface +} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toPrimaryConstructorParam.context.txt b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toPrimaryConstructorParam.context.txt new file mode 100644 index 00000000000..68e3694f194 --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toPrimaryConstructorParam.context.txt @@ -0,0 +1,17 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirExplicitStarImportingScope + Element 2 + Scope: FirDefaultSimpleImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirPackageMemberScope + Element 5 + Scope: FirExplicitSimpleImportingScope + Element 6 + Implicit receiver: + FirRegularClassSymbol public final class MyClass : R|test/MyInterface| + Type: test.MyClass diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toPrimaryConstructorParam.fir.txt b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toPrimaryConstructorParam.fir.txt new file mode 100644 index 00000000000..2a6784da61b --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toPrimaryConstructorParam.fir.txt @@ -0,0 +1,6 @@ +KT element: KtNameReferenceExpression +FIR element: FirPropertyAccessExpressionImpl +FIR source kind: KtRealSourceElementKind + +FIR element rendered: +R|/param| diff --git a/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toPrimaryConstructorParam.kt b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toPrimaryConstructorParam.kt new file mode 100644 index 00000000000..7e70876c624 --- /dev/null +++ b/analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toPrimaryConstructorParam.kt @@ -0,0 +1,5 @@ +package test + +interface MyInterface + +class MyClass(param: MyInterface): MyInterface by param \ No newline at end of file diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/SourceDependentCopyContextTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/SourceDependentCopyContextTestGenerated.java index b2e897e1507..89a8fbcee08 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/SourceDependentCopyContextTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/SourceDependentCopyContextTestGenerated.java @@ -53,4 +53,40 @@ public class SourceDependentCopyContextTestGenerated extends AbstractSourceDepen public void testFunction() throws Exception { runTest("analysis/low-level-api-fir/testData/dependentCopy/function.kt"); } + + @Test + @TestMetadata("superCallArgument_delegatedConstructor.kt") + public void testSuperCallArgument_delegatedConstructor() throws Exception { + runTest("analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_delegatedConstructor.kt"); + } + + @Test + @TestMetadata("superCallArgument_primaryConstructor.kt") + public void testSuperCallArgument_primaryConstructor() throws Exception { + runTest("analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_primaryConstructor.kt"); + } + + @Test + @TestMetadata("superCallArgument_secondaryConstructor.kt") + public void testSuperCallArgument_secondaryConstructor() throws Exception { + runTest("analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_secondaryConstructor.kt"); + } + + @Test + @TestMetadata("superTypeDelegation.kt") + public void testSuperTypeDelegation() throws Exception { + runTest("analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation.kt"); + } + + @Test + @TestMetadata("superTypeDelegation_toCompanion.kt") + public void testSuperTypeDelegation_toCompanion() throws Exception { + runTest("analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toCompanion.kt"); + } + + @Test + @TestMetadata("superTypeDelegation_toPrimaryConstructorParam.kt") + public void testSuperTypeDelegation_toPrimaryConstructorParam() throws Exception { + runTest("analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toPrimaryConstructorParam.kt"); + } } diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/SourceDependentCopyFirTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/SourceDependentCopyFirTestGenerated.java index 233d08370a8..4ef9dd8fac2 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/SourceDependentCopyFirTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/SourceDependentCopyFirTestGenerated.java @@ -53,4 +53,40 @@ public class SourceDependentCopyFirTestGenerated extends AbstractSourceDependent public void testFunction() throws Exception { runTest("analysis/low-level-api-fir/testData/dependentCopy/function.kt"); } + + @Test + @TestMetadata("superCallArgument_delegatedConstructor.kt") + public void testSuperCallArgument_delegatedConstructor() throws Exception { + runTest("analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_delegatedConstructor.kt"); + } + + @Test + @TestMetadata("superCallArgument_primaryConstructor.kt") + public void testSuperCallArgument_primaryConstructor() throws Exception { + runTest("analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_primaryConstructor.kt"); + } + + @Test + @TestMetadata("superCallArgument_secondaryConstructor.kt") + public void testSuperCallArgument_secondaryConstructor() throws Exception { + runTest("analysis/low-level-api-fir/testData/dependentCopy/superCallArgument_secondaryConstructor.kt"); + } + + @Test + @TestMetadata("superTypeDelegation.kt") + public void testSuperTypeDelegation() throws Exception { + runTest("analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation.kt"); + } + + @Test + @TestMetadata("superTypeDelegation_toCompanion.kt") + public void testSuperTypeDelegation_toCompanion() throws Exception { + runTest("analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toCompanion.kt"); + } + + @Test + @TestMetadata("superTypeDelegation_toPrimaryConstructorParam.kt") + public void testSuperTypeDelegation_toPrimaryConstructorParam() throws Exception { + runTest("analysis/low-level-api-fir/testData/dependentCopy/superTypeDelegation_toPrimaryConstructorParam.kt"); + } }