From a064db8da6c2fa0398191a3c15120c36cb6816d6 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Fri, 4 Aug 2023 22:13:46 +0900 Subject: [PATCH] [LL API] Add some more 'ContextCollector' tests --- .../testdata/contextCollector/enumValue.kt | 23 ++++++ .../testdata/contextCollector/enumValue.txt | 81 +++++++++++++++++++ .../testdata/contextCollector/file.kt | 15 ++++ .../testdata/contextCollector/file.txt | 36 +++++++++ .../primaryConstructorParameter.kt | 5 ++ .../primaryConstructorParameter.txt | 36 +++++++++ .../fir/ContextCollectorTestGenerated.java | 18 +++++ 7 files changed, 214 insertions(+) create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/enumValue.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/enumValue.txt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/file.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/file.txt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/primaryConstructorParameter.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/primaryConstructorParameter.txt diff --git a/analysis/low-level-api-fir/testdata/contextCollector/enumValue.kt b/analysis/low-level-api-fir/testdata/contextCollector/enumValue.kt new file mode 100644 index 00000000000..b8e051e3ada --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/enumValue.kt @@ -0,0 +1,23 @@ +enum class Direction { + NORTH { + override val code: Int + get() = 1 + }, + + EAST { + override val code: Int + get() = 2 + }, + + SOUTH { + override val code: Int + get() = 3 + }, + + WEST { + override val code: Int + get() = 4 + }; + + abstract val code: Int +} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/enumValue.txt b/analysis/low-level-api-fir/testdata/contextCollector/enumValue.txt new file mode 100644 index 00000000000..20d8600a3f2 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/enumValue.txt @@ -0,0 +1,81 @@ +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 + Implicit receiver: + FirRegularClassSymbol public final companion object Companion : R|kotlin/Any| + Type: kotlin/Enum.Companion + Element 8 + Scope: FirNestedClassifierScopeWithSubstitution + Classifiers: + FirRegularClassSymbol public final companion object Companion : R|kotlin/Any| + Static scope owner symbol: FirRegularClassSymbol public abstract class Enum|> : R|kotlin/Comparable|, R|java/io/Serializable| + Element 9 + Scope: FirNameAwareOnlyCallablesScope + Functions + FirNamedFunctionSymbol public final static fun valueOf(value: R|kotlin/String|): R|Direction| + FirNamedFunctionSymbol public final static fun values(): R|kotlin/Array| + Properties: + FirEnumEntrySymbol public final static enum entry EAST: R|Direction| = object : R|Direction| + FirEnumEntrySymbol public final static enum entry NORTH: R|Direction| = LAZY_EXPRESSION + FirEnumEntrySymbol public final static enum entry SOUTH: R|Direction| = LAZY_EXPRESSION + FirEnumEntrySymbol public final static enum entry WEST: R|Direction| = LAZY_EXPRESSION + FirPropertySymbol public final static val entries: R|kotlin/enums/EnumEntries| + public get(): R|kotlin/enums/EnumEntries| + Element 10 + Implicit receiver: + FirAnonymousObjectSymbol object : R|Direction| + Type: + Element 11 + Scope: FirLocalScope + Properties: + FirBackingFieldSymbol private : R|kotlin/Int| + Element 12 + Scope: FirLocalScope + +FILE: [ResolvedTo(IMPORTS)] enumValue.kt + public final [ResolvedTo(STATUS)] enum class Direction : R|kotlin/Enum| { + private [ResolvedTo(STATUS)] constructor(): R|Direction| { + LAZY_super|> + } + + public final static [ResolvedTo(STATUS)] enum entry NORTH: R|Direction| = LAZY_EXPRESSION + public final static [ResolvedTo(BODY_RESOLVE)] enum entry EAST: R|Direction| = object : R|Direction| { + private [ResolvedTo(BODY_RESOLVE)] constructor(): R|| { + super() + } + + public open override [ResolvedTo(BODY_RESOLVE)] val code: R|kotlin/Int| + public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/Int| { + ^ Int(2) + } + + } + + public final static [ResolvedTo(STATUS)] enum entry SOUTH: R|Direction| = LAZY_EXPRESSION + public final static [ResolvedTo(STATUS)] enum entry WEST: R|Direction| = LAZY_EXPRESSION + public abstract [ResolvedTo(STATUS)] val code: R|kotlin/Int| + public [ResolvedTo(STATUS)] get(): R|kotlin/Int| + + public final static [ResolvedTo(STATUS)] fun values(): R|kotlin/Array| { + } + + public final static [ResolvedTo(STATUS)] fun valueOf([ResolvedTo(STATUS)] value: R|kotlin/String|): R|Direction| { + } + + public final static [ResolvedTo(STATUS)] val entries: R|kotlin/enums/EnumEntries| + public [ResolvedTo(STATUS)] get(): R|kotlin/enums/EnumEntries| + + } diff --git a/analysis/low-level-api-fir/testdata/contextCollector/file.kt b/analysis/low-level-api-fir/testdata/contextCollector/file.kt new file mode 100644 index 00000000000..6c59d4ba87e --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/file.kt @@ -0,0 +1,15 @@ +package test + +import java.util.List + +fun test() = List::class + +fun other(): Int { + return "foo".length +} + +class Foo { + fun foo() { + require(other() == 3) + } +} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/file.txt b/analysis/low-level-api-fir/testdata/contextCollector/file.txt new file mode 100644 index 00000000000..fdaa5dc853c --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/file.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 + Import name:List + Qualified name: java.util.List + Is all under: false + +FILE: [ResolvedTo(IMPORTS)] file.kt + public final [ResolvedTo(BODY_RESOLVE)] fun test(): R|kotlin/reflect/KClass>| { + ^test (Q|java/util/List|) + } + public final [ResolvedTo(BODY_RESOLVE)] fun other(): R|kotlin/Int| { + ^other String(foo).R|kotlin/String.length| + } + public final [ResolvedTo(STATUS)] class Foo : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Foo| { + super() + } + + public final [ResolvedTo(BODY_RESOLVE)] fun foo(): R|kotlin/Unit| { + #(==(R|test/other|(), Int(3))) + } + + } diff --git a/analysis/low-level-api-fir/testdata/contextCollector/primaryConstructorParameter.kt b/analysis/low-level-api-fir/testdata/contextCollector/primaryConstructorParameter.kt new file mode 100644 index 00000000000..13c153a510e --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/primaryConstructorParameter.kt @@ -0,0 +1,5 @@ +class Foo( + val a: String = "foo" + val b: Int = a.length, + val c: Long = (a.length - 1).toLong() +) \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/primaryConstructorParameter.txt b/analysis/low-level-api-fir/testdata/contextCollector/primaryConstructorParameter.txt new file mode 100644 index 00000000000..df64f0982a2 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/primaryConstructorParameter.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 + Element 7 + Implicit receiver: + FirRegularClassSymbol public final class Foo : R|kotlin/Any| + Type: Foo + +FILE: [ResolvedTo(IMPORTS)] primaryConstructorParameter.kt + public final [ResolvedTo(STATUS)] class Foo : R|kotlin/Any| { + public [ResolvedTo(STATUS)] constructor([ResolvedTo(STATUS)] a: R|kotlin/String| = LAZY_EXPRESSION, [ResolvedTo(STATUS)] b: R|kotlin/Int| = LAZY_EXPRESSION, [ResolvedTo(STATUS)] c: R|kotlin/Long| = LAZY_EXPRESSION): R|Foo| { + LAZY_super + } + + public final [ResolvedTo(STATUS)] val a: R|kotlin/String| = R|/a| + public [ResolvedTo(STATUS)] get(): R|kotlin/String| + + public final [ResolvedTo(BODY_RESOLVE)] val b: R|kotlin/Int| = R|/b| + public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/Int| + + public final [ResolvedTo(STATUS)] val c: R|kotlin/Long| = R|/c| + public [ResolvedTo(STATUS)] get(): R|kotlin/Long| + + } diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorTestGenerated.java index 4bf2c2afbee..2d1e8ba3397 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorTestGenerated.java @@ -36,6 +36,12 @@ public class ContextCollectorTestGenerated extends AbstractContextCollectorTest runTest("analysis/low-level-api-fir/testdata/contextCollector/contextReceiversClass.kt"); } + @Test + @TestMetadata("enumValue.kt") + public void testEnumValue() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/enumValue.kt"); + } + @Test @TestMetadata("extensionFunction.kt") public void testExtensionFunction() throws Exception { @@ -48,6 +54,12 @@ public class ContextCollectorTestGenerated extends AbstractContextCollectorTest runTest("analysis/low-level-api-fir/testdata/contextCollector/extensionLambdas.kt"); } + @Test + @TestMetadata("file.kt") + public void testFile() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/file.kt"); + } + @Test @TestMetadata("innerClasses.kt") public void testInnerClasses() throws Exception { @@ -66,6 +78,12 @@ public class ContextCollectorTestGenerated extends AbstractContextCollectorTest runTest("analysis/low-level-api-fir/testdata/contextCollector/nestedClasses.kt"); } + @Test + @TestMetadata("primaryConstructorParameter.kt") + public void testPrimaryConstructorParameter() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/primaryConstructorParameter.kt"); + } + @Test @TestMetadata("simple.kt") public void testSimple() throws Exception {