Support JvmPackageName annotation in binary format
The main changes are in jvm_package_table.proto and ModuleMapping.kt. With JvmPackageName, package parts can now have a JVM package name that differs from their Kotlin name. So, in addition to the old package parts which were stored as short names + short name of multifile facade (we can't change this because of compatibility with old compilers), we now store separately those package parts, which have a different JVM package name. The format is optimized to avoid storing any package name more than once as a string. Another notable change is in KotlinCliJavaFileManagerImpl, where we now load .kotlin_module files when determining whether or not a package exists. Before this change, no PsiPackage (and thus, no JavaPackage and eventually, no LazyJavaPackageFragment) was created unless there was at least one file in the corresponding directory. Now we also create packages if they are "mapped" to other JVM packages, i.e. if all package parts in them have been annotated with JvmPackageName. Most of the other changes are refactorings to allow internal names of package parts/multifile classes where previously there were only short names.
This commit is contained in:
@@ -204,6 +204,7 @@ class KotlinCliJavaFileManagerTest : KotlinTestWithEnvironment() {
|
||||
val root = StandardFileSystems.local().findFileByPath(javaFilesDir.path)!!
|
||||
coreJavaFileManager.initialize(
|
||||
JvmDependenciesIndexImpl(listOf(JavaRoot(root, JavaRoot.RootType.SOURCE))),
|
||||
emptyList(),
|
||||
SingleJavaFileRootsIndex(emptyList()),
|
||||
useFastClassFilesReading = true
|
||||
)
|
||||
|
||||
@@ -10409,11 +10409,23 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("rootPackage.kt")
|
||||
public void testRootPackage() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/rootPackage.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/simple.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withJvmName.kt")
|
||||
public void testWithJvmName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/withJvmName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/jvmStatic")
|
||||
|
||||
+18
@@ -138,6 +138,24 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jvmPackageName.kt")
|
||||
public void testJvmPackageName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/jvmPackageName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jvmPackageNameInRootPackage.kt")
|
||||
public void testJvmPackageNameInRootPackage() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/jvmPackageNameInRootPackage.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jvmPackageNameWithJvmName.kt")
|
||||
public void testJvmPackageNameWithJvmName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/jvmPackageNameWithJvmName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jvmStaticInObject.kt")
|
||||
public void testJvmStaticInObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/jvmStaticInObject.kt");
|
||||
|
||||
@@ -19,14 +19,21 @@ package org.jetbrains.kotlin.codegen
|
||||
import org.jetbrains.kotlin.cli.AbstractCliTest
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
|
||||
import org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
||||
import java.io.File
|
||||
|
||||
class JvmPackageTableTest : KtUsefulTestCase() {
|
||||
private fun doTest(relativeDirectory: String) {
|
||||
private fun doTest(
|
||||
relativeDirectory: String,
|
||||
compileWith: LanguageVersion = LanguageVersion.LATEST_STABLE,
|
||||
loadWith: LanguageVersion = LanguageVersion.LATEST_STABLE
|
||||
) {
|
||||
val directory = KotlinTestUtils.getTestDataPathBase() + relativeDirectory
|
||||
val tmpdir = KotlinTestUtils.tmpDir(this::class.simpleName)
|
||||
|
||||
@@ -34,14 +41,17 @@ class JvmPackageTableTest : KtUsefulTestCase() {
|
||||
val (output, exitCode) = AbstractCliTest.executeCompilerGrabOutput(K2JVMCompiler(), listOf(
|
||||
directory,
|
||||
"-d", tmpdir.path,
|
||||
"-module-name", moduleName
|
||||
"-module-name", moduleName,
|
||||
"-language-version", compileWith.versionString
|
||||
))
|
||||
System.err.println(output) // normally output is empty
|
||||
assertEquals("Compilation should complete successfully", ExitCode.OK, exitCode)
|
||||
|
||||
val mapping = ModuleMapping.create(
|
||||
File(tmpdir, "META-INF/$moduleName.${ModuleMapping.MAPPING_FILE_EXT}").readBytes(), "test",
|
||||
DeserializationConfiguration.Default
|
||||
CompilerDeserializationConfiguration(
|
||||
LanguageVersionSettingsImpl(loadWith, ApiVersion.createByLanguageVersion(loadWith))
|
||||
)
|
||||
)
|
||||
val result = buildString {
|
||||
for ((fqName, packageParts) in mapping.packageFqName2Parts) {
|
||||
@@ -66,4 +76,14 @@ class JvmPackageTableTest : KtUsefulTestCase() {
|
||||
fun testSimple() {
|
||||
doTest("/jvmPackageTable/simple")
|
||||
}
|
||||
|
||||
fun testJvmPackageName() {
|
||||
doTest("/jvmPackageTable/jvmPackageName",
|
||||
compileWith = LanguageVersion.KOTLIN_1_2, loadWith = LanguageVersion.KOTLIN_1_2)
|
||||
}
|
||||
|
||||
fun testJvmPackageNameManyParts() {
|
||||
doTest("/jvmPackageTable/jvmPackageNameManyParts",
|
||||
compileWith = LanguageVersion.KOTLIN_1_2, loadWith = LanguageVersion.KOTLIN_1_2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10409,11 +10409,23 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("rootPackage.kt")
|
||||
public void testRootPackage() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/rootPackage.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/simple.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withJvmName.kt")
|
||||
public void testWithJvmName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/withJvmName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/jvmStatic")
|
||||
|
||||
Reference in New Issue
Block a user