Descriptors added to newMethod() signature
This commit is contained in:
@@ -66,6 +66,7 @@ public abstract class AbstractClassBuilder implements ClassBuilder {
|
||||
@NotNull
|
||||
public MethodVisitor newMethod(
|
||||
@Nullable PsiElement origin,
|
||||
@Nullable DeclarationDescriptor descriptor,
|
||||
int access,
|
||||
@NotNull String name,
|
||||
@NotNull String desc,
|
||||
|
||||
@@ -40,6 +40,7 @@ public interface ClassBuilder {
|
||||
@NotNull
|
||||
MethodVisitor newMethod(
|
||||
@Nullable PsiElement origin,
|
||||
@Nullable DeclarationDescriptor descriptor,
|
||||
int access,
|
||||
@NotNull String name,
|
||||
@NotNull String desc,
|
||||
|
||||
@@ -200,7 +200,7 @@ public class ClosureCodegen extends ParentCodegenAware {
|
||||
|
||||
|
||||
private void generateConstInstance(@NotNull ClassBuilder cv) {
|
||||
MethodVisitor mv = cv.newMethod(fun, ACC_STATIC | ACC_SYNTHETIC, "<clinit>", "()V", null, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
MethodVisitor mv = cv.newMethod(fun, funDescriptor, ACC_STATIC | ACC_SYNTHETIC, "<clinit>", "()V", null, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||
|
||||
cv.newField(fun, funDescriptor, ACC_STATIC | ACC_FINAL, JvmAbi.INSTANCE_FIELD, asmType.getDescriptor(), null, null);
|
||||
@@ -220,7 +220,7 @@ public class ClosureCodegen extends ParentCodegenAware {
|
||||
if (bridge.equals(delegate)) return;
|
||||
|
||||
MethodVisitor mv =
|
||||
cv.newMethod(fun, ACC_PUBLIC | ACC_BRIDGE, bridge.getName(), bridge.getDescriptor(), null, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
cv.newMethod(fun, funDescriptor, ACC_PUBLIC | ACC_BRIDGE, bridge.getName(), bridge.getDescriptor(), null, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
|
||||
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||
|
||||
@@ -254,21 +254,10 @@ public class ClosureCodegen extends ParentCodegenAware {
|
||||
private Method generateConstructor(@NotNull ClassBuilder cv, @NotNull Type superClassAsmType) {
|
||||
List<FieldInfo> args = calculateConstructorParameters(typeMapper, closure, asmType);
|
||||
|
||||
return generateConstructor(cv, args, fun, superClassAsmType, state, visibilityFlag);
|
||||
}
|
||||
|
||||
public static Method generateConstructor(
|
||||
@NotNull ClassBuilder cv,
|
||||
@NotNull List<FieldInfo> args,
|
||||
@Nullable PsiElement fun,
|
||||
@NotNull Type superClass,
|
||||
@NotNull GenerationState state,
|
||||
int flags
|
||||
) {
|
||||
Type[] argTypes = fieldListToTypeArray(args);
|
||||
|
||||
Method constructor = new Method("<init>", Type.VOID_TYPE, argTypes);
|
||||
MethodVisitor mv = cv.newMethod(fun, flags, "<init>", constructor.getDescriptor(), null,
|
||||
MethodVisitor mv = cv.newMethod(fun, funDescriptor, visibilityFlag, "<init>", constructor.getDescriptor(), null,
|
||||
ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||
mv.visitCode();
|
||||
@@ -279,8 +268,8 @@ public class ClosureCodegen extends ParentCodegenAware {
|
||||
k = AsmUtil.genAssignInstanceFieldFromParam(fieldInfo, k, iv);
|
||||
}
|
||||
|
||||
iv.load(0, superClass);
|
||||
iv.invokespecial(superClass.getInternalName(), "<init>", "()V");
|
||||
iv.load(0, superClassAsmType);
|
||||
iv.invokespecial(superClassAsmType.getInternalName(), "<init>", "()V");
|
||||
|
||||
iv.visitInsn(RETURN);
|
||||
|
||||
|
||||
@@ -127,6 +127,7 @@ public class FunctionCodegen extends ParentCodegenAware {
|
||||
Method asmMethod = jvmSignature.getAsmMethod();
|
||||
|
||||
MethodVisitor mv = v.newMethod(origin,
|
||||
functionDescriptor,
|
||||
getMethodAsmFlags(functionDescriptor, methodContextKind),
|
||||
asmMethod.getName(),
|
||||
asmMethod.getDescriptor(),
|
||||
@@ -449,7 +450,7 @@ public class FunctionCodegen extends ParentCodegenAware {
|
||||
if (!bridgesToGenerate.isEmpty()) {
|
||||
PsiElement origin = descriptor.getKind() == DECLARATION ? callableDescriptorToDeclaration(bindingContext, descriptor) : null;
|
||||
for (Bridge<Method> bridge : bridgesToGenerate) {
|
||||
generateBridge(origin, bridge.getFrom(), bridge.getTo());
|
||||
generateBridge(origin, descriptor, bridge.getFrom(), bridge.getTo());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -506,7 +507,7 @@ public class FunctionCodegen extends ParentCodegenAware {
|
||||
return;
|
||||
}
|
||||
int flags = getVisibilityAccessFlag(constructorDescriptor);
|
||||
MethodVisitor mv = classBuilder.newMethod(null, flags, "<init>", "()V", null,
|
||||
MethodVisitor mv = classBuilder.newMethod(null, constructorDescriptor, flags, "<init>", "()V", null,
|
||||
getThrownExceptions(constructorDescriptor, state.getTypeMapper()));
|
||||
|
||||
if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES) return;
|
||||
@@ -558,7 +559,7 @@ public class FunctionCodegen extends ParentCodegenAware {
|
||||
|
||||
Method defaultMethod = typeMapper.mapDefaultMethod(functionDescriptor, kind, owner);
|
||||
|
||||
MethodVisitor mv = v.newMethod(null, flags | (isConstructor ? 0 : ACC_STATIC),
|
||||
MethodVisitor mv = v.newMethod(null, functionDescriptor, flags | (isConstructor ? 0 : ACC_STATIC),
|
||||
defaultMethod.getName(),
|
||||
defaultMethod.getDescriptor(), null,
|
||||
getThrownExceptions(functionDescriptor, typeMapper));
|
||||
@@ -720,10 +721,15 @@ public class FunctionCodegen extends ParentCodegenAware {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void generateBridge(@Nullable PsiElement origin, @NotNull Method bridge, @NotNull Method delegateTo) {
|
||||
private void generateBridge(
|
||||
@Nullable PsiElement origin,
|
||||
@NotNull FunctionDescriptor descriptor,
|
||||
@NotNull Method bridge,
|
||||
@NotNull Method delegateTo
|
||||
) {
|
||||
int flags = ACC_PUBLIC | ACC_BRIDGE | ACC_SYNTHETIC; // TODO.
|
||||
|
||||
MethodVisitor mv = v.newMethod(null, flags, delegateTo.getName(), bridge.getDescriptor(), null, null);
|
||||
MethodVisitor mv = v.newMethod(null, descriptor, flags, delegateTo.getName(), bridge.getDescriptor(), null, null);
|
||||
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||
|
||||
mv.visitCode();
|
||||
@@ -766,7 +772,7 @@ public class FunctionCodegen extends ParentCodegenAware {
|
||||
|
||||
int flags = ACC_PUBLIC;
|
||||
|
||||
MethodVisitor mv = v.newMethod(null, flags, delegateMethod.getName(), delegateMethod.getDescriptor(), null,
|
||||
MethodVisitor mv = v.newMethod(null, functionDescriptor, flags, delegateMethod.getName(), delegateMethod.getDescriptor(), null,
|
||||
getThrownExceptions(functionDescriptor, typeMapper));
|
||||
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import kotlin.Function0;
|
||||
import kotlin.Function1;
|
||||
import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.backend.common.DataClassMethodGenerator;
|
||||
@@ -865,7 +867,13 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
private void generateEnumValuesMethod() {
|
||||
Type type = typeMapper.mapType(KotlinBuiltIns.getInstance().getArrayType(descriptor.getDefaultType()));
|
||||
|
||||
MethodVisitor mv = v.newMethod(myClass, ACC_PUBLIC | ACC_STATIC, "values", "()" + type.getDescriptor(), null, null);
|
||||
FunctionDescriptor valuesFunction = findEnumFunction("values", new Function1<FunctionDescriptor, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(FunctionDescriptor descriptor) {
|
||||
return DescriptorUtils.isEnumValuesMethod(descriptor);
|
||||
}
|
||||
});
|
||||
MethodVisitor mv = v.newMethod(myClass, valuesFunction, ACC_PUBLIC | ACC_STATIC, "values", "()" + type.getDescriptor(), null, null);
|
||||
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||
|
||||
mv.visitCode();
|
||||
@@ -877,8 +885,14 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
private void generateEnumValueOfMethod() {
|
||||
MethodVisitor mv =
|
||||
v.newMethod(myClass, ACC_PUBLIC | ACC_STATIC, "valueOf", "(Ljava/lang/String;)" + classAsmType.getDescriptor(), null, null);
|
||||
FunctionDescriptor valueOfFunction = findEnumFunction("valueOf", new Function1<FunctionDescriptor, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(FunctionDescriptor descriptor) {
|
||||
return DescriptorUtils.isEnumValueOfMethod(descriptor);
|
||||
}
|
||||
});
|
||||
MethodVisitor mv = v.newMethod(myClass, valueOfFunction,
|
||||
ACC_PUBLIC | ACC_STATIC, "valueOf", "(Ljava/lang/String;)" + classAsmType.getDescriptor(), null, null);
|
||||
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||
|
||||
mv.visitCode();
|
||||
@@ -890,6 +904,16 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
FunctionCodegen.endVisit(mv, "valueOf()", myClass);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private FunctionDescriptor findEnumFunction(@NotNull String name, Function1<FunctionDescriptor, Boolean> predicate) {
|
||||
ClassDescriptor enumClassObject = descriptor.getClassObjectDescriptor();
|
||||
assert enumClassObject != null : "No class object in " + descriptor;
|
||||
Collection<FunctionDescriptor> valuesFunctions = enumClassObject.getDefaultType().getMemberScope().getFunctions(Name.identifier(name));
|
||||
FunctionDescriptor valuesFunction = KotlinPackage.firstOrNull(valuesFunctions, predicate);
|
||||
assert valuesFunction != null : "No " + name + "() function found for " + descriptor;
|
||||
return valuesFunction;
|
||||
}
|
||||
|
||||
protected void generateSyntheticAccessors() {
|
||||
Map<DeclarationDescriptor, DeclarationDescriptor> accessors = context.getAccessors();
|
||||
for (Map.Entry<DeclarationDescriptor, DeclarationDescriptor> entry : accessors.entrySet()) {
|
||||
|
||||
@@ -199,7 +199,7 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
|
||||
assert state.getClassBuilderMode() == ClassBuilderMode.FULL
|
||||
: "<clinit> should not be generated for light classes. Descriptor: " + descriptor;
|
||||
if (clInit == null) {
|
||||
MethodVisitor mv = v.newMethod(null, ACC_STATIC, "<clinit>", "()V", null, null);
|
||||
MethodVisitor mv = v.newMethod(null, descriptor, ACC_STATIC, "<clinit>", "()V", null, null);
|
||||
mv.visitCode();
|
||||
SimpleFunctionDescriptorImpl clInit =
|
||||
SimpleFunctionDescriptorImpl.create(descriptor, Annotations.EMPTY, Name.special("<clinit>"), SYNTHESIZED);
|
||||
|
||||
@@ -129,7 +129,7 @@ public class PropertyCodegen {
|
||||
Type type = typeMapper.mapType(descriptor);
|
||||
String name = p.getName();
|
||||
assert name != null : "Annotation parameter has no name: " + p.getText();
|
||||
MethodVisitor visitor = v.newMethod(p, ACC_PUBLIC | ACC_ABSTRACT, name, "()" + type.getDescriptor(), null, null);
|
||||
MethodVisitor visitor = v.newMethod(p, descriptor, ACC_PUBLIC | ACC_ABSTRACT, name, "()" + type.getDescriptor(), null, null);
|
||||
JetExpression defaultValue = p.getDefaultValue();
|
||||
if (defaultValue != null) {
|
||||
CompileTimeConstant<?> constant = ExpressionCodegen.getCompileTimeConstant(defaultValue, bindingContext);
|
||||
@@ -170,7 +170,7 @@ public class PropertyCodegen {
|
||||
|
||||
if (!isTrait(context.getContextDescriptor()) || kind == OwnerKind.TRAIT_IMPL) {
|
||||
int flags = ACC_DEPRECATED | ACC_FINAL | ACC_PRIVATE | ACC_STATIC | ACC_SYNTHETIC;
|
||||
MethodVisitor mv = v.newMethod(null, flags, name, desc, null, null);
|
||||
MethodVisitor mv = v.newMethod(null, descriptor, flags, name, desc, null, null);
|
||||
AnnotationCodegen.forMethod(mv, typeMapper).genAnnotations(descriptor);
|
||||
mv.visitCode();
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
|
||||
@@ -95,7 +95,8 @@ public class SamWrapperCodegen {
|
||||
}
|
||||
|
||||
private void generateConstructor(Type ownerType, Type functionType, ClassBuilder cv) {
|
||||
MethodVisitor mv = cv.newMethod(null, NO_FLAG_PACKAGE_PRIVATE, "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, functionType), null, null);
|
||||
MethodVisitor mv = cv.newMethod(null, samType.getJavaClassDescriptor(),
|
||||
NO_FLAG_PACKAGE_PRIVATE, "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, functionType), null, null);
|
||||
|
||||
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||
mv.visitCode();
|
||||
|
||||
@@ -127,7 +127,8 @@ public class ScriptCodegen extends MemberCodegen<JetScript> {
|
||||
JvmMethodSignature jvmSignature = typeMapper.mapScriptSignature(scriptDescriptor, context.getEarlierScripts());
|
||||
|
||||
MethodVisitor mv = classBuilder.newMethod(
|
||||
scriptDeclaration, ACC_PUBLIC, jvmSignature.getAsmMethod().getName(), jvmSignature.getAsmMethod().getDescriptor(),
|
||||
scriptDeclaration, scriptDescriptor.getClassDescriptor().getUnsubstitutedPrimaryConstructor(),
|
||||
ACC_PUBLIC, jvmSignature.getAsmMethod().getName(), jvmSignature.getAsmMethod().getDescriptor(),
|
||||
null, null);
|
||||
|
||||
mv.visitCode();
|
||||
|
||||
+2
-1
@@ -232,7 +232,7 @@ public class AnonymousObjectTransformer {
|
||||
|
||||
String constructorDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, descTypes.toArray(new Type[descTypes.size()]));
|
||||
|
||||
MethodVisitor constructorVisitor = classBuilder.newMethod(null,
|
||||
MethodVisitor constructorVisitor = classBuilder.newMethod(null, null,
|
||||
AsmUtil.NO_FLAG_PACKAGE_PRIVATE,
|
||||
"<init>", constructorDescriptor,
|
||||
null, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
@@ -304,6 +304,7 @@ public class AnonymousObjectTransformer {
|
||||
@NotNull
|
||||
private static MethodVisitor newMethod(@NotNull ClassBuilder builder, @NotNull MethodNode original) {
|
||||
return builder.newMethod(
|
||||
null,
|
||||
null,
|
||||
original.access,
|
||||
original.name,
|
||||
|
||||
@@ -61,13 +61,16 @@ public class RemappingClassBuilder extends DelegatingClassBuilder {
|
||||
@NotNull
|
||||
public MethodVisitor newMethod(
|
||||
@Nullable PsiElement origin,
|
||||
@Nullable DeclarationDescriptor descriptor,
|
||||
int access,
|
||||
@NotNull String name,
|
||||
@NotNull String desc,
|
||||
@Nullable String signature,
|
||||
@Nullable String[] exceptions
|
||||
) {
|
||||
return new RemappingMethodAdapter(access, desc, builder.newMethod(origin, access, name, remapper.mapMethodDesc(desc), signature, exceptions), remapper);
|
||||
return new RemappingMethodAdapter(access, desc,
|
||||
builder.newMethod(origin, descriptor, access, name, remapper.mapMethodDesc(desc), signature, exceptions),
|
||||
remapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -99,13 +99,14 @@ public class StubClassBuilder extends AbstractClassBuilder {
|
||||
@Override
|
||||
public MethodVisitor newMethod(
|
||||
@Nullable PsiElement origin,
|
||||
@Nullable DeclarationDescriptor descriptor,
|
||||
int access,
|
||||
@NotNull String name,
|
||||
@NotNull String desc,
|
||||
@Nullable String signature,
|
||||
@Nullable String[] exceptions
|
||||
) {
|
||||
MethodVisitor internalVisitor = super.newMethod(origin, access, name, desc, signature, exceptions);
|
||||
MethodVisitor internalVisitor = super.newMethod(origin, descriptor, access, name, desc, signature, exceptions);
|
||||
|
||||
if (internalVisitor != EMPTY_METHOD_VISITOR) {
|
||||
// If stub for method generated
|
||||
|
||||
Reference in New Issue
Block a user