Make JvmPropertyAccessorSignature extends JvmMethodSignature

This commit is contained in:
Mikhael Bogdanov
2013-04-26 11:08:11 +04:00
parent ffed25f48c
commit 5fe6e32882
4 changed files with 49 additions and 52 deletions
@@ -525,18 +525,27 @@ public class BothSignatureWriter {
@NotNull
public JvmMethodSignature makeJvmMethodSignature(String name) {
if (needGenerics) {
return new JvmMethodSignature(
makeAsmMethod(name),
makeJavaGenericSignature(),
makeKotlinMethodTypeParameters(),
makeKotlinParameterTypes(),
makeKotlinReturnTypeSignature()
);
}
else {
return new JvmMethodSignature(makeAsmMethod(name), makeKotlinParameterTypes());
}
return new JvmMethodSignature(
makeAsmMethod(name),
needGenerics ? makeJavaGenericSignature() : null,
needGenerics ? makeKotlinMethodTypeParameters() : null,
makeKotlinParameterTypes(),
makeKotlinReturnTypeSignature(),
needGenerics
);
}
@NotNull
public JvmPropertyAccessorSignature makeJvmPropertyAccessorSignature(String name, boolean isGetter) {
return new JvmPropertyAccessorSignature(
makeAsmMethod(name),
needGenerics ? makeJavaGenericSignature() : null,
needGenerics ? makeKotlinMethodTypeParameters() : null,
makeKotlinParameterTypes(),
makeKotlinReturnTypeSignature(),
needGenerics,
isGetter
);
}
}
@@ -43,38 +43,20 @@ public class JvmMethodSignature {
*/
private final boolean genericsAvailable;
public JvmMethodSignature(
protected JvmMethodSignature(
@NotNull Method asmMethod,
@Nullable String genericsSignature,
@Nullable String kotlinTypeParameters,
@NotNull List<JvmMethodParameterSignature> kotlinParameterTypes,
@NotNull String kotlinReturnType
@NotNull String kotlinReturnType,
boolean genericsAvailable
) {
this.asmMethod = asmMethod;
this.genericsSignature = genericsSignature;
this.kotlinTypeParameter = kotlinTypeParameters;
this.kotlinParameterTypes = kotlinParameterTypes;
this.kotlinReturnType = kotlinReturnType;
this.genericsAvailable = true;
}
public JvmMethodSignature(@NotNull Method asmMethod, @NotNull List<JvmMethodParameterSignature> kotlinParameterTypes) {
this.asmMethod = asmMethod;
this.genericsSignature = null;
this.kotlinTypeParameter = null;
this.kotlinParameterTypes = kotlinParameterTypes;
this.kotlinReturnType = "";
this.genericsAvailable = false;
}
public static JvmMethodSignature simple(
@NotNull String methodName,
@NotNull Type returnType,
@NotNull List<JvmMethodParameterSignature> parameterSignatures
) {
List<Type> types = getTypes(parameterSignatures);
return new JvmMethodSignature(new Method(methodName, returnType, types.toArray(new Type[types.size()])),
parameterSignatures);
this.genericsAvailable = genericsAvailable;
}
@NotNull
@@ -17,25 +17,36 @@
package org.jetbrains.jet.codegen.signature;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.asm4.commons.Method;
public class JvmPropertyAccessorSignature {
@NotNull
private final JvmMethodSignature jvmMethodSignature;
@NotNull
private final String propertyTypeKotlinSignature;
import java.util.List;
public JvmPropertyAccessorSignature(@NotNull JvmMethodSignature jvmMethodSignature, @NotNull String propertyTypeKotlinSignature) {
this.jvmMethodSignature = jvmMethodSignature;
this.propertyTypeKotlinSignature = propertyTypeKotlinSignature;
public class JvmPropertyAccessorSignature extends JvmMethodSignature {
private final boolean isGetter;
protected JvmPropertyAccessorSignature(
@NotNull Method asmMethod,
@Nullable String genericsSignature,
@Nullable String kotlinTypeParameters,
@NotNull List<JvmMethodParameterSignature> kotlinParameterTypes,
@NotNull String kotlinReturnType,
boolean needGenerics,
boolean isGetter
) {
super(asmMethod, genericsSignature, kotlinTypeParameters, kotlinParameterTypes,
kotlinReturnType, needGenerics);
this.isGetter = isGetter;
}
@NotNull
public JvmMethodSignature getJvmMethodSignature() {
return jvmMethodSignature;
return this;
}
@NotNull
public String getPropertyTypeKotlinSignature() {
return propertyTypeKotlinSignature;
return isGetter ? getKotlinReturnType() : getKotlinParameterType(getParameterCount() - 1);
}
}
@@ -736,8 +736,6 @@ public class JetTypeMapper extends BindingTraceAware {
@NotNull
public JvmPropertyAccessorSignature mapGetterSignature(PropertyDescriptor descriptor, OwnerKind kind) {
String name = getPropertyAccessorName(descriptor, true);
// TODO: do not genClassOrObject generics if not needed
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true);
@@ -752,9 +750,8 @@ public class JetTypeMapper extends BindingTraceAware {
mapType(descriptor.getType(), signatureWriter, JetTypeMapperMode.VALUE, Variance.OUT_VARIANCE);
signatureWriter.writeReturnTypeEnd();
JvmMethodSignature jvmMethodSignature = signatureWriter.makeJvmMethodSignature(name);
return new JvmPropertyAccessorSignature(jvmMethodSignature, jvmMethodSignature.getKotlinReturnType());
String name = getPropertyAccessorName(descriptor, true);
return signatureWriter.makeJvmPropertyAccessorSignature(name, true);
}
@@ -776,9 +773,7 @@ public class JetTypeMapper extends BindingTraceAware {
signatureWriter.writeVoidReturn();
String name = getPropertyAccessorName(descriptor, false);
JvmMethodSignature jvmMethodSignature = signatureWriter.makeJvmMethodSignature(name);
return new JvmPropertyAccessorSignature(jvmMethodSignature,
jvmMethodSignature.getKotlinParameterType(jvmMethodSignature.getParameterCount() - 1));
return signatureWriter.makeJvmPropertyAccessorSignature(name, false);
}
private void writeParameter(BothSignatureWriter signatureWriter, JetType outType) {