From 7ddb4f832458069bd544580a6fe5769faf264c4e Mon Sep 17 00:00:00 2001 From: Roman Golyshev Date: Tue, 5 Sep 2023 15:56:22 +0200 Subject: [PATCH] KT-61245 [LL API] Collect correct context for class headers To avoid collecting context which includes the implicit class receiver, context for class header positions is collected before entering the `context.withRegularClass` call --- .../level/api/fir/util/ContextCollector.kt | 6 ++ .../classHeaderPositions/contextReceiver.kt | 8 ++ .../classHeaderPositions/contextReceiver.txt | 37 +++++++++ ...structorParameter_initializerExpression.kt | 9 +++ ...tructorParameter_initializerExpression.txt | 48 ++++++++++++ .../primaryConstructorParameter_typeRef.kt | 7 ++ .../primaryConstructorParameter_typeRef.txt | 45 +++++++++++ .../superTypeCallArgumentsExpression.kt | 12 +++ .../superTypeCallArgumentsExpression.txt | 45 +++++++++++ .../superTypeCallArgumentsTypeRef.kt | 9 +++ .../superTypeCallArgumentsTypeRef.txt | 48 ++++++++++++ .../classHeaderPositions/superTypeCallee.kt | 12 +++ .../classHeaderPositions/superTypeCallee.txt | 36 +++++++++ .../superTypeCalleeGenerics.kt | 7 ++ .../superTypeCalleeGenerics.txt | 36 +++++++++ .../superTypeDelegatedExpression.kt | 9 +++ .../superTypeDelegatedExpression.txt | 49 ++++++++++++ .../superTypeDelegatedTypeRef.kt | 11 +++ .../superTypeDelegatedTypeRef.txt | 40 ++++++++++ .../classHeaderPositions/superTypeRef.kt | 14 ++++ .../classHeaderPositions/superTypeRef.txt | 36 +++++++++ .../superTypeRefGenerics.kt | 14 ++++ .../superTypeRefGenerics.txt | 36 +++++++++ .../ContextCollectorScriptTestGenerated.java | 10 +++ .../ContextCollectorSourceTestGenerated.java | 76 +++++++++++++++++++ 25 files changed, 660 insertions(+) create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/contextReceiver.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/contextReceiver.txt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_initializerExpression.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_initializerExpression.txt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_typeRef.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_typeRef.txt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsExpression.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsExpression.txt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsTypeRef.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsTypeRef.txt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallee.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallee.txt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCalleeGenerics.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCalleeGenerics.txt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedExpression.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedExpression.txt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedTypeRef.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedTypeRef.txt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRef.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRef.txt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRefGenerics.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRefGenerics.txt diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/util/ContextCollector.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/util/ContextCollector.kt index 2eb31a8ca51..37db7cfb83d 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/util/ContextCollector.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/util/ContextCollector.kt @@ -326,8 +326,14 @@ private class ContextCollectorVisitor( regularClass.lazyResolveToPhase(FirResolvePhase.STATUS) context.withContainingClass(regularClass) { + processList(regularClass.contextReceivers) processList(regularClass.typeParameters) + // we do it before we actually visit the constructors, + // because we don't want to have implicit this receiver + // for supertype callee positions + processList(regularClass.superTypeRefs) + context.withRegularClass(regularClass, holder) { dumpContext(regularClass, ContextKind.BODY) diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/contextReceiver.kt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/contextReceiver.kt new file mode 100644 index 00000000000..44b88afec43 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/contextReceiver.kt @@ -0,0 +1,8 @@ +package test + +open class Base { + class Nested +} + +context(Base) +class Child : Base() {} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/contextReceiver.txt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/contextReceiver.txt new file mode 100644 index 00000000000..31a9851218a --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/contextReceiver.txt @@ -0,0 +1,37 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + +FILE: [ResolvedTo(IMPORTS)] contextReceiver.kt + public open [ResolvedTo(STATUS)] class Base : R|kotlin/Any| { + public [ResolvedTo(STATUS)] constructor(): R|test/Base| { + LAZY_super + } + + public? final? [ResolvedTo(RAW_FIR)] class Nested : R|kotlin/Any| { + public? [ResolvedTo(RAW_FIR)] constructor(): R|test/Base.Nested| { + LAZY_super + } + + } + + } + context(R|test/Base|) + public final [ResolvedTo(STATUS)] class Child : R|test/Base| { + public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Child| { + super() + } + + } diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_initializerExpression.kt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_initializerExpression.kt new file mode 100644 index 00000000000..73f7c38200e --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_initializerExpression.kt @@ -0,0 +1,9 @@ +package test + +open class Base { + class Nested + + val fromBase: String = "" +} + +class Child(name: String = "name") : Base() \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_initializerExpression.txt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_initializerExpression.txt new file mode 100644 index 00000000000..f1ad0132dd4 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_initializerExpression.txt @@ -0,0 +1,48 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + Element 7 + Scope: FirNestedClassifierScopeWithSubstitution + Classifiers: + FirRegularClassSymbol public final class Nested : R|kotlin/Any| + Static scope owner symbol: FirRegularClassSymbol public open class Base : R|kotlin/Any| + Element 8 + Scope: FirLocalScope + Properties: + FirValueParameterSymbol name: R|kotlin/String| = String(name) + +FILE: [ResolvedTo(IMPORTS)] primaryConstructorParameter_initializerExpression.kt + public open [ResolvedTo(STATUS)] class Base : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Base| { + super() + } + + public final [ResolvedTo(STATUS)] class Nested : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Base.Nested| { + super() + } + + } + + public final [ResolvedTo(BODY_RESOLVE)] val fromBase: R|kotlin/String| = String() + public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/String| + + } + public final [ResolvedTo(STATUS)] class Child : R|test/Base| { + public [ResolvedTo(BODY_RESOLVE)] constructor([ResolvedTo(BODY_RESOLVE)] name: R|kotlin/String| = String(name)): R|test/Child| { + super() + } + + } diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_typeRef.kt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_typeRef.kt new file mode 100644 index 00000000000..beff6c9183f --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_typeRef.kt @@ -0,0 +1,7 @@ +package test + +open class Base { + class Nested +} + +class Child(name: String) : Base() \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_typeRef.txt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_typeRef.txt new file mode 100644 index 00000000000..bae41ffa503 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_typeRef.txt @@ -0,0 +1,45 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + Element 7 + Scope: FirNestedClassifierScopeWithSubstitution + Classifiers: + FirRegularClassSymbol public final class Nested : R|kotlin/Any| + Static scope owner symbol: FirRegularClassSymbol public open class Base : R|kotlin/Any| + Element 8 + Scope: FirLocalScope + Properties: + FirValueParameterSymbol name: R|kotlin/String| + +FILE: [ResolvedTo(IMPORTS)] primaryConstructorParameter_typeRef.kt + public open [ResolvedTo(STATUS)] class Base : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Base| { + super() + } + + public final [ResolvedTo(STATUS)] class Nested : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Base.Nested| { + super() + } + + } + + } + public final [ResolvedTo(STATUS)] class Child : R|test/Base| { + public [ResolvedTo(BODY_RESOLVE)] constructor([ResolvedTo(BODY_RESOLVE)] name: R|kotlin/String|): R|test/Child| { + super() + } + + } diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsExpression.kt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsExpression.kt new file mode 100644 index 00000000000..ebbe2d96fee --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsExpression.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package test + +open class Base(param: Nested) { + class Nested +} + +class Child(primaryConstructorParameter: Nested) : Base(primaryConstructorParameter) \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsExpression.txt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsExpression.txt new file mode 100644 index 00000000000..e107889224b --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsExpression.txt @@ -0,0 +1,45 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + Element 7 + Scope: FirNestedClassifierScopeWithSubstitution + Classifiers: + FirRegularClassSymbol public final class Nested : R|kotlin/Any| + Static scope owner symbol: FirRegularClassSymbol public open class Base : R|kotlin/Any| + Element 8 + Scope: FirLocalScope + Properties: + FirValueParameterSymbol primaryConstructorParameter: R|test/Base.Nested| + +FILE: [ResolvedTo(IMPORTS)] superTypeCallArgumentsExpression.kt + public open [ResolvedTo(STATUS)] class Base : R|kotlin/Any| { + public [ResolvedTo(STATUS)] constructor([ResolvedTo(STATUS)] param: R|test/Base.Nested|): R|test/Base| { + LAZY_super + } + + public final [ResolvedTo(STATUS)] class Nested : R|kotlin/Any| { + public? [ResolvedTo(RAW_FIR)] constructor(): R|test/Base.Nested| { + LAZY_super + } + + } + + } + public final [ResolvedTo(STATUS)] class Child : R|test/Base| { + public [ResolvedTo(BODY_RESOLVE)] constructor([ResolvedTo(BODY_RESOLVE)] primaryConstructorParameter: R|test/Base.Nested|): R|test/Child| { + super(R|/primaryConstructorParameter|) + } + + } \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsTypeRef.kt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsTypeRef.kt new file mode 100644 index 00000000000..d0410ac0f14 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsTypeRef.kt @@ -0,0 +1,9 @@ +package test + +open class Base(param: Nested) { + class Nested +} + +fun materialize(): T = TODO() + +class Child(primaryConstructorParameter: Nested) : Base(materialize<Nested>()) \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsTypeRef.txt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsTypeRef.txt new file mode 100644 index 00000000000..5b4945b8c24 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsTypeRef.txt @@ -0,0 +1,48 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + Element 7 + Scope: FirNestedClassifierScopeWithSubstitution + Classifiers: + FirRegularClassSymbol public final class Nested : R|kotlin/Any| + Static scope owner symbol: FirRegularClassSymbol public open class Base : R|kotlin/Any| + Element 8 + Scope: FirLocalScope + Properties: + FirValueParameterSymbol primaryConstructorParameter: R|test/Base.Nested| + +FILE: [ResolvedTo(IMPORTS)] superTypeCallArgumentsTypeRef.kt + public open [ResolvedTo(STATUS)] class Base : R|kotlin/Any| { + public [ResolvedTo(STATUS)] constructor([ResolvedTo(STATUS)] param: R|test/Base.Nested|): R|test/Base| { + LAZY_super + } + + public final [ResolvedTo(STATUS)] class Nested : R|kotlin/Any| { + public? [ResolvedTo(RAW_FIR)] constructor(): R|test/Base.Nested| { + LAZY_super + } + + } + + } + public final [ResolvedTo(CONTRACTS)] fun <[ResolvedTo(CONTRACTS)] T> materialize(): R|T| { + ^materialize TODO#() + } + public final [ResolvedTo(STATUS)] class Child : R|test/Base| { + public [ResolvedTo(BODY_RESOLVE)] constructor([ResolvedTo(BODY_RESOLVE)] primaryConstructorParameter: R|test/Base.Nested|): R|test/Child| { + super(R|test/materialize|()) + } + + } \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallee.kt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallee.kt new file mode 100644 index 00000000000..0d3059e9b95 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallee.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package test + +open class Base { + class Nested +} + +class Child : Base() \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallee.txt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallee.txt new file mode 100644 index 00000000000..80bd4b11966 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallee.txt @@ -0,0 +1,36 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + +FILE: [ResolvedTo(IMPORTS)] superTypeCallee.kt + public open [ResolvedTo(STATUS)] class Base : R|kotlin/Any| { + public [ResolvedTo(STATUS)] constructor(): R|test/Base| { + LAZY_super + } + + public? final? [ResolvedTo(RAW_FIR)] class Nested : R|kotlin/Any| { + public? [ResolvedTo(RAW_FIR)] constructor(): R|test/Base.Nested| { + LAZY_super + } + + } + + } + public final [ResolvedTo(STATUS)] class Child : R|test/Base| { + public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Child| { + super() + } + + } diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCalleeGenerics.kt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCalleeGenerics.kt new file mode 100644 index 00000000000..c692c132ee4 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCalleeGenerics.kt @@ -0,0 +1,7 @@ +package test + +open class Base { + class Nested +} + +class Child : Base<Any>() \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCalleeGenerics.txt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCalleeGenerics.txt new file mode 100644 index 00000000000..e0aff489872 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCalleeGenerics.txt @@ -0,0 +1,36 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + +FILE: [ResolvedTo(IMPORTS)] superTypeCalleeGenerics.kt + public open [ResolvedTo(STATUS)] class Base<[ResolvedTo(STATUS)] T> : R|kotlin/Any| { + public [ResolvedTo(STATUS)] constructor<[ResolvedTo(STATUS)] T>(): R|test/Base| { + LAZY_super + } + + public? final? [ResolvedTo(RAW_FIR)] class Nested : R|kotlin/Any| { + public? [ResolvedTo(RAW_FIR)] constructor(): R|test/Base.Nested| { + LAZY_super + } + + } + + } + public final [ResolvedTo(STATUS)] class Child : R|test/Base| { + public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Child| { + super|>() + } + + } diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedExpression.kt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedExpression.kt new file mode 100644 index 00000000000..01253ff56f5 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedExpression.kt @@ -0,0 +1,9 @@ +package test + +interface MyInterface + +open class Base { + class Nested : MyInterface +} + +class Child(constructorParam: MyInterface) : Base(), MyInterface by Nested() \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedExpression.txt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedExpression.txt new file mode 100644 index 00000000000..cda800e0ae9 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedExpression.txt @@ -0,0 +1,49 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + Element 7 + Scope: FirNestedClassifierScopeWithSubstitution + Classifiers: + FirRegularClassSymbol public final class Nested : R|test/MyInterface| + Static scope owner symbol: FirRegularClassSymbol public open class Base : R|kotlin/Any| + Element 8 + Scope: FirLocalScope + Properties: + FirValueParameterSymbol constructorParam: R|test/MyInterface| + +FILE: [ResolvedTo(IMPORTS)] superTypeDelegatedExpression.kt + public abstract [ResolvedTo(STATUS)] interface MyInterface : R|kotlin/Any| { + } + public open [ResolvedTo(STATUS)] class Base : R|kotlin/Any| { + public [ResolvedTo(STATUS)] constructor(): R|test/Base| { + LAZY_super + } + + public final [ResolvedTo(STATUS)] class Nested : R|test/MyInterface| { + public [ResolvedTo(STATUS)] constructor(): R|test/Base.Nested| { + LAZY_super<> + } + + } + + } + public final [ResolvedTo(STATUS)] class Child : R|test/Base|, R|test/MyInterface| { + public [ResolvedTo(BODY_RESOLVE)] constructor([ResolvedTo(BODY_RESOLVE)] constructorParam: R|test/MyInterface|): R|test/Child| { + super() + } + + private final [ResolvedTo(BODY_RESOLVE)] field $$delegate_0: R|test/MyInterface| = R|test/Base.Nested.Nested|() + + } \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedTypeRef.kt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedTypeRef.kt new file mode 100644 index 00000000000..70441d38261 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedTypeRef.kt @@ -0,0 +1,11 @@ +package test + +interface MyInterface + +open class Base { + class Nested : MyInterface +} + +class Child : Base, MyInterface by Nested() { + constructor(): super() +} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedTypeRef.txt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedTypeRef.txt new file mode 100644 index 00000000000..946038f0d06 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedTypeRef.txt @@ -0,0 +1,40 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + +FILE: [ResolvedTo(IMPORTS)] superTypeDelegatedTypeRef.kt + public abstract [ResolvedTo(STATUS)] interface MyInterface : R|kotlin/Any| { + } + public open [ResolvedTo(STATUS)] class Base : R|kotlin/Any| { + public [ResolvedTo(STATUS)] constructor(): R|test/Base| { + LAZY_super + } + + public final [ResolvedTo(STATUS)] class Nested : R|test/MyInterface| { + public [ResolvedTo(STATUS)] constructor(): R|test/Base.Nested| { + LAZY_super<> + } + + } + + } + public final [ResolvedTo(STATUS)] class Child : R|test/Base|, R|test/MyInterface| { + private final [ResolvedTo(BODY_RESOLVE)] field $$delegate_0: R|test/MyInterface| = R|test/Base.Nested.Nested|() + + public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Child| { + super() + } + + } diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRef.kt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRef.kt new file mode 100644 index 00000000000..3a64b45a3a3 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRef.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package test + +open class Base { + class Nested +} + +class Child : Base { + constructor(): super() {} +} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRef.txt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRef.txt new file mode 100644 index 00000000000..327392f872f --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRef.txt @@ -0,0 +1,36 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + +FILE: [ResolvedTo(IMPORTS)] superTypeRef.kt + public open [ResolvedTo(STATUS)] class Base : R|kotlin/Any| { + public [ResolvedTo(STATUS)] constructor(): R|test/Base| { + LAZY_super + } + + public? final? [ResolvedTo(RAW_FIR)] class Nested : R|kotlin/Any| { + public? [ResolvedTo(RAW_FIR)] constructor(): R|test/Base.Nested| { + LAZY_super + } + + } + + } + public final [ResolvedTo(STATUS)] class Child : R|test/Base| { + public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Child| { + super() + } + + } diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRefGenerics.kt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRefGenerics.kt new file mode 100644 index 00000000000..72e7472e93d --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRefGenerics.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package test + +open class Base { + class Nested +} + +class Child : Base<Any> { + constructor(): super() {} +} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRefGenerics.txt b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRefGenerics.txt new file mode 100644 index 00000000000..ae642bad86f --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRefGenerics.txt @@ -0,0 +1,36 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + +FILE: [ResolvedTo(IMPORTS)] superTypeRefGenerics.kt + public open [ResolvedTo(STATUS)] class Base<[ResolvedTo(STATUS)] T> : R|kotlin/Any| { + public [ResolvedTo(STATUS)] constructor<[ResolvedTo(STATUS)] T>(): R|test/Base| { + LAZY_super + } + + public? final? [ResolvedTo(RAW_FIR)] class Nested : R|kotlin/Any| { + public? [ResolvedTo(RAW_FIR)] constructor(): R|test/Base.Nested| { + LAZY_super + } + + } + + } + public final [ResolvedTo(STATUS)] class Child : R|test/Base| { + public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Child| { + super|>() + } + + } diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorScriptTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorScriptTestGenerated.java index 3ae272dd642..6f00e5ab543 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorScriptTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorScriptTestGenerated.java @@ -24,6 +24,16 @@ public class ContextCollectorScriptTestGenerated extends AbstractContextCollecto KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/contextCollector"), Pattern.compile("^(.+)\\.(kts)$"), null, true); } + @Nested + @TestMetadata("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions") + @TestDataPath("$PROJECT_ROOT") + public class ClassHeaderPositions { + @Test + public void testAllFilesPresentInClassHeaderPositions() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions"), Pattern.compile("^(.+)\\.(kts)$"), null, true); + } + } + @Nested @TestMetadata("analysis/low-level-api-fir/testdata/contextCollector/scripts") @TestDataPath("$PROJECT_ROOT") diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorSourceTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorSourceTestGenerated.java index 484d9976d8d..614ba332626 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorSourceTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorSourceTestGenerated.java @@ -102,6 +102,82 @@ public class ContextCollectorSourceTestGenerated extends AbstractContextCollecto runTest("analysis/low-level-api-fir/testdata/contextCollector/simple.kt"); } + @Nested + @TestMetadata("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions") + @TestDataPath("$PROJECT_ROOT") + public class ClassHeaderPositions { + @Test + public void testAllFilesPresentInClassHeaderPositions() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions"), Pattern.compile("^(.+)\\.(kt)$"), null, true); + } + + @Test + @TestMetadata("contextReceiver.kt") + public void testContextReceiver() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/contextReceiver.kt"); + } + + @Test + @TestMetadata("primaryConstructorParameter_initializerExpression.kt") + public void testPrimaryConstructorParameter_initializerExpression() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_initializerExpression.kt"); + } + + @Test + @TestMetadata("primaryConstructorParameter_typeRef.kt") + public void testPrimaryConstructorParameter_typeRef() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/primaryConstructorParameter_typeRef.kt"); + } + + @Test + @TestMetadata("superTypeCallArgumentsExpression.kt") + public void testSuperTypeCallArgumentsExpression() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsExpression.kt"); + } + + @Test + @TestMetadata("superTypeCallArgumentsTypeRef.kt") + public void testSuperTypeCallArgumentsTypeRef() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallArgumentsTypeRef.kt"); + } + + @Test + @TestMetadata("superTypeCallee.kt") + public void testSuperTypeCallee() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCallee.kt"); + } + + @Test + @TestMetadata("superTypeCalleeGenerics.kt") + public void testSuperTypeCalleeGenerics() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeCalleeGenerics.kt"); + } + + @Test + @TestMetadata("superTypeDelegatedExpression.kt") + public void testSuperTypeDelegatedExpression() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedExpression.kt"); + } + + @Test + @TestMetadata("superTypeDelegatedTypeRef.kt") + public void testSuperTypeDelegatedTypeRef() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeDelegatedTypeRef.kt"); + } + + @Test + @TestMetadata("superTypeRef.kt") + public void testSuperTypeRef() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRef.kt"); + } + + @Test + @TestMetadata("superTypeRefGenerics.kt") + public void testSuperTypeRefGenerics() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/classHeaderPositions/superTypeRefGenerics.kt"); + } + } + @Nested @TestMetadata("analysis/low-level-api-fir/testdata/contextCollector/scripts") @TestDataPath("$PROJECT_ROOT")