- call multifile class members (compiling against binaries)
- inline multifile class members
This commit is contained in:
@@ -88,25 +88,29 @@ public class ClassFileFactory implements OutputFileCollection {
|
||||
for (PackageCodegen codegen : packageCodegens) {
|
||||
codegen.done();
|
||||
}
|
||||
for (MultifileClassCodegen codegen : multifileClass2codegen.values()) {
|
||||
Collection<MultifileClassCodegen> multifileClassCodegens = multifileClass2codegen.values();
|
||||
for (MultifileClassCodegen codegen : multifileClassCodegens) {
|
||||
codegen.done();
|
||||
}
|
||||
// TODO module mappings for multifile classes
|
||||
writeModuleMappings(packageCodegens);
|
||||
writeModuleMappings(packageCodegens, multifileClassCodegens);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeModuleMappings(Collection<PackageCodegen> values) {
|
||||
private void writeModuleMappings(
|
||||
@NotNull Collection<PackageCodegen> packageCodegens,
|
||||
@NotNull Collection<MultifileClassCodegen> multifileClassCodegens
|
||||
) {
|
||||
final JvmPackageTable.PackageTable.Builder builder = JvmPackageTable.PackageTable.newBuilder();
|
||||
String outputFilePath = getMappingFileName(state.getModuleName());
|
||||
|
||||
List<PackageParts> parts = ContainerUtil.newArrayList();
|
||||
List<PackageParts> parts = collectGeneratedPackageParts(packageCodegens, multifileClassCodegens);
|
||||
|
||||
Set<File> sourceFiles = new HashSet<File>();
|
||||
|
||||
for (PackageCodegen codegen : values) {
|
||||
parts.add(codegen.getPackageParts());
|
||||
|
||||
// TODO extract common logic
|
||||
// TODO extract common logic
|
||||
for (PackageCodegen codegen : packageCodegens) {
|
||||
sourceFiles.addAll(toIoFilesIgnoringNonPhysical(PackagePartClassUtils.getFilesWithCallables(codegen.getFiles())));
|
||||
}
|
||||
for (MultifileClassCodegen codegen : multifileClassCodegens) {
|
||||
sourceFiles.addAll(toIoFilesIgnoringNonPhysical(PackagePartClassUtils.getFilesWithCallables(codegen.getFiles())));
|
||||
}
|
||||
|
||||
@@ -152,6 +156,34 @@ public class ClassFileFactory implements OutputFileCollection {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<PackageParts> collectGeneratedPackageParts(
|
||||
@NotNull Collection<PackageCodegen> packageCodegens,
|
||||
@NotNull Collection<MultifileClassCodegen> multifileClassCodegens
|
||||
) {
|
||||
Map<String, PackageParts> mergedPartsByPackageName = new LinkedHashMap<String, PackageParts>();
|
||||
|
||||
for (PackageCodegen packageCodegen : packageCodegens) {
|
||||
PackageParts generatedParts = packageCodegen.getPackageParts();
|
||||
PackageParts premergedParts = new PackageParts(generatedParts.getPackageFqName());
|
||||
mergedPartsByPackageName.put(generatedParts.getPackageFqName(), premergedParts);
|
||||
premergedParts.getParts().addAll(generatedParts.getParts());
|
||||
}
|
||||
|
||||
for (MultifileClassCodegen multifileClassCodegen : multifileClassCodegens) {
|
||||
PackageParts multifileClassParts = multifileClassCodegen.getPackageParts();
|
||||
PackageParts premergedParts = mergedPartsByPackageName.get(multifileClassParts.getPackageFqName());
|
||||
if (premergedParts == null) {
|
||||
premergedParts = new PackageParts(multifileClassParts.getPackageFqName());
|
||||
mergedPartsByPackageName.put(multifileClassParts.getPackageFqName(), premergedParts);
|
||||
}
|
||||
premergedParts.getParts().addAll(multifileClassParts.getParts());
|
||||
}
|
||||
|
||||
List<PackageParts> result = new ArrayList<PackageParts>();
|
||||
result.addAll(mergedPartsByPackageName.values());
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<OutputFile> asList() {
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageParts
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.IncrementalPackageFragmentProvider
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus
|
||||
@@ -41,7 +42,7 @@ import java.util.*
|
||||
|
||||
public class MultifileClassCodegen(
|
||||
private val state: GenerationState,
|
||||
private val files: Collection<JetFile>,
|
||||
public val files: Collection<JetFile>,
|
||||
private val facadeFqName: FqName
|
||||
) {
|
||||
private val facadeClassType = AsmUtil.asmTypeByFqNameWithoutInnerClasses(facadeFqName)
|
||||
@@ -50,6 +51,8 @@ public class MultifileClassCodegen(
|
||||
|
||||
private val compiledPackageFragment = getCompiledPackageFragment(facadeFqName.parent(), state)
|
||||
|
||||
public val packageParts = PackageParts(facadeFqName.parent().asString())
|
||||
|
||||
// TODO incremental compilation support
|
||||
// TODO previouslyCompiledCallables
|
||||
// We can do this (probably without 'compiledPackageFragment') after modifications to part codegen.
|
||||
@@ -159,8 +162,8 @@ public class MultifileClassCodegen(
|
||||
|
||||
partFqNames.add(partClassInfo.fileClassFqName)
|
||||
|
||||
// val name = partType.internalName
|
||||
// packageParts.parts.add(name.substring(name.lastIndexOf('/') + 1))
|
||||
val name = partType.internalName
|
||||
packageParts.parts.add(name.substring(name.lastIndexOf('/') + 1))
|
||||
|
||||
val builder = state.factory.newVisitor(MultifileClassPart(file, packageFragment, facadeFqName), partType, file)
|
||||
|
||||
|
||||
@@ -110,9 +110,9 @@ public class PropertyCodegen {
|
||||
assert kind == OwnerKind.PACKAGE || kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.TRAIT_IMPL
|
||||
: "Generating property with a wrong kind (" + kind + "): " + descriptor;
|
||||
|
||||
Type implClassType = CodegenContextUtil.getImplementationOwnerClassType(context);
|
||||
if (implClassType != null) {
|
||||
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, descriptor, shortNameByAsmType(implClassType));
|
||||
String implClassName = CodegenContextUtil.getImplementationClassShortName(context);
|
||||
if (implClassName != null) {
|
||||
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, descriptor, implClassName);
|
||||
}
|
||||
|
||||
if (CodegenContextUtil.isImplClassOwner(context)) {
|
||||
|
||||
@@ -23,12 +23,9 @@ import org.jetbrains.org.objectweb.asm.Type
|
||||
public object CodegenContextUtil {
|
||||
public @JvmStatic fun getImplementationOwnerClassType(owner: CodegenContext<*>): Type? =
|
||||
when (owner) {
|
||||
is DelegatingFacadeContext ->
|
||||
owner.delegateToClassType
|
||||
is DelegatingToPartContext ->
|
||||
owner.implementationOwnerClassType
|
||||
else ->
|
||||
null
|
||||
is DelegatingFacadeContext -> owner.delegateToClassType
|
||||
is DelegatingToPartContext -> owner.implementationOwnerClassType
|
||||
else -> null
|
||||
}
|
||||
|
||||
public @JvmStatic fun getImplementationClassShortName(owner: CodegenContext<*>): String? =
|
||||
|
||||
+1
-1
@@ -21,5 +21,5 @@ import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
public interface DelegatingFacadeContext {
|
||||
@Nullable
|
||||
public Type getDelegateToClassType();
|
||||
Type getDelegateToClassType();
|
||||
}
|
||||
|
||||
@@ -30,16 +30,13 @@ import org.jetbrains.kotlin.codegen.binding.PsiCodegenPredictor;
|
||||
import org.jetbrains.kotlin.codegen.context.CodegenContext;
|
||||
import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil;
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassesProvider;
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
|
||||
import org.jetbrains.kotlin.load.kotlin.nativeDeclarations.NativeDeclarationsPackage;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe;
|
||||
import org.jetbrains.kotlin.name.SpecialNames;
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageScope;
|
||||
import org.jetbrains.kotlin.name.*;
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
@@ -59,6 +56,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializedType;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
@@ -142,10 +140,7 @@ public class JetTypeMapper {
|
||||
|
||||
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
||||
if (container instanceof PackageFragmentDescriptor) {
|
||||
boolean effectiveInsideModule = isInsideModule && !NativeDeclarationsPackage.hasNativeAnnotation(descriptor);
|
||||
return Type.getObjectType(internalNameForPackage(
|
||||
(CallableMemberDescriptor) descriptor
|
||||
));
|
||||
return Type.getObjectType(internalNameForPackage((CallableMemberDescriptor) descriptor));
|
||||
}
|
||||
else if (container instanceof ClassDescriptor) {
|
||||
return mapClass((ClassDescriptor) container);
|
||||
@@ -174,9 +169,19 @@ public class JetTypeMapper {
|
||||
CallableMemberDescriptor directMember = getDirectMember(descriptor);
|
||||
|
||||
if (directMember instanceof DeserializedCallableMemberDescriptor) {
|
||||
// TODO private vs public
|
||||
FqName packagePartFqName = PackagePartClassUtils.getPackagePartFqName((DeserializedCallableMemberDescriptor) directMember);
|
||||
return internalNameByFqNameWithoutInnerClasses(packagePartFqName);
|
||||
Name implClassName = JvmFileClassUtil.getImplClassName((DeserializedCallableMemberDescriptor) directMember);
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
if (containingDeclaration instanceof PackageFragmentDescriptor) {
|
||||
PackageFragmentDescriptor packageFragmentDescriptor = (PackageFragmentDescriptor) containingDeclaration;
|
||||
JetScope scope = packageFragmentDescriptor.getMemberScope();
|
||||
if (scope instanceof LazyJavaPackageScope) {
|
||||
String facadeShortName = ((LazyJavaPackageScope) scope).getFacadeSimpleNameForPartSimpleName(implClassName.asString());
|
||||
if (facadeShortName != null) {
|
||||
FqName facadeFqName = packageFragmentDescriptor.getFqName().child(Name.identifier(facadeShortName));
|
||||
return internalNameByFqNameWithoutInnerClasses(facadeFqName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException("Unreachable state");
|
||||
|
||||
@@ -16,12 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.fileClasses
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.constants.StringValue
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
|
||||
|
||||
|
||||
public object JvmFileClassUtil {
|
||||
public val JVM_NAME: FqName = FqName("kotlin.jvm.JvmName")
|
||||
@@ -49,6 +51,15 @@ public object JvmFileClassUtil {
|
||||
public @JvmStatic fun getFacadeFqName(file: JetFile, jvmFileClassAnnotations: ParsedJmvFileClassAnnotations): FqName =
|
||||
file.packageFqName.child(Name.identifier(jvmFileClassAnnotations.name))
|
||||
|
||||
public @JvmStatic fun getPartFqNameForDeserializedCallable(callable: DeserializedCallableMemberDescriptor): FqName {
|
||||
val implClassName = getImplClassName(callable)
|
||||
val packageFqName = (callable.containingDeclaration as PackageFragmentDescriptor).fqName
|
||||
return packageFqName.child(implClassName)
|
||||
}
|
||||
|
||||
public @JvmStatic fun getImplClassName(callable: DeserializedCallableMemberDescriptor): Name =
|
||||
callable.nameResolver.getName(callable.proto.getExtension(JvmProtoBuf.implClassName))
|
||||
|
||||
public @JvmStatic fun getHiddenPartFqName(file: JetFile, jvmFileClassAnnotations: ParsedJmvFileClassAnnotations): FqName =
|
||||
file.packageFqName.child(Name.identifier(manglePartName(jvmFileClassAnnotations.name, file.name)))
|
||||
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import a.foo
|
||||
|
||||
fun box(): String = foo { "OK" }
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
@file:[JvmName("MultifileClass") JvmMultifileClass]
|
||||
package a
|
||||
|
||||
inline fun foo(body: () -> String): String = body()
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
import b.bar
|
||||
|
||||
fun box(): String = bar()
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package b
|
||||
|
||||
import a.foo
|
||||
|
||||
fun bar(): String = foo()
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
@file:[JvmName("MultifileClass") JvmMultifileClass]
|
||||
package a
|
||||
|
||||
fun foo(): String = "OK"
|
||||
@@ -0,0 +1,3 @@
|
||||
import a.foo
|
||||
|
||||
fun box(): String = foo()
|
||||
@@ -0,0 +1,4 @@
|
||||
@file:[JvmName("MultifileClass") JvmMultifileClass]
|
||||
package a
|
||||
|
||||
fun foo(): String = "OK"
|
||||
@@ -89,11 +89,22 @@ public object InlineTestUtil {
|
||||
val notInlined = ArrayList<NotInlinedCall>()
|
||||
|
||||
files.forEach { file ->
|
||||
|
||||
val cr = ClassReader(file.asByteArray())
|
||||
cr.accept(object : ClassVisitorWithName() {
|
||||
private var skipMethodsOfThisClass = false
|
||||
|
||||
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? {
|
||||
if (desc.endsWith("KotlinPackage;") || desc.endsWith("KotlinMultifileClass;")) {
|
||||
skipMethodsOfThisClass = true
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun visitMethod(access: Int, name: String, desc: String, signature: String, exceptions: Array<String>): MethodVisitor? {
|
||||
if (skipMethodsOfThisClass) {
|
||||
return null
|
||||
}
|
||||
|
||||
val classFqName = JvmClassName.byInternalName(className).getFqNameForClassNameWithoutDollars()
|
||||
if (PackageClassUtils.isPackageClassFqName(classFqName)) {
|
||||
return null
|
||||
|
||||
+15
@@ -428,6 +428,21 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxInline/multifileClasses")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class MultifileClasses extends AbstractBlackBoxInlineCodegenTest {
|
||||
public void testAllFilesPresentInMultifileClasses() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/multifileClasses"), Pattern.compile("^(.+)\\.1.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("inlineFromOtherPackage.1.kt")
|
||||
public void testInlineFromOtherPackage() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/multifileClasses/inlineFromOtherPackage.1.kt");
|
||||
doTestMultiFileWithInlineCheck(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxInline/noInline")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+6
@@ -47,6 +47,12 @@ public class BlackBoxMultiFileCodegenTestGenerated extends AbstractBlackBoxCodeg
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxMultiFile"), Pattern.compile("^([^\\.]+)$"), false);
|
||||
}
|
||||
|
||||
@TestMetadata("callMultifileClassMemberFromOtherPackage")
|
||||
public void testCallMultifileClassMemberFromOtherPackage() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxMultiFile/callMultifileClassMemberFromOtherPackage/");
|
||||
doTestMultiFile(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("internalVisibility")
|
||||
public void testInternalVisibility() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxMultiFile/internalVisibility/");
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.jvm.compiler
|
||||
|
||||
import org.jetbrains.kotlin.codegen.ClassFileFactory
|
||||
import org.jetbrains.kotlin.codegen.InlineTestUtil
|
||||
import org.jetbrains.kotlin.codegen.filterClassFiles
|
||||
import java.io.File
|
||||
import java.util.Collections
|
||||
|
||||
public abstract class AbstractCompileKotlinAgainstMultifileKotlinTest : AbstractCompileKotlinAgainstKotlinTest(), AbstractSMAPBaseTest {
|
||||
|
||||
public fun doBoxTest(firstFileName: String) {
|
||||
val inputFiles = listOf(firstFileName, firstFileName.substringBeforeLast("1.kt") + "2.kt")
|
||||
|
||||
val (factory1, factory2) = doBoxTest(inputFiles)
|
||||
}
|
||||
|
||||
private fun doBoxTest(files: List<String>): Pair<ClassFileFactory, ClassFileFactory> {
|
||||
Collections.sort(files)
|
||||
|
||||
var factory1: ClassFileFactory? = null
|
||||
var factory2: ClassFileFactory? = null
|
||||
try {
|
||||
factory1 = compileA(File(files[1]))
|
||||
factory2 = compileB(File(files[0]))
|
||||
invokeBox()
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
var result = ""
|
||||
if (factory1 != null) {
|
||||
result += "FIRST: \n\n" + factory1.createText()
|
||||
}
|
||||
if (factory2 != null) {
|
||||
result += "\n\nSECOND: \n\n" + factory2.createText()
|
||||
}
|
||||
System.out.println(result)
|
||||
throw e
|
||||
}
|
||||
|
||||
return Pair(factory1!!, factory2!!)
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -428,6 +428,21 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxInline/multifileClasses")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class MultifileClasses extends AbstractCompileKotlinAgainstInlineKotlinTest {
|
||||
public void testAllFilesPresentInMultifileClasses() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/multifileClasses"), Pattern.compile("^(.+)\\.1.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("inlineFromOtherPackage.1.kt")
|
||||
public void testInlineFromOtherPackage() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/multifileClasses/inlineFromOtherPackage.1.kt");
|
||||
doBoxTestWithInlineCheck(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxInline/noInline")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.jvm.compiler;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||
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("compiler/testData/codegen/boxMultifileClasses")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class CompileKotlinAgainstMultifileKotlinTestGenerated extends AbstractCompileKotlinAgainstMultifileKotlinTest {
|
||||
public void testAllFilesPresentInBoxMultifileClasses() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxMultifileClasses"), Pattern.compile("^(.+)\\.1.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxMultifileClasses/calls")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Calls extends AbstractCompileKotlinAgainstMultifileKotlinTest {
|
||||
public void testAllFilesPresentInCalls() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxMultifileClasses/calls"), Pattern.compile("^(.+)\\.1.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("callFromOtherPackage.1.kt")
|
||||
public void testCallFromOtherPackage() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxMultifileClasses/calls/callFromOtherPackage.1.kt");
|
||||
doBoxTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaPackage
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
|
||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
@@ -58,6 +59,22 @@ public class LazyJavaPackageScope(
|
||||
}.filterNotNull()
|
||||
}
|
||||
|
||||
private val partToFacade = c.storageManager.createLazyValue {
|
||||
val result = hashMapOf<String, String>()
|
||||
for (kotlinClass in kotlinBinaryClasses()) {
|
||||
val header = kotlinClass.classHeader
|
||||
if (header.kind == KotlinClassHeader.Kind.MULTIFILE_CLASS_PART) {
|
||||
val partName = kotlinClass.classId.shortClassName.asString()
|
||||
val facadeName = header.multifileClassName ?: ""
|
||||
result[partName] = facadeName
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
public fun getFacadeSimpleNameForPartSimpleName(partName: String): String? =
|
||||
partToFacade()[partName]
|
||||
|
||||
private val deserializedPackageScope = c.storageManager.createLazyValue {
|
||||
if (kotlinBinaryClasses().isEmpty())
|
||||
JetScope.Empty
|
||||
|
||||
+3
-3
@@ -69,7 +69,7 @@ public final class DeserializedDescriptorResolver {
|
||||
|
||||
@Nullable
|
||||
public JetScope createKotlinPackagePartScope(@NotNull PackageFragmentDescriptor descriptor, @NotNull KotlinJvmBinaryClass kotlinClass) {
|
||||
String[] data = readData(kotlinClass, KotlinClassHeader.Kind.FILE_FACADE);
|
||||
String[] data = readData(kotlinClass, null);
|
||||
if (data != null) {
|
||||
//all classes are included in java scope
|
||||
PackageData packageData = JvmProtoBufUtil.readPackageDataFrom(data);
|
||||
@@ -102,12 +102,12 @@ public final class DeserializedDescriptorResolver {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String[] readData(@NotNull KotlinJvmBinaryClass kotlinClass, @NotNull KotlinClassHeader.Kind expectedKind) {
|
||||
public String[] readData(@NotNull KotlinJvmBinaryClass kotlinClass, @Nullable KotlinClassHeader.Kind expectedKind) {
|
||||
KotlinClassHeader header = kotlinClass.getClassHeader();
|
||||
if (!header.getIsCompatibleAbiVersion()) {
|
||||
errorReporter.reportIncompatibleAbiVersion(kotlinClass.getClassId(), kotlinClass.getLocation(), header.getVersion());
|
||||
}
|
||||
else if (header.getKind() == expectedKind) {
|
||||
else if (expectedKind == null || header.getKind() == expectedKind) {
|
||||
return header.getAnnotationData();
|
||||
}
|
||||
|
||||
|
||||
@@ -183,6 +183,10 @@ fun main(args: Array<String>) {
|
||||
model("codegen/boxInline", extension = "1.kt", testMethod = "doBoxTestWithInlineCheck")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractCompileKotlinAgainstMultifileKotlinTest>(), "CompileKotlinAgainstMultifileKotlinTestGenerated") {
|
||||
model("codegen/boxMultifileClasses", extension = "1.kt", testMethod = "doBoxTest")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractBlackBoxCodegenTest>(), "BlackBoxMultiFileCodegenTestGenerated") {
|
||||
model("codegen/boxMultiFile", extension = null, recursive = false, testMethod = "doTestMultiFile")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user