From d49913944cd6f6c9d2171fd27b48f75f0cc8abb0 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Fri, 26 Feb 2021 19:22:19 +0100 Subject: [PATCH] FIR: add tests which checks that every declaration in file has body resolve phase after resolving the fiile --- .../kotlin/generators/tests/GenerateTests.kt | 4 + .../annonymousClass.fir.txt | 13 +++ .../annonymousClass.kt | 5 + .../innerDeclarationsResolve/class.fir.txt | 20 ++++ .../innerDeclarationsResolve/class.kt | 8 ++ .../constructorParameter.fir.txt | 10 ++ .../constructorParameter.kt | 1 + .../funWithoutTypes.fir.txt | 3 + .../funWithoutTypes.kt | 3 + .../functionValueParameter.fir.txt | 12 +++ .../functionValueParameter.kt | 9 ++ .../functionWithImplicitType.fir.txt | 6 ++ .../functionWithImplicitType.kt | 5 + .../innerDeclarationsResolve/lambda.fir.txt | 23 +++++ .../lambdaInImplicitFunBody.fir.txt | 23 +++++ .../lambdaInImplicitFunBody.kt | 13 +++ .../lambdaInImplicitPropertyBody.fir.txt | 25 +++++ .../lambdaInImplicitPropertyBody.kt | 14 +++ .../lambdasInWithBodyFunction.fir.txt | 26 ++++++ .../lambdasInWithBodyFunction.kt | 15 +++ .../localClass.fir.txt | 13 +++ .../innerDeclarationsResolve/localClass.kt | 5 + .../propertyWithGetterAndSetter.fir.txt | 8 ++ .../propertyWithGetterAndSetter.kt | 5 + .../propertyWithSetter.fir.txt | 25 +++++ .../propertyWithSetter.kt | 14 +++ ...stractInnerDeclarationsResolvePhaseTest.kt | 36 ++++++++ ...DeclarationsResolvePhaseTestGenerated.java | 91 +++++++++++++++++++ 28 files changed, 435 insertions(+) create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/annonymousClass.fir.txt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/annonymousClass.kt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/class.fir.txt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/class.kt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/constructorParameter.fir.txt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/constructorParameter.kt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/funWithoutTypes.fir.txt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/funWithoutTypes.kt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionValueParameter.fir.txt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionValueParameter.kt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionWithImplicitType.fir.txt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionWithImplicitType.kt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambda.fir.txt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitFunBody.fir.txt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitFunBody.kt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitPropertyBody.fir.txt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitPropertyBody.kt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdasInWithBodyFunction.fir.txt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdasInWithBodyFunction.kt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/localClass.fir.txt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/localClass.kt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithGetterAndSetter.fir.txt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithGetterAndSetter.kt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithSetter.fir.txt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithSetter.kt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/resolve/AbstractInnerDeclarationsResolvePhaseTest.kt create mode 100644 idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/resolve/InnerDeclarationsResolvePhaseTestGenerated.java diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index efe60681233..05a944a2e18 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -86,6 +86,7 @@ import org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirMultiModuleResolve import org.jetbrains.kotlin.idea.fir.low.level.api.diagnostic.AbstractDiagnosticTraversalCounterTest import org.jetbrains.kotlin.idea.fir.low.level.api.file.structure.AbstractFileStructureAndOutOfBlockModificationTrackerConsistencyTest import org.jetbrains.kotlin.idea.fir.low.level.api.file.structure.AbstractFileStructureTest +import org.jetbrains.kotlin.idea.fir.low.level.api.resolve.AbstractInnerDeclarationsResolvePhaseTest import org.jetbrains.kotlin.idea.fir.low.level.api.sessions.AbstractSessionsInvalidationTest import org.jetbrains.kotlin.idea.fir.low.level.api.trackers.AbstractProjectWideOutOfBlockKotlinModificationTrackerTest import org.jetbrains.kotlin.idea.folding.AbstractKotlinFoldingTest @@ -1085,6 +1086,9 @@ fun main(args: Array) { testClass { model("sessionInvalidation", recursive = false, extension = null) } + testClass { + model("innerDeclarationsResolve") + } } testGroup("idea/idea-fir/tests", "idea") { diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/annonymousClass.fir.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/annonymousClass.fir.txt new file mode 100644 index 00000000000..aa49d47005b --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/annonymousClass.fir.txt @@ -0,0 +1,13 @@ +FILE: annonymousClass.kt + public final [BODY_RESOLVE] fun x(): R|kotlin/Unit| { + [BODY_RESOLVE] lval x: R|| = object : R|kotlin/Any| { + private [BODY_RESOLVE] constructor(): R|| { + super() + } + + public final [BODY_RESOLVE] fun foo(): R|kotlin/Unit| { + } + + } + + } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/annonymousClass.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/annonymousClass.kt new file mode 100644 index 00000000000..7e5ec8b81b3 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/annonymousClass.kt @@ -0,0 +1,5 @@ +fun x() { + val x = object: Any() { + fun foo(){} + } +} \ No newline at end of file diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/class.fir.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/class.fir.txt new file mode 100644 index 00000000000..686411ea28e --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/class.fir.txt @@ -0,0 +1,20 @@ +FILE: class.kt + public final [BODY_RESOLVE] class B : R|kotlin/Any| { + public [BODY_RESOLVE] constructor(): R|B| { + super() + } + + public final [BODY_RESOLVE] fun q(): { + } + + private final [BODY_RESOLVE] val y: R|ERROR CLASS: Symbol not found, for `C`| = this@R|/B|.R|/B.q|() + [BODY_RESOLVE] private get(): R|ERROR CLASS: Symbol not found, for `C`| + + public final [BODY_RESOLVE] fun foo([BODY_RESOLVE] a: ): { + ^foo #(R|/a|, = [BODY_RESOLVE] with@fun (): R|ERROR CLASS: Unresolved name: bar| { + ^ #(String(a), this@R|/B|.R|/B.y|) + } + ) + } + + } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/class.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/class.kt new file mode 100644 index 00000000000..606ccd67dbf --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/class.kt @@ -0,0 +1,8 @@ +class B { + fun q(): C {} + private val y = q() + + fun foo(a: A) = with(a) { + bar("a", y) + } +} \ No newline at end of file diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/constructorParameter.fir.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/constructorParameter.fir.txt new file mode 100644 index 00000000000..e7d2bb5b48b --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/constructorParameter.fir.txt @@ -0,0 +1,10 @@ +FILE: constructorParameter.kt + public final [BODY_RESOLVE] class A : R|kotlin/Any| { + public [BODY_RESOLVE] constructor([BODY_RESOLVE] x: R|kotlin/String|): R|A| { + super() + } + + public final [BODY_RESOLVE] val x: R|kotlin/String| = R|/x| + [BODY_RESOLVE] public get(): R|kotlin/String| + + } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/constructorParameter.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/constructorParameter.kt new file mode 100644 index 00000000000..f88074aa4a2 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/constructorParameter.kt @@ -0,0 +1 @@ +class A(val x: String) \ No newline at end of file diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/funWithoutTypes.fir.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/funWithoutTypes.fir.txt new file mode 100644 index 00000000000..a0db93a3615 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/funWithoutTypes.fir.txt @@ -0,0 +1,3 @@ +FILE: funWithoutTypes.kt + public final [BODY_RESOLVE] fun main(): R|kotlin/Unit| { + } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/funWithoutTypes.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/funWithoutTypes.kt new file mode 100644 index 00000000000..f1eafa99a88 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/funWithoutTypes.kt @@ -0,0 +1,3 @@ +fun main() { + +} \ No newline at end of file diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionValueParameter.fir.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionValueParameter.fir.txt new file mode 100644 index 00000000000..20370940989 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionValueParameter.fir.txt @@ -0,0 +1,12 @@ +FILE: functionValueParameter.kt + public final [BODY_RESOLVE] fun bar([BODY_RESOLVE] a: R|kotlin/Int|, [BODY_RESOLVE] b: R|(kotlin/Boolean) -> kotlin/Unit|): R|kotlin/Unit| { + } + public final [BODY_RESOLVE] class A : R|kotlin/Any| { + public [BODY_RESOLVE] constructor(): R|A| { + super() + } + + public final [BODY_RESOLVE] fun foo([BODY_RESOLVE] x: R|kotlin/String|, [BODY_RESOLVE] y: R|() -> kotlin/String|): R|kotlin/Unit| { + } + + } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionValueParameter.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionValueParameter.kt new file mode 100644 index 00000000000..58184826c94 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionValueParameter.kt @@ -0,0 +1,9 @@ +fun bar(a: Int, b: (Boolean) -> Unit) { + +} + +class A { + fun foo(x: String, y: () -> String) { + + } +} \ No newline at end of file diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionWithImplicitType.fir.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionWithImplicitType.fir.txt new file mode 100644 index 00000000000..2a998a49f90 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionWithImplicitType.fir.txt @@ -0,0 +1,6 @@ +FILE: functionWithImplicitType.kt + public final [BODY_RESOLVE] fun checkSubtype([BODY_RESOLVE] t: R|T|): R|T| { + ^checkSubtype R|/t| + } + public final [BODY_RESOLVE] val ab: R|kotlin/collections/List?| = R|/checkSubtype|?|>(Q|java/util/Collections|.R|java/util/Collections.emptyList|!|>()) + [BODY_RESOLVE] public get(): R|kotlin/collections/List?| diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionWithImplicitType.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionWithImplicitType.kt new file mode 100644 index 00000000000..e7a7f0c8db9 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionWithImplicitType.kt @@ -0,0 +1,5 @@ +import java.util.Collections + +fun checkSubtype(t: T) = t + +val ab = checkSubtype?>(Collections.emptyList()) diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambda.fir.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambda.fir.txt new file mode 100644 index 00000000000..4a039ac073a --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambda.fir.txt @@ -0,0 +1,23 @@ +FILE: lambda.kt + public final inline [BODY_RESOLVE] fun with([BODY_RESOLVE] receiver: R|T|, [BODY_RESOLVE] block: R|T.() -> R|): R|R| { + ^with R|/block|.R|SubstitutionOverride|(R|/receiver|) + } + public final inline [BODY_RESOLVE] fun R|T|.let([BODY_RESOLVE] block: R|(T) -> R|): R|R| { + ^let R|/block|.R|SubstitutionOverride|(this@R|/let|) + } + public final [BODY_RESOLVE] class B : R|kotlin/Any| { + public [BODY_RESOLVE] constructor(): R|B| { + super() + } + + public final [BODY_RESOLVE] fun foo([BODY_RESOLVE] a: R|kotlin/Int|): R|kotlin/String| { + ^foo R|/with|(R|/a|, = [BODY_RESOLVE] with@fun R|kotlin/Int|.(): R|kotlin/String| { + ^ this@R|special/anonymous|.R|kotlin/Any.toString|().R|/let|( = [BODY_RESOLVE] let@fun ([BODY_RESOLVE] it: R|kotlin/String|): R|kotlin/String| { + ^ R|/it| + } + ) + } + ) + } + + } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitFunBody.fir.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitFunBody.fir.txt new file mode 100644 index 00000000000..2a096f77245 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitFunBody.fir.txt @@ -0,0 +1,23 @@ +FILE: lambdaInImplicitFunBody.kt + public final inline [BODY_RESOLVE] fun with([BODY_RESOLVE] receiver: R|T|, [BODY_RESOLVE] block: R|T.() -> R|): R|R| { + ^with R|/block|.R|SubstitutionOverride|(R|/receiver|) + } + public final inline [BODY_RESOLVE] fun R|T|.let([BODY_RESOLVE] block: R|(T) -> R|): R|R| { + ^let R|/block|.R|SubstitutionOverride|(this@R|/let|) + } + public final [BODY_RESOLVE] class B : R|kotlin/Any| { + public [BODY_RESOLVE] constructor(): R|B| { + super() + } + + public final [BODY_RESOLVE] fun foo([BODY_RESOLVE] a: R|kotlin/Int|): R|kotlin/String| { + ^foo R|/with|(R|/a|, = [BODY_RESOLVE] with@fun R|kotlin/Int|.(): R|kotlin/String| { + ^ this@R|special/anonymous|.R|kotlin/Any.toString|().R|/let|( = [BODY_RESOLVE] let@fun ([BODY_RESOLVE] it: R|kotlin/String|): R|kotlin/String| { + ^ R|/it| + } + ) + } + ) + } + + } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitFunBody.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitFunBody.kt new file mode 100644 index 00000000000..f60c0378525 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitFunBody.kt @@ -0,0 +1,13 @@ +inline fun with(receiver: T, block: T.() -> R): R { + return receiver.block() +} + +inline fun T.let(block: (T) -> R): R { + return block(this) +} + +class B { + fun foo(a: Int) = with(a) { + toString().let { it } + } +} \ No newline at end of file diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitPropertyBody.fir.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitPropertyBody.fir.txt new file mode 100644 index 00000000000..57a44d22288 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitPropertyBody.fir.txt @@ -0,0 +1,25 @@ +FILE: lambdaInImplicitPropertyBody.kt + public final inline [BODY_RESOLVE] fun with([BODY_RESOLVE] receiver: R|T|, [BODY_RESOLVE] block: R|T.() -> R|): R|R| { + ^with R|/block|.R|SubstitutionOverride|(R|/receiver|) + } + public final inline [BODY_RESOLVE] fun R|T|.let([BODY_RESOLVE] block: R|(T) -> R|): R|R| { + ^let R|/block|.R|SubstitutionOverride|(this@R|/let|) + } + public final [BODY_RESOLVE] class B : R|kotlin/Any| { + public [BODY_RESOLVE] constructor(): R|B| { + super() + } + + public final [BODY_RESOLVE] val a: R|kotlin/Int| = Int(10) + [BODY_RESOLVE] public get(): R|kotlin/Int| + + public final [BODY_RESOLVE] val x: R|kotlin/String| = R|/with|(this@R|/B|.R|/B.a|, = [BODY_RESOLVE] with@fun R|kotlin/Int|.(): R|kotlin/String| { + ^ this@R|special/anonymous|.R|kotlin/Any.toString|().R|/let|( = [BODY_RESOLVE] let@fun ([BODY_RESOLVE] it: R|kotlin/String|): R|kotlin/String| { + ^ R|/it| + } + ) + } + ) + [BODY_RESOLVE] public get(): R|kotlin/String| + + } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitPropertyBody.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitPropertyBody.kt new file mode 100644 index 00000000000..bc562eec574 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitPropertyBody.kt @@ -0,0 +1,14 @@ +inline fun with(receiver: T, block: T.() -> R): R { + return receiver.block() +} + +inline fun T.let(block: (T) -> R): R { + return block(this) +} + +class B { + val a: Int = 10 + val x = with(a) { + toString().let { it } + } +} \ No newline at end of file diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdasInWithBodyFunction.fir.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdasInWithBodyFunction.fir.txt new file mode 100644 index 00000000000..7f801170a24 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdasInWithBodyFunction.fir.txt @@ -0,0 +1,26 @@ +FILE: lambdasInWithBodyFunction.kt + public final inline [BODY_RESOLVE] fun with([BODY_RESOLVE] receiver: R|T|, [BODY_RESOLVE] block: R|T.() -> R|): R|R| { + ^with R|/block|.R|SubstitutionOverride|(R|/receiver|) + } + public final inline [BODY_RESOLVE] fun R|T|.let([BODY_RESOLVE] block: R|(T) -> R|): R|R| { + ^let R|/block|.R|SubstitutionOverride|(this@R|/let|) + } + public final [BODY_RESOLVE] class A : R|kotlin/Any| { + public [BODY_RESOLVE] constructor(): R|A| { + super() + } + + public final [BODY_RESOLVE] fun foo(): R|kotlin/Unit| { + [BODY_RESOLVE] lval a: R|kotlin/Int| = R|/with|(Int(1), = [BODY_RESOLVE] with@fun R|kotlin/Int|.(): R|kotlin/Int| { + ^ this@R|special/anonymous|.R|/let|( = [BODY_RESOLVE] let@fun ([BODY_RESOLVE] it: R|kotlin/Int|): R|kotlin/Int| { + ^ R|/it| + } + ) + } + ).R|/let|( = [BODY_RESOLVE] let@fun ([BODY_RESOLVE] it: R|kotlin/Int|): R|kotlin/Int| { + ^ Int(2) + } + ) + } + + } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdasInWithBodyFunction.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdasInWithBodyFunction.kt new file mode 100644 index 00000000000..2fcba5316b3 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdasInWithBodyFunction.kt @@ -0,0 +1,15 @@ +inline fun with(receiver: T, block: T.() -> R): R { + return receiver.block() +} + +inline fun T.let(block: (T) -> R): R { + return block(this) +} + +class A { + fun foo() { + val a = with(1) { + this.let { it } + }.let { 2 } + } +} diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/localClass.fir.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/localClass.fir.txt new file mode 100644 index 00000000000..35af11c6c6b --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/localClass.fir.txt @@ -0,0 +1,13 @@ +FILE: localClass.kt + public final [BODY_RESOLVE] fun x(): R|kotlin/Unit| { + local final [BODY_RESOLVE] class Local : R|kotlin/Any| { + public [BODY_RESOLVE] constructor(): R|Local| { + super() + } + + public final [BODY_RESOLVE] fun foo(): R|kotlin/Unit| { + } + + } + + } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/localClass.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/localClass.kt new file mode 100644 index 00000000000..a565210b59b --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/localClass.kt @@ -0,0 +1,5 @@ +fun x() { + class Local { + fun foo(){} + } +} \ No newline at end of file diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithGetterAndSetter.fir.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithGetterAndSetter.fir.txt new file mode 100644 index 00000000000..7050cdc1792 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithGetterAndSetter.fir.txt @@ -0,0 +1,8 @@ +FILE: propertyWithGetterAndSetter.kt + public final [BODY_RESOLVE] var withGetterAndSetter: R|kotlin/Int| = Int(42) + [BODY_RESOLVE] public get(): R|kotlin/Int| { + ^ F|/withGetterAndSetter| + } + [BODY_RESOLVE] public set([BODY_RESOLVE] value: R|kotlin/Int|): R|kotlin/Unit| { + F|/withGetterAndSetter| = R|/value| + } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithGetterAndSetter.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithGetterAndSetter.kt new file mode 100644 index 00000000000..e3481db3d06 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithGetterAndSetter.kt @@ -0,0 +1,5 @@ +var withGetterAndSetter: Int = 42 + get() = field + set(value) { + field = value + } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithSetter.fir.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithSetter.fir.txt new file mode 100644 index 00000000000..450b49694c8 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithSetter.fir.txt @@ -0,0 +1,25 @@ +FILE: propertyWithSetter.kt + public abstract [BODY_RESOLVE] class Foo : R|kotlin/Any| { + public [BODY_RESOLVE] constructor(): R|Foo| { + super() + } + + public abstract [BODY_RESOLVE] var id: R|kotlin/Int| + [BODY_RESOLVE] public get(): R|kotlin/Int| + [BODY_RESOLVE] protected set([BODY_RESOLVE] value: R|kotlin/Int|): R|kotlin/Unit| + + } + public final [BODY_RESOLVE] class Bar : R|Foo| { + public [BODY_RESOLVE] constructor(): R|Bar| { + super() + } + + public final override [BODY_RESOLVE] var id: R|kotlin/Int| = Int(1) + [BODY_RESOLVE] public get(): R|kotlin/Int| + [BODY_RESOLVE] public set([BODY_RESOLVE] value: R|kotlin/Int|): R|kotlin/Unit| + + } + public final [BODY_RESOLVE] fun test(): R|kotlin/Unit| { + [BODY_RESOLVE] lval bar: R|Bar| = R|/Bar.Bar|() + R|/bar|.R|/Bar.id| = Int(1) + } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithSetter.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithSetter.kt new file mode 100644 index 00000000000..91b1d6f5dc8 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithSetter.kt @@ -0,0 +1,14 @@ +abstract class Foo { + abstract var id: Int + protected set +} + +class Bar : Foo() { + override var id: Int = 1 + public set +} + +fun test() { + val bar = Bar() + bar.id = 1 +} \ No newline at end of file diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/resolve/AbstractInnerDeclarationsResolvePhaseTest.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/resolve/AbstractInnerDeclarationsResolvePhaseTest.kt new file mode 100644 index 00000000000..8fa27f78d8f --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/resolve/AbstractInnerDeclarationsResolvePhaseTest.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2021 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 org.jetbrains.kotlin.idea.fir.low.level.api.resolve + +import com.intellij.openapi.util.io.FileUtil +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirRenderer +import org.jetbrains.kotlin.fir.declarations.FirFile +import org.jetbrains.kotlin.fir.render +import org.jetbrains.kotlin.fir.visitors.FirVisitor +import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid +import org.jetbrains.kotlin.idea.fir.low.level.api.api.getOrBuildFir +import org.jetbrains.kotlin.idea.fir.low.level.api.api.getOrBuildFirOfType +import org.jetbrains.kotlin.idea.fir.low.level.api.api.getResolveState +import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase +import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.test.KotlinTestUtils +import java.io.File + +abstract class AbstractInnerDeclarationsResolvePhaseTest : KotlinLightCodeInsightFixtureTestCase() { + override fun isFirPlugin(): Boolean = true + fun doTest(path: String) { + val testDataFile = File(path) + val ktFile = myFixture.configureByText(testDataFile.name, FileUtil.loadFile(testDataFile)) as KtFile + + val resolveState = ktFile.getResolveState() + val firFile = ktFile.getOrBuildFirOfType(resolveState) + + val actual = firFile.render(FirRenderer.RenderMode.WithResolvePhases) + val expectedFileName = testDataFile.name.replace(".kt", ".fir.txt") + KotlinTestUtils.assertEqualsToFile(testDataFile.parentFile.resolve(expectedFileName), actual) + } +} diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/resolve/InnerDeclarationsResolvePhaseTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/resolve/InnerDeclarationsResolvePhaseTestGenerated.java new file mode 100644 index 00000000000..908f2848cd1 --- /dev/null +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/resolve/InnerDeclarationsResolvePhaseTestGenerated.java @@ -0,0 +1,91 @@ +/* + * Copyright 2010-2021 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 org.jetbrains.kotlin.idea.fir.low.level.api.resolve; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class InnerDeclarationsResolvePhaseTestGenerated extends AbstractInnerDeclarationsResolvePhaseTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInInnerDeclarationsResolve() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("annonymousClass.kt") + public void testAnnonymousClass() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/annonymousClass.kt"); + } + + @TestMetadata("class.kt") + public void testClass() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/class.kt"); + } + + @TestMetadata("constructorParameter.kt") + public void testConstructorParameter() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/constructorParameter.kt"); + } + + @TestMetadata("funWithoutTypes.kt") + public void testFunWithoutTypes() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/funWithoutTypes.kt"); + } + + @TestMetadata("functionValueParameter.kt") + public void testFunctionValueParameter() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionValueParameter.kt"); + } + + @TestMetadata("functionWithImplicitType.kt") + public void testFunctionWithImplicitType() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionWithImplicitType.kt"); + } + + @TestMetadata("lambdaInImplicitFunBody.kt") + public void testLambdaInImplicitFunBody() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitFunBody.kt"); + } + + @TestMetadata("lambdaInImplicitPropertyBody.kt") + public void testLambdaInImplicitPropertyBody() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitPropertyBody.kt"); + } + + @TestMetadata("lambdasInWithBodyFunction.kt") + public void testLambdasInWithBodyFunction() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdasInWithBodyFunction.kt"); + } + + @TestMetadata("localClass.kt") + public void testLocalClass() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/localClass.kt"); + } + + @TestMetadata("propertyWithGetterAndSetter.kt") + public void testPropertyWithGetterAndSetter() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithGetterAndSetter.kt"); + } + + @TestMetadata("propertyWithSetter.kt") + public void testPropertyWithSetter() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithSetter.kt"); + } +}