- InnerClasses & EnclosingMethod attributes for local classes
in multifile part members - invocation of multifile part/facade members (TODO: deserialized descriptor case) - inlining of multifile part/facade members (TODO: inline against binaries case)
This commit is contained in:
@@ -27,9 +27,6 @@ import java.util.*
|
|||||||
public class CodegenFileClassesProvider() : JvmFileClassesProvider {
|
public class CodegenFileClassesProvider() : JvmFileClassesProvider {
|
||||||
private val fileParts = hashMapOf<JetFile, JvmFileClassInfo>()
|
private val fileParts = hashMapOf<JetFile, JvmFileClassInfo>()
|
||||||
|
|
||||||
override fun getFileClassFqName(file: JetFile): FqName =
|
override public fun getFileClassInfo(file: JetFile): JvmFileClassInfo =
|
||||||
getFileClassInfo(file).fileClassFqName
|
|
||||||
|
|
||||||
public fun getFileClassInfo(file: JetFile): JvmFileClassInfo =
|
|
||||||
fileParts.getOrPut(file) { JvmFileClassUtil.getFileClassInfoNoResolve(file) }
|
fileParts.getOrPut(file) { JvmFileClassUtil.getFileClassInfoNoResolve(file) }
|
||||||
}
|
}
|
||||||
@@ -148,9 +148,8 @@ public class FunctionCodegen {
|
|||||||
int flags = getMethodAsmFlags(functionDescriptor, contextKind);
|
int flags = getMethodAsmFlags(functionDescriptor, contextKind);
|
||||||
boolean isNative = NativeDeclarationsPackage.hasNativeAnnotation(functionDescriptor);
|
boolean isNative = NativeDeclarationsPackage.hasNativeAnnotation(functionDescriptor);
|
||||||
|
|
||||||
//TODO: generate native method only in new mini facades (now it equals to package part)
|
if (isNative && owner instanceof DelegatingFacadeContext) {
|
||||||
if (isNative && owner instanceof PackageFacadeContext) {
|
// Native methods are only defined in facades and do not need package part implementations
|
||||||
// Native methods are only defined in package facades and do not need package part implementations
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MethodVisitor mv = v.newMethod(origin,
|
MethodVisitor mv = v.newMethod(origin,
|
||||||
@@ -160,7 +159,7 @@ public class FunctionCodegen {
|
|||||||
jvmSignature.getGenericsSignature(),
|
jvmSignature.getGenericsSignature(),
|
||||||
getThrownExceptions(functionDescriptor, typeMapper));
|
getThrownExceptions(functionDescriptor, typeMapper));
|
||||||
|
|
||||||
String implClassName = CodegenContextUtil.getImplClassNameByOwnerIfRequired(owner);
|
String implClassName = CodegenContextUtil.getImplementationClassShortName(owner);
|
||||||
if (implClassName != null) {
|
if (implClassName != null) {
|
||||||
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, functionDescriptor, implClassName);
|
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, functionDescriptor, implClassName);
|
||||||
}
|
}
|
||||||
@@ -329,8 +328,8 @@ public class FunctionCodegen {
|
|||||||
JetTypeMapper typeMapper = parentCodegen.typeMapper;
|
JetTypeMapper typeMapper = parentCodegen.typeMapper;
|
||||||
|
|
||||||
Label methodEnd;
|
Label methodEnd;
|
||||||
if (context.getParentContext() instanceof PackageFacadeContext) {
|
if (context.getParentContext() instanceof DelegatingFacadeContext) {
|
||||||
generatePackageDelegateMethodBody(mv, signature.getAsmMethod(), (PackageFacadeContext) context.getParentContext());
|
generateFacadeDelegateMethodBody(mv, signature.getAsmMethod(), (DelegatingFacadeContext) context.getParentContext());
|
||||||
methodEnd = new Label();
|
methodEnd = new Label();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -402,10 +401,10 @@ public class FunctionCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void generatePackageDelegateMethodBody(
|
private static void generateFacadeDelegateMethodBody(
|
||||||
@NotNull MethodVisitor mv,
|
@NotNull MethodVisitor mv,
|
||||||
@NotNull Method asmMethod,
|
@NotNull Method asmMethod,
|
||||||
@NotNull PackageFacadeContext context
|
@NotNull DelegatingFacadeContext context
|
||||||
) {
|
) {
|
||||||
generateDelegateToMethodBody(true, mv, asmMethod, context.getDelegateToClassType().getInternalName());
|
generateDelegateToMethodBody(true, mv, asmMethod, context.getDelegateToClassType().getInternalName());
|
||||||
}
|
}
|
||||||
@@ -596,9 +595,9 @@ public class FunctionCodegen {
|
|||||||
AnnotationCodegen.forMethod(mv, typeMapper).genAnnotations(functionDescriptor, defaultMethod.getReturnType());
|
AnnotationCodegen.forMethod(mv, typeMapper).genAnnotations(functionDescriptor, defaultMethod.getReturnType());
|
||||||
|
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||||
if (this.owner instanceof PackageFacadeContext) {
|
if (this.owner instanceof DelegatingFacadeContext) {
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
generatePackageDelegateMethodBody(mv, defaultMethod, (PackageFacadeContext) this.owner);
|
generateFacadeDelegateMethodBody(mv, defaultMethod, (DelegatingFacadeContext) this.owner);
|
||||||
endVisit(mv, "default method delegation", getSourceFromDescriptor(functionDescriptor));
|
endVisit(mv, "default method delegation", getSourceFromDescriptor(functionDescriptor));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -289,9 +289,16 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
|
|||||||
if (outermost instanceof ClassContext) {
|
if (outermost instanceof ClassContext) {
|
||||||
return typeMapper.mapType(((ClassContext) outermost).getContextDescriptor());
|
return typeMapper.mapType(((ClassContext) outermost).getContextDescriptor());
|
||||||
}
|
}
|
||||||
else if (outermost instanceof PackageContext && !(outermost instanceof PackageFacadeContext)) {
|
else if (outermost instanceof DelegatingFacadeContext || outermost instanceof DelegatingToPartContext) {
|
||||||
return fileClassesProvider.getFileClassType(element.getContainingJetFile());
|
Type implementationOwnerType = CodegenContextUtil.getImplementationOwnerClassType(outermost);
|
||||||
}/*disabled cause of KT-7775
|
if (implementationOwnerType != null) {
|
||||||
|
return implementationOwnerType;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return fileClassesProvider.getFileClassType(element.getContainingJetFile());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*disabled cause of KT-7775
|
||||||
else if (outermost instanceof ScriptContext) {
|
else if (outermost instanceof ScriptContext) {
|
||||||
return asmTypeForScriptDescriptor(bindingContext, ((ScriptContext) outermost).getScriptDescriptor());
|
return asmTypeForScriptDescriptor(bindingContext, ((ScriptContext) outermost).getScriptDescriptor());
|
||||||
}*/
|
}*/
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class PropertyCodegen {
|
|||||||
assert kind == OwnerKind.PACKAGE || kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.TRAIT_IMPL
|
assert kind == OwnerKind.PACKAGE || kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.TRAIT_IMPL
|
||||||
: "Generating property with a wrong kind (" + kind + "): " + descriptor;
|
: "Generating property with a wrong kind (" + kind + "): " + descriptor;
|
||||||
|
|
||||||
Type implClassType = CodegenContextUtil.getImplClassTypeByOwnerIfRequired(context);
|
Type implClassType = CodegenContextUtil.getImplementationOwnerClassType(context);
|
||||||
if (implClassType != null) {
|
if (implClassType != null) {
|
||||||
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, descriptor, shortNameByAsmType(implClassType));
|
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, descriptor, shortNameByAsmType(implClassType));
|
||||||
}
|
}
|
||||||
@@ -493,6 +493,9 @@ public class PropertyCodegen {
|
|||||||
else if (ownerContext instanceof PackageContext) {
|
else if (ownerContext instanceof PackageContext) {
|
||||||
owner = ((PackageContext) ownerContext).getPackagePartType();
|
owner = ((PackageContext) ownerContext).getPackagePartType();
|
||||||
}
|
}
|
||||||
|
else if (ownerContext instanceof MultifileClassContextBase) {
|
||||||
|
owner = ((MultifileClassContextBase) ownerContext).getFilePartType();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException("Unknown context: " + ownerContext);
|
throw new UnsupportedOperationException("Unknown context: " + ownerContext);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
|||||||
@NotNull Type multifileClassType,
|
@NotNull Type multifileClassType,
|
||||||
@NotNull Type filePartType
|
@NotNull Type filePartType
|
||||||
) {
|
) {
|
||||||
return new MultifileClassContext(descriptor, this, multifileClassType, filePartType);
|
return new MultifileClassFacadeContext(descriptor, this, multifileClassType, filePartType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -21,21 +21,19 @@ import org.jetbrains.org.objectweb.asm.Type
|
|||||||
|
|
||||||
|
|
||||||
public object CodegenContextUtil {
|
public object CodegenContextUtil {
|
||||||
public @JvmStatic fun getImplClassTypeByOwnerIfRequired(owner: CodegenContext<*>): Type? =
|
public @JvmStatic fun getImplementationOwnerClassType(owner: CodegenContext<*>): Type? =
|
||||||
when (owner) {
|
when (owner) {
|
||||||
is PackageFacadeContext ->
|
is DelegatingFacadeContext ->
|
||||||
owner.delegateToClassType
|
owner.delegateToClassType
|
||||||
is PackageContext ->
|
is DelegatingToPartContext ->
|
||||||
owner.packagePartType
|
owner.implementationOwnerClassType
|
||||||
is MultifileClassOrPartContext ->
|
|
||||||
owner.filePartType
|
|
||||||
else ->
|
else ->
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
public @JvmStatic fun getImplClassNameByOwnerIfRequired(owner: CodegenContext<*>): String? =
|
public @JvmStatic fun getImplementationClassShortName(owner: CodegenContext<*>): String? =
|
||||||
getImplClassTypeByOwnerIfRequired(owner)?.let{ AsmUtil.shortNameByAsmType(it) }
|
getImplementationOwnerClassType(owner)?.let { AsmUtil.shortNameByAsmType(it) }
|
||||||
|
|
||||||
public @JvmStatic fun isImplClassOwner(owner: CodegenContext<*>): Boolean =
|
public @JvmStatic fun isImplClassOwner(owner: CodegenContext<*>): Boolean =
|
||||||
!(owner is PackageFacadeContext || owner is MultifileClassContext)
|
owner !is DelegatingFacadeContext
|
||||||
}
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* 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.codegen.context;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.org.objectweb.asm.Type;
|
||||||
|
|
||||||
|
public interface DelegatingFacadeContext {
|
||||||
|
@Nullable
|
||||||
|
public Type getDelegateToClassType();
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* 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.codegen.context;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.org.objectweb.asm.Type;
|
||||||
|
|
||||||
|
public interface DelegatingToPartContext {
|
||||||
|
@Nullable
|
||||||
|
Type getImplementationOwnerClassType();
|
||||||
|
}
|
||||||
+2
-2
@@ -20,11 +20,11 @@ import org.jetbrains.kotlin.codegen.OwnerKind;
|
|||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
||||||
import org.jetbrains.org.objectweb.asm.Type;
|
import org.jetbrains.org.objectweb.asm.Type;
|
||||||
|
|
||||||
public class MultifileClassOrPartContext extends FieldOwnerContext<PackageFragmentDescriptor> {
|
public class MultifileClassContextBase extends FieldOwnerContext<PackageFragmentDescriptor> {
|
||||||
private final Type multifileClassType;
|
private final Type multifileClassType;
|
||||||
private final Type filePartType;
|
private final Type filePartType;
|
||||||
|
|
||||||
public MultifileClassOrPartContext(
|
public MultifileClassContextBase(
|
||||||
PackageFragmentDescriptor descriptor,
|
PackageFragmentDescriptor descriptor,
|
||||||
CodegenContext parent,
|
CodegenContext parent,
|
||||||
Type multifileClassType,
|
Type multifileClassType,
|
||||||
+8
-4
@@ -16,13 +16,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.codegen.context;
|
package org.jetbrains.kotlin.codegen.context;
|
||||||
|
|
||||||
import org.jetbrains.kotlin.codegen.OwnerKind;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
||||||
import org.jetbrains.org.objectweb.asm.Type;
|
import org.jetbrains.org.objectweb.asm.Type;
|
||||||
|
|
||||||
public class MultifileClassContext extends MultifileClassOrPartContext {
|
public class MultifileClassFacadeContext extends MultifileClassContextBase implements DelegatingFacadeContext {
|
||||||
public MultifileClassContext(
|
public MultifileClassFacadeContext(
|
||||||
PackageFragmentDescriptor descriptor,
|
PackageFragmentDescriptor descriptor,
|
||||||
CodegenContext parent,
|
CodegenContext parent,
|
||||||
Type multifileClassType,
|
Type multifileClassType,
|
||||||
@@ -31,4 +30,9 @@ public class MultifileClassContext extends MultifileClassOrPartContext {
|
|||||||
super(descriptor, parent, multifileClassType, filePartType);
|
super(descriptor, parent, multifileClassType, filePartType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Type getDelegateToClassType() {
|
||||||
|
return getFilePartType();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+7
-3
@@ -16,12 +16,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.codegen.context;
|
package org.jetbrains.kotlin.codegen.context;
|
||||||
|
|
||||||
import org.jetbrains.kotlin.codegen.OwnerKind;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
||||||
import org.jetbrains.org.objectweb.asm.Type;
|
import org.jetbrains.org.objectweb.asm.Type;
|
||||||
|
|
||||||
public class MultifileClassPartContext extends MultifileClassOrPartContext {
|
public class MultifileClassPartContext extends MultifileClassContextBase implements DelegatingToPartContext {
|
||||||
public MultifileClassPartContext(
|
public MultifileClassPartContext(
|
||||||
PackageFragmentDescriptor descriptor,
|
PackageFragmentDescriptor descriptor,
|
||||||
CodegenContext parent,
|
CodegenContext parent,
|
||||||
@@ -31,4 +30,9 @@ public class MultifileClassPartContext extends MultifileClassOrPartContext {
|
|||||||
super(descriptor, parent, multifileClassType, filePartType);
|
super(descriptor, parent, multifileClassType, filePartType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Type getImplementationOwnerClassType() {
|
||||||
|
return getFilePartType();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,14 +17,19 @@
|
|||||||
package org.jetbrains.kotlin.codegen.context;
|
package org.jetbrains.kotlin.codegen.context;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.codegen.OwnerKind;
|
import org.jetbrains.kotlin.codegen.OwnerKind;
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
||||||
import org.jetbrains.org.objectweb.asm.Type;
|
import org.jetbrains.org.objectweb.asm.Type;
|
||||||
|
|
||||||
public class PackageContext extends FieldOwnerContext<PackageFragmentDescriptor> {
|
public class PackageContext extends FieldOwnerContext<PackageFragmentDescriptor> implements DelegatingToPartContext {
|
||||||
private final Type packagePartType;
|
private final Type packagePartType;
|
||||||
|
|
||||||
public PackageContext(@NotNull PackageFragmentDescriptor contextDescriptor, @NotNull CodegenContext parent, Type packagePartType) {
|
public PackageContext(
|
||||||
|
@NotNull PackageFragmentDescriptor contextDescriptor,
|
||||||
|
@NotNull CodegenContext parent,
|
||||||
|
@Nullable Type packagePartType
|
||||||
|
) {
|
||||||
super(contextDescriptor, OwnerKind.PACKAGE, parent, null, null, null);
|
super(contextDescriptor, OwnerKind.PACKAGE, parent, null, null, null);
|
||||||
this.packagePartType = packagePartType;
|
this.packagePartType = packagePartType;
|
||||||
}
|
}
|
||||||
@@ -34,7 +39,14 @@ public class PackageContext extends FieldOwnerContext<PackageFragmentDescriptor>
|
|||||||
return "Package: " + getContextDescriptor().getName();
|
return "Package: " + getContextDescriptor().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Type getPackagePartType() {
|
public Type getPackagePartType() {
|
||||||
return packagePartType;
|
return packagePartType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Type getImplementationOwnerClassType() {
|
||||||
|
return packagePartType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,20 +17,22 @@
|
|||||||
package org.jetbrains.kotlin.codegen.context;
|
package org.jetbrains.kotlin.codegen.context;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
||||||
import org.jetbrains.org.objectweb.asm.Type;
|
import org.jetbrains.org.objectweb.asm.Type;
|
||||||
|
|
||||||
public class PackageFacadeContext extends PackageContext {
|
public class PackageFacadeContext extends PackageContext implements DelegatingFacadeContext {
|
||||||
|
|
||||||
public PackageFacadeContext(
|
public PackageFacadeContext(
|
||||||
@NotNull PackageFragmentDescriptor contextDescriptor,
|
@NotNull PackageFragmentDescriptor contextDescriptor,
|
||||||
@NotNull CodegenContext parent,
|
@NotNull CodegenContext parent,
|
||||||
@NotNull Type delegateTo
|
@NotNull Type packagePartType
|
||||||
) {
|
) {
|
||||||
super(contextDescriptor, parent, delegateTo);
|
super(contextDescriptor, parent, packagePartType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@Override
|
||||||
|
@Nullable
|
||||||
public Type getDelegateToClassType() {
|
public Type getDelegateToClassType() {
|
||||||
return getPackagePartType();
|
return getPackagePartType();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,7 @@ import org.jetbrains.annotations.TestOnly;
|
|||||||
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
||||||
import org.jetbrains.kotlin.codegen.MemberCodegen;
|
import org.jetbrains.kotlin.codegen.MemberCodegen;
|
||||||
import org.jetbrains.kotlin.codegen.binding.CodegenBinding;
|
import org.jetbrains.kotlin.codegen.binding.CodegenBinding;
|
||||||
import org.jetbrains.kotlin.codegen.context.CodegenContext;
|
import org.jetbrains.kotlin.codegen.context.*;
|
||||||
import org.jetbrains.kotlin.codegen.context.MethodContext;
|
|
||||||
import org.jetbrains.kotlin.codegen.context.PackageContext;
|
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||||
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
||||||
import org.jetbrains.kotlin.descriptors.*;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
@@ -221,22 +219,22 @@ public class InlineCodegenUtil {
|
|||||||
if (currentDescriptor instanceof PackageFragmentDescriptor) {
|
if (currentDescriptor instanceof PackageFragmentDescriptor) {
|
||||||
PsiFile file = getContainingFile(codegenContext);
|
PsiFile file = getContainingFile(codegenContext);
|
||||||
|
|
||||||
Type packagePartType;
|
Type implementationOwnerType;
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
//in case package fragment clinit
|
implementationOwnerType = CodegenContextUtil.getImplementationOwnerClassType(codegenContext);
|
||||||
assert codegenContext instanceof PackageContext : "Expected package context but " + codegenContext;
|
|
||||||
packagePartType = ((PackageContext) codegenContext).getPackagePartType();
|
|
||||||
} else {
|
} else {
|
||||||
packagePartType = fileClassesManager.getFileClassType((JetFile) file);
|
implementationOwnerType = fileClassesManager.getFileClassType((JetFile) file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packagePartType == null) {
|
if (implementationOwnerType == null) {
|
||||||
DeclarationDescriptor contextDescriptor = codegenContext.getContextDescriptor();
|
DeclarationDescriptor contextDescriptor = codegenContext.getContextDescriptor();
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
throw new RuntimeException("Couldn't find declaration for " + contextDescriptor.getContainingDeclaration().getName() + "." + contextDescriptor.getName() );
|
throw new RuntimeException("Couldn't find declaration for " +
|
||||||
|
contextDescriptor.getContainingDeclaration().getName() + "." + contextDescriptor.getName() +
|
||||||
|
"; context: " + codegenContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
return packagePartType.getInternalName();
|
return implementationOwnerType.getInternalName();
|
||||||
}
|
}
|
||||||
else if (currentDescriptor instanceof ClassifierDescriptor) {
|
else if (currentDescriptor instanceof ClassifierDescriptor) {
|
||||||
Type type = typeMapper.mapType((ClassifierDescriptor) currentDescriptor);
|
Type type = typeMapper.mapType((ClassifierDescriptor) currentDescriptor);
|
||||||
|
|||||||
@@ -144,9 +144,7 @@ public class JetTypeMapper {
|
|||||||
if (container instanceof PackageFragmentDescriptor) {
|
if (container instanceof PackageFragmentDescriptor) {
|
||||||
boolean effectiveInsideModule = isInsideModule && !NativeDeclarationsPackage.hasNativeAnnotation(descriptor);
|
boolean effectiveInsideModule = isInsideModule && !NativeDeclarationsPackage.hasNativeAnnotation(descriptor);
|
||||||
return Type.getObjectType(internalNameForPackage(
|
return Type.getObjectType(internalNameForPackage(
|
||||||
(PackageFragmentDescriptor) container,
|
(CallableMemberDescriptor) descriptor
|
||||||
(CallableMemberDescriptor) descriptor,
|
|
||||||
effectiveInsideModule
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
else if (container instanceof ClassDescriptor) {
|
else if (container instanceof ClassDescriptor) {
|
||||||
@@ -161,25 +159,25 @@ public class JetTypeMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String internalNameForPackage(
|
private String internalNameForPackage(@NotNull CallableMemberDescriptor descriptor) {
|
||||||
@NotNull PackageFragmentDescriptor packageFragment,
|
JetFile file = DescriptorToSourceUtils.getContainingFile(descriptor);
|
||||||
@NotNull CallableMemberDescriptor descriptor,
|
if (file != null) {
|
||||||
boolean insideModule
|
Visibility visibility = descriptor.getVisibility();
|
||||||
) {
|
if (Visibilities.isPrivate(visibility)) {
|
||||||
///if (insideModule) {
|
|
||||||
JetFile file = DescriptorToSourceUtils.getContainingFile(descriptor);
|
|
||||||
if (file != null) {
|
|
||||||
return fileClassesProvider.getFileClassInternalName(file);
|
return fileClassesProvider.getFileClassInternalName(file);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
CallableMemberDescriptor directMember = getDirectMember(descriptor);
|
return fileClassesProvider.getFacadeClassInternalName(file);
|
||||||
|
|
||||||
if (directMember instanceof DeserializedCallableMemberDescriptor) {
|
|
||||||
FqName packagePartFqName = PackagePartClassUtils.getPackagePartFqName((DeserializedCallableMemberDescriptor) directMember);
|
|
||||||
return internalNameByFqNameWithoutInnerClasses(packagePartFqName);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//}
|
CallableMemberDescriptor directMember = getDirectMember(descriptor);
|
||||||
|
|
||||||
|
if (directMember instanceof DeserializedCallableMemberDescriptor) {
|
||||||
|
// TODO private vs public
|
||||||
|
FqName packagePartFqName = PackagePartClassUtils.getPackagePartFqName((DeserializedCallableMemberDescriptor) directMember);
|
||||||
|
return internalNameByFqNameWithoutInnerClasses(packagePartFqName);
|
||||||
|
}
|
||||||
|
|
||||||
throw new RuntimeException("Unreachable state");
|
throw new RuntimeException("Unreachable state");
|
||||||
//return PackageClassUtils.getPackageClassInternalName(packageFragment.getFqName());
|
//return PackageClassUtils.getPackageClassInternalName(packageFragment.getFqName());
|
||||||
|
|||||||
+20
-3
@@ -22,12 +22,29 @@ import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
|||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
|
|
||||||
public interface JvmFileClassesProvider {
|
public interface JvmFileClassesProvider {
|
||||||
public fun getFileClassFqName(file: JetFile): FqName
|
public fun getFileClassInfo(file: JetFile): JvmFileClassInfo
|
||||||
|
|
||||||
|
public fun getFileClassFqName(file: JetFile): FqName =
|
||||||
|
getFileClassInfo(file).fileClassFqName
|
||||||
|
|
||||||
public fun getFileClassInternalName(file: JetFile): String =
|
public fun getFileClassInternalName(file: JetFile): String =
|
||||||
JvmClassName.byFqNameWithoutInnerClasses(getFileClassFqName(file)).internalName
|
getFileClassFqName(file).getInternalName()
|
||||||
|
|
||||||
public fun getFileClassType(file: JetFile): Type =
|
public fun getFileClassType(file: JetFile): Type =
|
||||||
Type.getObjectType(getFileClassInternalName(file))
|
getFileClassFqName(file).getClassType()
|
||||||
|
|
||||||
|
public fun getFacadeClassFqName(file: JetFile): FqName =
|
||||||
|
getFileClassInfo(file).facadeClassFqName
|
||||||
|
|
||||||
|
public fun getFacadeClassInternalName(file: JetFile): String =
|
||||||
|
getFacadeClassFqName(file).getInternalName()
|
||||||
|
|
||||||
|
public fun getFacadeClassType(file: JetFile): Type =
|
||||||
|
getFacadeClassFqName(file).getClassType()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun FqName.getInternalName(): String =
|
||||||
|
JvmClassName.byFqNameWithoutInnerClasses(this).internalName
|
||||||
|
|
||||||
|
private fun FqName.getClassType(): Type =
|
||||||
|
Type.getObjectType(getInternalName())
|
||||||
|
|||||||
+2
-2
@@ -21,6 +21,6 @@ import org.jetbrains.kotlin.psi.JetFile
|
|||||||
|
|
||||||
|
|
||||||
public object NoResolveFileClassesProvider : JvmFileClassesProvider {
|
public object NoResolveFileClassesProvider : JvmFileClassesProvider {
|
||||||
override fun getFileClassFqName(file: JetFile): FqName =
|
override fun getFileClassInfo(file: JetFile): JvmFileClassInfo =
|
||||||
JvmFileClassUtil.getFileClassInfo(file, JvmFileClassUtil.parseJvmNameOnFileNoResolve(file)).fileClassFqName
|
JvmFileClassUtil.getFileClassInfo(file, JvmFileClassUtil.parseJvmNameOnFileNoResolve(file))
|
||||||
}
|
}
|
||||||
+1
-1
@@ -2,4 +2,4 @@
|
|||||||
@file:JvmMultifileClass
|
@file:JvmMultifileClass
|
||||||
public fun bar(): String = barx()
|
public fun bar(): String = barx()
|
||||||
|
|
||||||
private fun foox(): String = "O"
|
public fun foox(): String = "O"
|
||||||
+1
-1
@@ -2,4 +2,4 @@
|
|||||||
@file:JvmMultifileClass
|
@file:JvmMultifileClass
|
||||||
public fun foo(): String = foox()
|
public fun foo(): String = foox()
|
||||||
|
|
||||||
private fun barx(): String = "K"
|
public fun barx(): String = "K"
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
@file:JvmName("TestPackage")
|
||||||
|
@file:JvmMultifileClass
|
||||||
|
package test
|
||||||
|
|
||||||
|
fun foo(): String = bar()
|
||||||
|
fun bar(): String {
|
||||||
|
class Local(val x: String)
|
||||||
|
return Local("OK").x
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String = foo()
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
@file:[JvmName("Util") JvmMultifileClass]
|
||||||
|
package test
|
||||||
|
|
||||||
|
internal fun internalInOtherFile() {}
|
||||||
|
public fun publicInOtherFile() {}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
@file:[JvmName("Util") JvmMultifileClass]
|
||||||
|
package test
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
privateInThisFile()
|
||||||
|
internalInThisFile()
|
||||||
|
publicInThisFile()
|
||||||
|
internalInOtherFile()
|
||||||
|
publicInOtherFile()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun privateInThisFile() {}
|
||||||
|
|
||||||
|
internal fun internalInThisFile() {}
|
||||||
|
|
||||||
|
public fun publicInThisFile() {}
|
||||||
|
|
||||||
|
// @test/1ThisFileKt.class:
|
||||||
|
// 1 INVOKESTATIC test/1ThisFileKt.privateInThisFile
|
||||||
|
// 1 INVOKESTATIC test/1ThisFileKt.internalInThisFile
|
||||||
|
// 1 INVOKESTATIC test/1ThisFileKt.publicInThisFile
|
||||||
|
// 1 INVOKESTATIC test/1OtherFileKt.internalInOtherFile
|
||||||
|
// 1 INVOKESTATIC test/1OtherFileKt.publicInOtherFile
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.codegen;
|
||||||
|
|
||||||
|
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/bytecodeTextMultifile")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public class BytecodeTextMultifileTestGenerated extends AbstractBytecodeTextTest {
|
||||||
|
public void testAllFilesPresentInBytecodeTextMultifile() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeTextMultifile"), Pattern.compile("^([^\\.]+)$"), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("partMembersCall")
|
||||||
|
public void testPartMembersCall() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeTextMultifile/partMembersCall/");
|
||||||
|
doTestMultiFile(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-3
@@ -141,9 +141,9 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
|
|||||||
doTestWithJava(fileName);
|
doTestWithJava(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("multifileClassWithCrossPrivate")
|
@TestMetadata("multifileClassWithCrossCall")
|
||||||
public void testMultifileClassWithCrossPrivate() throws Exception {
|
public void testMultifileClassWithCrossCall() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/fileClasses/multifileClassWithCrossPrivate/");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/fileClasses/multifileClassWithCrossCall/");
|
||||||
doTestWithJava(fileName);
|
doTestWithJava(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
@@ -2245,6 +2245,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
|||||||
doTestWithStdlib(fileName);
|
doTestWithStdlib(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("multifileClassWithLocalClass.kt")
|
||||||
|
public void testMultifileClassWithLocalClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/platformNames/multifileClassWithLocalClass.kt");
|
||||||
|
doTestWithStdlib(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("multifileClassWithLocalGeneric.kt")
|
@TestMetadata("multifileClassWithLocalGeneric.kt")
|
||||||
public void testMultifileClassWithLocalGeneric() throws Exception {
|
public void testMultifileClassWithLocalGeneric() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/platformNames/multifileClassWithLocalGeneric.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/platformNames/multifileClassWithLocalGeneric.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user