Extract JvmMethodGenericSignature from JvmMethodSignature
This commit is contained in:
@@ -52,8 +52,8 @@ class CollectionStubMethodGenerator(
|
||||
val superCollectionClasses = findRelevantSuperCollectionClasses()
|
||||
if (superCollectionClasses.isEmpty()) return
|
||||
|
||||
val methodStubsToGenerate = LinkedHashSet<JvmMethodSignature>()
|
||||
val syntheticStubsToGenerate = LinkedHashSet<JvmMethodSignature>()
|
||||
val methodStubsToGenerate = LinkedHashSet<JvmMethodGenericSignature>()
|
||||
val syntheticStubsToGenerate = LinkedHashSet<JvmMethodGenericSignature>()
|
||||
|
||||
for ((readOnlyClass, mutableClass) in superCollectionClasses) {
|
||||
// To determine which method stubs we need to generate, we create a synthetic class (named 'child' here) which inherits from
|
||||
@@ -118,10 +118,10 @@ class CollectionStubMethodGenerator(
|
||||
else
|
||||
Pair(overriddenMethodSignature.asmMethod, overriddenMethodSignature.valueParameters)
|
||||
|
||||
specialSignature = JvmMethodSignature(
|
||||
specialSignature = JvmMethodGenericSignature(
|
||||
asmMethod,
|
||||
specialGenericSignature,
|
||||
valueParameters
|
||||
valueParameters,
|
||||
specialGenericSignature
|
||||
)
|
||||
|
||||
methodStubsToGenerate.add(specialSignature)
|
||||
@@ -240,9 +240,9 @@ class CollectionStubMethodGenerator(
|
||||
return KotlinTypeImpl.create(Annotations.EMPTY, classDescriptor, false, typeArguments)
|
||||
}
|
||||
|
||||
private fun FunctionDescriptor.signature(): JvmMethodSignature = typeMapper.mapSignatureWithGeneric(this, OwnerKind.IMPLEMENTATION)
|
||||
private fun FunctionDescriptor.signature(): JvmMethodGenericSignature = typeMapper.mapSignatureWithGeneric(this, OwnerKind.IMPLEMENTATION)
|
||||
|
||||
private fun generateMethodStub(signature: JvmMethodSignature, synthetic: Boolean) {
|
||||
private fun generateMethodStub(signature: JvmMethodGenericSignature, synthetic: Boolean) {
|
||||
// TODO: investigate if it makes sense to generate abstract stubs in traits
|
||||
var access = ACC_PUBLIC
|
||||
if (descriptor.kind == ClassKind.INTERFACE) access = access or ACC_ABSTRACT
|
||||
|
||||
@@ -54,6 +54,7 @@ import org.jetbrains.kotlin.resolve.constants.KClassValue;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
|
||||
@@ -152,7 +153,7 @@ public class FunctionCodegen {
|
||||
return;
|
||||
}
|
||||
|
||||
JvmMethodSignature jvmSignature = typeMapper.mapSignatureWithGeneric(functionDescriptor, contextKind);
|
||||
JvmMethodGenericSignature jvmSignature = typeMapper.mapSignatureWithGeneric(functionDescriptor, contextKind);
|
||||
Method asmMethod = jvmSignature.getAsmMethod();
|
||||
|
||||
int flags = getMethodAsmFlags(functionDescriptor, contextKind);
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
@@ -212,7 +213,7 @@ public class PropertyCodegen {
|
||||
}
|
||||
|
||||
public void generateConstructorPropertyAsMethodForAnnotationClass(KtParameter p, PropertyDescriptor descriptor) {
|
||||
JvmMethodSignature signature = typeMapper.mapAnnotationParameterSignature(descriptor);
|
||||
JvmMethodGenericSignature signature = typeMapper.mapAnnotationParameterSignature(descriptor);
|
||||
String name = p.getName();
|
||||
if (name == null) return;
|
||||
MethodVisitor mv = v.newMethod(
|
||||
|
||||
@@ -237,7 +237,7 @@ public class InlineCodegen extends CallGenerator {
|
||||
getMethodAsmFlags(functionDescriptor, context.getContextKind()) | (callDefault ? Opcodes.ACC_STATIC : 0),
|
||||
asmMethod.getName(),
|
||||
asmMethod.getDescriptor(),
|
||||
jvmSignature.getGenericsSignature(),
|
||||
null,
|
||||
null);
|
||||
|
||||
//for maxLocals calculation
|
||||
@@ -351,7 +351,7 @@ public class InlineCodegen extends CallGenerator {
|
||||
|
||||
JvmMethodSignature jvmMethodSignature = typeMapper.mapSignatureSkipGeneric(descriptor);
|
||||
Method asmMethod = jvmMethodSignature.getAsmMethod();
|
||||
MethodNode methodNode = new MethodNode(InlineCodegenUtil.API, getMethodAsmFlags(descriptor, context.getContextKind()), asmMethod.getName(), asmMethod.getDescriptor(), jvmMethodSignature.getGenericsSignature(), null);
|
||||
MethodNode methodNode = new MethodNode(InlineCodegenUtil.API, getMethodAsmFlags(descriptor, context.getContextKind()), asmMethod.getName(), asmMethod.getDescriptor(), null, null);
|
||||
|
||||
MethodVisitor adapter = InlineCodegenUtil.wrapWithMaxLocalCalc(methodNode);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.codegen.signature;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
|
||||
@@ -171,13 +172,13 @@ public class JvmSignatureWriter {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature makeJvmMethodSignature(@NotNull String name) {
|
||||
public JvmMethodGenericSignature makeJvmMethodSignature(@NotNull String name) {
|
||||
List<Type> types = new ArrayList<Type>(kotlinParameterTypes.size());
|
||||
for (JvmMethodParameterSignature parameter : kotlinParameterTypes) {
|
||||
types.add(parameter.getAsmType());
|
||||
}
|
||||
Method asmMethod = new Method(name, jvmReturnType, types.toArray(new Type[types.size()]));
|
||||
return new JvmMethodSignature(asmMethod, makeJavaGenericSignature(), kotlinParameterTypes);
|
||||
return new JvmMethodGenericSignature(asmMethod, kotlinParameterTypes, makeJavaGenericSignature());
|
||||
}
|
||||
|
||||
public int getCurrentSignatureSize() {
|
||||
|
||||
@@ -66,6 +66,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes;
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName;
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
|
||||
@@ -398,7 +399,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapAnnotationParameterSignature(@NotNull PropertyDescriptor descriptor) {
|
||||
public JvmMethodGenericSignature mapAnnotationParameterSignature(@NotNull PropertyDescriptor descriptor) {
|
||||
JvmSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
|
||||
sw.writeReturnType();
|
||||
mapType(descriptor.getType(), sw, TypeMappingMode.VALUE_FOR_ANNOTATION);
|
||||
@@ -990,7 +991,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JvmMethodSignature mapSignature(@NotNull FunctionDescriptor f, boolean skipGenericSignature) {
|
||||
private JvmMethodGenericSignature mapSignature(@NotNull FunctionDescriptor f, boolean skipGenericSignature) {
|
||||
return mapSignature(f, OwnerKind.IMPLEMENTATION, skipGenericSignature);
|
||||
}
|
||||
|
||||
@@ -1005,12 +1006,12 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapSignatureWithGeneric(@NotNull FunctionDescriptor f, @NotNull OwnerKind kind) {
|
||||
public JvmMethodGenericSignature mapSignatureWithGeneric(@NotNull FunctionDescriptor f, @NotNull OwnerKind kind) {
|
||||
return mapSignature(f, kind, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JvmMethodSignature mapSignature(@NotNull FunctionDescriptor f, @NotNull OwnerKind kind, boolean skipGenericSignature) {
|
||||
private JvmMethodGenericSignature mapSignature(@NotNull FunctionDescriptor f, @NotNull OwnerKind kind, boolean skipGenericSignature) {
|
||||
if (f.getInitialSignatureDescriptor() != null && f != f.getInitialSignatureDescriptor()) {
|
||||
// Overrides of special builtin in Kotlin classes always have special signature
|
||||
if (SpecialBuiltinMembers.getOverriddenBuiltinReflectingJvmDescriptor(f) == null ||
|
||||
@@ -1027,7 +1028,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapSignature(
|
||||
public JvmMethodGenericSignature mapSignature(
|
||||
@NotNull FunctionDescriptor f,
|
||||
@NotNull OwnerKind kind,
|
||||
@NotNull List<ValueParameterDescriptor> valueParameters,
|
||||
@@ -1078,7 +1079,7 @@ public class JetTypeMapper {
|
||||
sw.writeReturnTypeEnd();
|
||||
}
|
||||
|
||||
JvmMethodSignature signature = sw.makeJvmMethodSignature(mapFunctionName(f));
|
||||
JvmMethodGenericSignature signature = sw.makeJvmMethodSignature(mapFunctionName(f));
|
||||
|
||||
if (kind != OwnerKind.DEFAULT_IMPLS) {
|
||||
SpecialSignatureInfo specialSignatureInfo = BuiltinMethodsWithSpecialGenericSignature.getSpecialSignatureInfo(f);
|
||||
@@ -1086,7 +1087,7 @@ public class JetTypeMapper {
|
||||
if (specialSignatureInfo != null) {
|
||||
String newGenericSignature = CodegenUtilKt.replaceValueParametersIn(
|
||||
specialSignatureInfo, signature.getGenericsSignature());
|
||||
return new JvmMethodSignature(signature.getAsmMethod(), newGenericSignature, signature.getValueParameters());
|
||||
return new JvmMethodGenericSignature(signature.getAsmMethod(), signature.getValueParameters(), newGenericSignature);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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.resolve.jvm.jvmSignature;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JvmMethodGenericSignature extends JvmMethodSignature {
|
||||
private final String genericsSignature;
|
||||
|
||||
public JvmMethodGenericSignature(
|
||||
@NotNull Method asmMethod,
|
||||
@NotNull List<JvmMethodParameterSignature> valueParameters,
|
||||
@Nullable String genericsSignature
|
||||
) {
|
||||
super(asmMethod, valueParameters);
|
||||
this.genericsSignature = genericsSignature;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getGenericsSignature() {
|
||||
return genericsSignature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof JvmMethodGenericSignature)) return false;
|
||||
|
||||
JvmMethodGenericSignature that = (JvmMethodGenericSignature) o;
|
||||
|
||||
return super.equals(that) &&
|
||||
(genericsSignature == null ? that.genericsSignature == null : genericsSignature.equals(that.genericsSignature));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (genericsSignature != null ? genericsSignature.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
-9
@@ -25,16 +25,13 @@ import java.util.List;
|
||||
|
||||
public class JvmMethodSignature {
|
||||
private final Method asmMethod;
|
||||
private final String genericsSignature;
|
||||
private final List<JvmMethodParameterSignature> valueParameters;
|
||||
|
||||
public JvmMethodSignature(
|
||||
@NotNull Method asmMethod,
|
||||
@Nullable String genericsSignature,
|
||||
@NotNull List<JvmMethodParameterSignature> valueParameters
|
||||
) {
|
||||
this.asmMethod = asmMethod;
|
||||
this.genericsSignature = genericsSignature;
|
||||
this.valueParameters = valueParameters;
|
||||
}
|
||||
|
||||
@@ -43,10 +40,6 @@ public class JvmMethodSignature {
|
||||
return asmMethod;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getGenericsSignature() {
|
||||
return genericsSignature;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JvmMethodParameterSignature> getValueParameters() {
|
||||
@@ -66,14 +59,12 @@ public class JvmMethodSignature {
|
||||
JvmMethodSignature that = (JvmMethodSignature) o;
|
||||
|
||||
return asmMethod.equals(that.asmMethod) &&
|
||||
(genericsSignature == null ? that.genericsSignature == null : genericsSignature.equals(that.genericsSignature)) &&
|
||||
valueParameters.equals(that.valueParameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = asmMethod.hashCode();
|
||||
result = 31 * result + (genericsSignature != null ? genericsSignature.hashCode() : 0);
|
||||
result = 31 * result + valueParameters.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user