Change nestedClasses logic to accept classes with nested type aliases
#KT-47650 fixed
This commit is contained in:
+6
@@ -35521,6 +35521,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/reflection/classes/nestedClasses.kt");
|
runTest("compiler/testData/codegen/box/reflection/classes/nestedClasses.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("nestedClassesInScript.kt")
|
||||||
|
public void testNestedClassesInScript() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/classes/nestedClassesInScript.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("nestedClassesJava.kt")
|
@TestMetadata("nestedClassesJava.kt")
|
||||||
public void testNestedClassesJava() throws Exception {
|
public void testNestedClassesJava() throws Exception {
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
|
// IGNORE_LIGHT_ANALYSIS
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// WITH_REFLECT
|
||||||
|
|
||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val kClass = Script::class
|
||||||
|
val nestedClasses = kClass.nestedClasses
|
||||||
|
val nestedClass = nestedClasses.single()
|
||||||
|
return nestedClass.simpleName!!
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// FILE: Script.kts
|
||||||
|
|
||||||
|
class OK
|
||||||
|
typealias Tazz = List<OK>
|
||||||
|
val x: Tazz = listOf()
|
||||||
|
x
|
||||||
+6
@@ -35479,6 +35479,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/reflection/classes/nestedClasses.kt");
|
runTest("compiler/testData/codegen/box/reflection/classes/nestedClasses.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("nestedClassesInScript.kt")
|
||||||
|
public void testNestedClassesInScript() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/classes/nestedClassesInScript.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("nestedClassesJava.kt")
|
@TestMetadata("nestedClassesJava.kt")
|
||||||
public void testNestedClassesJava() throws Exception {
|
public void testNestedClassesJava() throws Exception {
|
||||||
|
|||||||
+6
@@ -35521,6 +35521,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/reflection/classes/nestedClasses.kt");
|
runTest("compiler/testData/codegen/box/reflection/classes/nestedClasses.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("nestedClassesInScript.kt")
|
||||||
|
public void testNestedClassesInScript() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/classes/nestedClassesInScript.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("nestedClassesJava.kt")
|
@TestMetadata("nestedClassesJava.kt")
|
||||||
public void testNestedClassesJava() throws Exception {
|
public void testNestedClassesJava() throws Exception {
|
||||||
|
|||||||
+5
@@ -28052,6 +28052,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/reflection/classes/nestedClasses.kt");
|
runTest("compiler/testData/codegen/box/reflection/classes/nestedClasses.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nestedClassesInScript.kt")
|
||||||
|
public void testNestedClassesInScript() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/classes/nestedClassesInScript.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nestedClassesJava.kt")
|
@TestMetadata("nestedClassesJava.kt")
|
||||||
public void testNestedClassesJava() throws Exception {
|
public void testNestedClassesJava() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/reflection/classes/nestedClassesJava.kt");
|
runTest("compiler/testData/codegen/box/reflection/classes/nestedClassesJava.kt");
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ internal class KClassImpl<T : Any>(
|
|||||||
val nestedClasses: Collection<KClass<*>> by ReflectProperties.lazySoft {
|
val nestedClasses: Collection<KClass<*>> by ReflectProperties.lazySoft {
|
||||||
descriptor.unsubstitutedInnerClassesScope.getContributedDescriptors().filterNot(DescriptorUtils::isEnumEntry)
|
descriptor.unsubstitutedInnerClassesScope.getContributedDescriptors().filterNot(DescriptorUtils::isEnumEntry)
|
||||||
.mapNotNull { nestedClass ->
|
.mapNotNull { nestedClass ->
|
||||||
val jClass = (nestedClass as ClassDescriptor).toJavaClass()
|
val jClass = (nestedClass as? ClassDescriptor)?.toJavaClass()
|
||||||
jClass?.let { KClassImpl(it) }
|
jClass?.let { KClassImpl(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ dependencies {
|
|||||||
|
|
||||||
testImplementation(intellijCoreDep()) { includeJars("intellij-core") }
|
testImplementation(intellijCoreDep()) { includeJars("intellij-core") }
|
||||||
testRuntimeOnly(intellijDep()) { includeJars("jps-model", "jna") }
|
testRuntimeOnly(intellijDep()) { includeJars("jps-model", "jna") }
|
||||||
|
|
||||||
|
testImplementation(project(":kotlin-reflect"))
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
+29
@@ -6,7 +6,9 @@
|
|||||||
package org.jetbrains.kotlin.scripting.compiler.test
|
package org.jetbrains.kotlin.scripting.compiler.test
|
||||||
|
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.jetbrains.kotlin.scripting.compiler.plugin.impl.ScriptJvmCompilerIsolated
|
import org.jetbrains.kotlin.scripting.compiler.plugin.impl.ScriptJvmCompilerIsolated
|
||||||
|
import kotlin.reflect.KClass
|
||||||
import kotlin.script.experimental.api.*
|
import kotlin.script.experimental.api.*
|
||||||
import kotlin.script.experimental.host.toScriptSource
|
import kotlin.script.experimental.host.toScriptSource
|
||||||
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
||||||
@@ -27,6 +29,23 @@ class ScriptCompilerTest : TestCase() {
|
|||||||
assertTrue(res.reports.none { it.message.contains("nonsense") })
|
assertTrue(res.reports.none { it.message.contains("nonsense") })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testTypeAliases() {
|
||||||
|
val res = compileToClass(
|
||||||
|
"""
|
||||||
|
class Clazz
|
||||||
|
typealias Tazz = List<Clazz>
|
||||||
|
val x: Tazz = listOf()
|
||||||
|
x
|
||||||
|
""".trimIndent().toScriptSource()
|
||||||
|
)
|
||||||
|
|
||||||
|
val kclass = res.valueOrThrow()
|
||||||
|
val nestedClasses = kclass.nestedClasses.toList()
|
||||||
|
|
||||||
|
assertEquals(1, nestedClasses.size)
|
||||||
|
assertEquals("Clazz", nestedClasses[0].simpleName)
|
||||||
|
}
|
||||||
|
|
||||||
fun compile(
|
fun compile(
|
||||||
script: SourceCode,
|
script: SourceCode,
|
||||||
cfgBody: ScriptCompilationConfiguration.Builder.() -> Unit
|
cfgBody: ScriptCompilationConfiguration.Builder.() -> Unit
|
||||||
@@ -35,4 +54,14 @@ class ScriptCompilerTest : TestCase() {
|
|||||||
val compiler = ScriptJvmCompilerIsolated(defaultJvmScriptingHostConfiguration)
|
val compiler = ScriptJvmCompilerIsolated(defaultJvmScriptingHostConfiguration)
|
||||||
return compiler.compile(script, compilationConfiguration)
|
return compiler.compile(script, compilationConfiguration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun compileToClass(
|
||||||
|
script: SourceCode,
|
||||||
|
evaluationConfiguration: ScriptEvaluationConfiguration = ScriptEvaluationConfiguration(),
|
||||||
|
cfgBody: ScriptCompilationConfiguration.Builder.() -> Unit = {},
|
||||||
|
): ResultWithDiagnostics<KClass<*>> {
|
||||||
|
val result = compile(script, cfgBody)
|
||||||
|
if (result is ResultWithDiagnostics.Failure) return result
|
||||||
|
return runBlocking { result.valueOrThrow().getClass(evaluationConfiguration) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user