Drop KotlinDelegatedMethod, simplify related code in codegen
This commit is contained in:
@@ -40,7 +40,6 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget;
|
|||||||
import org.jetbrains.kotlin.jvm.RuntimeAssertionInfo;
|
import org.jetbrains.kotlin.jvm.RuntimeAssertionInfo;
|
||||||
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature;
|
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature;
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames;
|
|
||||||
import org.jetbrains.kotlin.load.java.SpecialBuiltinMembers;
|
import org.jetbrains.kotlin.load.java.SpecialBuiltinMembers;
|
||||||
import org.jetbrains.kotlin.load.kotlin.nativeDeclarations.NativeKt;
|
import org.jetbrains.kotlin.load.kotlin.nativeDeclarations.NativeKt;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
@@ -162,7 +161,7 @@ public class FunctionCodegen {
|
|||||||
int flags = getMethodAsmFlags(functionDescriptor, contextKind);
|
int flags = getMethodAsmFlags(functionDescriptor, contextKind);
|
||||||
boolean isNative = NativeKt.hasNativeAnnotation(functionDescriptor);
|
boolean isNative = NativeKt.hasNativeAnnotation(functionDescriptor);
|
||||||
|
|
||||||
if (isNative && owner instanceof DelegatingFacadeContext) {
|
if (isNative && owner instanceof MultifileClassFacadeContext) {
|
||||||
// Native methods are only defined in facades and do not need package part implementations
|
// Native methods are only defined in facades and do not need package part implementations
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -234,22 +233,6 @@ public class FunctionCodegen {
|
|||||||
else {
|
else {
|
||||||
annotationCodegen.genAnnotations(functionDescriptor, asmMethod.getReturnType());
|
annotationCodegen.genAnnotations(functionDescriptor, asmMethod.getReturnType());
|
||||||
}
|
}
|
||||||
|
|
||||||
writePackageFacadeMethodAnnotationsIfNeeded(mv);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writePackageFacadeMethodAnnotationsIfNeeded(MethodVisitor mv) {
|
|
||||||
if (owner instanceof PackageFacadeContext) {
|
|
||||||
PackageFacadeContext packageFacadeContext = (PackageFacadeContext) owner;
|
|
||||||
Type delegateToClassType = packageFacadeContext.getPublicFacadeType();
|
|
||||||
if (delegateToClassType != null) {
|
|
||||||
String className = delegateToClassType.getClassName();
|
|
||||||
AnnotationVisitor
|
|
||||||
av = mv.visitAnnotation(AsmUtil.asmDescByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_DELEGATED_METHOD), true);
|
|
||||||
av.visit(JvmAnnotationNames.IMPLEMENTATION_CLASS_NAME_FIELD_NAME, className);
|
|
||||||
av.visitEnd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateParameterAnnotations(
|
private void generateParameterAnnotations(
|
||||||
@@ -358,8 +341,8 @@ public class FunctionCodegen {
|
|||||||
int functionFakeIndex = -1;
|
int functionFakeIndex = -1;
|
||||||
int lambdaFakeIndex = -1;
|
int lambdaFakeIndex = -1;
|
||||||
|
|
||||||
if (context.getParentContext() instanceof DelegatingFacadeContext) {
|
if (context.getParentContext() instanceof MultifileClassFacadeContext) {
|
||||||
generateFacadeDelegateMethodBody(mv, signature.getAsmMethod(), (DelegatingFacadeContext) context.getParentContext());
|
generateFacadeDelegateMethodBody(mv, signature.getAsmMethod(), (MultifileClassFacadeContext) context.getParentContext());
|
||||||
methodEnd = new Label();
|
methodEnd = new Label();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -462,9 +445,9 @@ public class FunctionCodegen {
|
|||||||
private static void generateFacadeDelegateMethodBody(
|
private static void generateFacadeDelegateMethodBody(
|
||||||
@NotNull MethodVisitor mv,
|
@NotNull MethodVisitor mv,
|
||||||
@NotNull Method asmMethod,
|
@NotNull Method asmMethod,
|
||||||
@NotNull DelegatingFacadeContext context
|
@NotNull MultifileClassFacadeContext context
|
||||||
) {
|
) {
|
||||||
generateDelegateToMethodBody(true, mv, asmMethod, context.getDelegateToClassType().getInternalName());
|
generateDelegateToMethodBody(true, mv, asmMethod, context.getFilePartType().getInternalName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void generateDelegateToMethodBody(
|
private static void generateDelegateToMethodBody(
|
||||||
@@ -687,9 +670,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 DelegatingFacadeContext) {
|
if (this.owner instanceof MultifileClassFacadeContext) {
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
generateFacadeDelegateMethodBody(mv, defaultMethod, (DelegatingFacadeContext) this.owner);
|
generateFacadeDelegateMethodBody(mv, defaultMethod, (MultifileClassFacadeContext) this.owner);
|
||||||
endVisit(mv, "default method delegation", getSourceFromDescriptor(functionDescriptor));
|
endVisit(mv, "default method delegation", getSourceFromDescriptor(functionDescriptor));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ public abstract class MemberCodegen<T extends KtElement/* TODO: & JetDeclaration
|
|||||||
if (outermost instanceof ClassContext) {
|
if (outermost instanceof ClassContext) {
|
||||||
return typeMapper.mapType(((ClassContext) outermost).getContextDescriptor());
|
return typeMapper.mapType(((ClassContext) outermost).getContextDescriptor());
|
||||||
}
|
}
|
||||||
else if (outermost instanceof DelegatingFacadeContext || outermost instanceof DelegatingToPartContext) {
|
else if (outermost instanceof MultifileClassFacadeContext || outermost instanceof DelegatingToPartContext) {
|
||||||
Type implementationOwnerType = CodegenContextUtil.getImplementationOwnerClassType(outermost);
|
Type implementationOwnerType = CodegenContextUtil.getImplementationOwnerClassType(outermost);
|
||||||
if (implementationOwnerType != null) {
|
if (implementationOwnerType != null) {
|
||||||
return implementationOwnerType;
|
return implementationOwnerType;
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class PropertyCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void generateInPackageFacade(@NotNull DeserializedPropertyDescriptor deserializedProperty) {
|
public void generateInPackageFacade(@NotNull DeserializedPropertyDescriptor deserializedProperty) {
|
||||||
assert context instanceof DelegatingFacadeContext : "should be called only for generating facade: " + context;
|
assert context instanceof MultifileClassFacadeContext : "should be called only for generating facade: " + context;
|
||||||
gen(null, deserializedProperty, null, null);
|
gen(null, deserializedProperty, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ public object CodegenContextUtil {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
public fun getImplementationOwnerClassType(owner: CodegenContext<*>): Type? =
|
public fun getImplementationOwnerClassType(owner: CodegenContext<*>): Type? =
|
||||||
when (owner) {
|
when (owner) {
|
||||||
is DelegatingFacadeContext -> owner.delegateToClassType
|
is MultifileClassFacadeContext -> owner.filePartType
|
||||||
is DelegatingToPartContext -> owner.implementationOwnerClassType
|
is DelegatingToPartContext -> owner.implementationOwnerClassType
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
public fun isImplClassOwner(owner: CodegenContext<*>): Boolean =
|
public fun isImplClassOwner(owner: CodegenContext<*>): Boolean =
|
||||||
owner !is DelegatingFacadeContext
|
owner !is MultifileClassFacadeContext
|
||||||
}
|
}
|
||||||
|
|||||||
-25
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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
|
|
||||||
Type getDelegateToClassType();
|
|
||||||
}
|
|
||||||
+1
-8
@@ -16,11 +16,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.codegen.context;
|
package org.jetbrains.kotlin.codegen.context;
|
||||||
|
|
||||||
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 MultifileClassFacadeContext extends MultifileClassContextBase implements DelegatingFacadeContext {
|
public class MultifileClassFacadeContext extends MultifileClassContextBase {
|
||||||
public MultifileClassFacadeContext(
|
public MultifileClassFacadeContext(
|
||||||
PackageFragmentDescriptor descriptor,
|
PackageFragmentDescriptor descriptor,
|
||||||
CodegenContext parent,
|
CodegenContext parent,
|
||||||
@@ -29,10 +28,4 @@ public class MultifileClassFacadeContext extends MultifileClassContextBase imple
|
|||||||
) {
|
) {
|
||||||
super(descriptor, parent, multifileClassType, filePartType);
|
super(descriptor, parent, multifileClassType, filePartType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public Type getDelegateToClassType() {
|
|
||||||
return getFilePartType();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import org.jetbrains.org.objectweb.asm.Type;
|
|||||||
|
|
||||||
public class PackageContext extends FieldOwnerContext<PackageFragmentDescriptor> implements DelegatingToPartContext, FacadePartWithSourceFile {
|
public class PackageContext extends FieldOwnerContext<PackageFragmentDescriptor> implements DelegatingToPartContext, FacadePartWithSourceFile {
|
||||||
private final Type packagePartType;
|
private final Type packagePartType;
|
||||||
@Nullable private KtFile sourceFile;
|
private final KtFile sourceFile;
|
||||||
|
|
||||||
public PackageContext(
|
public PackageContext(
|
||||||
@NotNull PackageFragmentDescriptor contextDescriptor,
|
@NotNull PackageFragmentDescriptor contextDescriptor,
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
|
||||||
import org.jetbrains.org.objectweb.asm.Type;
|
|
||||||
|
|
||||||
public class PackageFacadeContext extends PackageContext implements DelegatingFacadeContext {
|
|
||||||
private final Type publicFacadeType;
|
|
||||||
|
|
||||||
public PackageFacadeContext(
|
|
||||||
@NotNull PackageFragmentDescriptor contextDescriptor,
|
|
||||||
@NotNull CodegenContext parent,
|
|
||||||
@NotNull Type packagePartType
|
|
||||||
) {
|
|
||||||
this(contextDescriptor, parent, packagePartType, packagePartType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PackageFacadeContext(
|
|
||||||
@NotNull PackageFragmentDescriptor contextDescriptor,
|
|
||||||
@NotNull CodegenContext parent,
|
|
||||||
@NotNull Type packagePartType,
|
|
||||||
@NotNull Type publicFacadeType
|
|
||||||
) {
|
|
||||||
super(contextDescriptor, parent, packagePartType, null);
|
|
||||||
|
|
||||||
this.publicFacadeType = publicFacadeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public Type getDelegateToClassType() {
|
|
||||||
return getPackagePartType();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Type getPublicFacadeType() {
|
|
||||||
return publicFacadeType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-4
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.load.java;
|
package org.jetbrains.kotlin.load.java;
|
||||||
|
|
||||||
import kotlin.SetsKt;
|
import kotlin.collections.SetsKt;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.name.ClassId;
|
import org.jetbrains.kotlin.name.ClassId;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
@@ -37,9 +37,6 @@ public final class JvmAnnotationNames {
|
|||||||
public static final FqName KOTLIN_INTERFACE_DEFAULT_IMPLS = new FqName("kotlin.jvm.internal.KotlinInterfaceDefaultImpls");
|
public static final FqName KOTLIN_INTERFACE_DEFAULT_IMPLS = new FqName("kotlin.jvm.internal.KotlinInterfaceDefaultImpls");
|
||||||
public static final FqName KOTLIN_LOCAL_CLASS = new FqName("kotlin.jvm.internal.KotlinLocalClass");
|
public static final FqName KOTLIN_LOCAL_CLASS = new FqName("kotlin.jvm.internal.KotlinLocalClass");
|
||||||
|
|
||||||
public static final FqName KOTLIN_DELEGATED_METHOD = new FqName("kotlin.jvm.internal.KotlinDelegatedMethod");
|
|
||||||
public static final String IMPLEMENTATION_CLASS_NAME_FIELD_NAME = "implementationClassName";
|
|
||||||
|
|
||||||
public static final String VERSION_FIELD_NAME = "version";
|
public static final String VERSION_FIELD_NAME = "version";
|
||||||
public static final String FILE_PART_CLASS_NAMES_FIELD_NAME = "filePartClassNames";
|
public static final String FILE_PART_CLASS_NAMES_FIELD_NAME = "filePartClassNames";
|
||||||
public static final String MULTIFILE_CLASS_NAME_FIELD_NAME = "multifileClassName";
|
public static final String MULTIFILE_CLASS_NAME_FIELD_NAME = "multifileClassName";
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 kotlin.jvm.internal;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target(ElementType.METHOD)
|
|
||||||
public @interface KotlinDelegatedMethod {
|
|
||||||
String implementationClassName();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user