Do not write old annotations (JetClass and others)
This commit is contained in:
@@ -122,7 +122,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
||||
JvmMethodSignature jvmMethodSignature = typeMapper.mapSignature(interfaceFunction.getName(), funDescriptor);
|
||||
|
||||
FunctionCodegen fc = new FunctionCodegen(context, cv, state);
|
||||
fc.generateMethod(fun, jvmMethodSignature, false, funDescriptor, strategy);
|
||||
fc.generateMethod(fun, jvmMethodSignature, funDescriptor, strategy);
|
||||
|
||||
this.constructor = generateConstructor(cv);
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ import org.jetbrains.jet.lang.psi.JetClassObject;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
@@ -105,23 +104,6 @@ public class CodegenUtil {
|
||||
}
|
||||
|
||||
|
||||
public static int getFlagsForVisibility(@NotNull Visibility visibility) {
|
||||
if (visibility == Visibilities.INTERNAL) {
|
||||
return JvmStdlibNames.FLAG_INTERNAL_BIT;
|
||||
}
|
||||
else if (visibility == Visibilities.PRIVATE) {
|
||||
return JvmStdlibNames.FLAG_PRIVATE_BIT;
|
||||
}
|
||||
else if (visibility == Visibilities.PROTECTED) {
|
||||
return JvmStdlibNames.FLAG_PROTECTED_BIT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int getFlagsForClassKind(@NotNull ClassDescriptor descriptor) {
|
||||
return descriptor.getKind() == ClassKind.OBJECT ? JvmStdlibNames.FLAG_CLASS_KIND_OBJECT : JvmStdlibNames.FLAG_CLASS_KIND_DEFAULT;
|
||||
}
|
||||
|
||||
public static JvmMethodSignature erasedInvokeSignature(FunctionDescriptor fd) {
|
||||
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, false);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
@@ -20,7 +21,6 @@ import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.asm4.AnnotationVisitor;
|
||||
import org.jetbrains.asm4.Label;
|
||||
import org.jetbrains.asm4.MethodVisitor;
|
||||
import org.jetbrains.asm4.Type;
|
||||
@@ -32,9 +32,6 @@ import org.jetbrains.jet.codegen.context.MethodContext;
|
||||
import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind;
|
||||
import org.jetbrains.jet.codegen.signature.JvmMethodParameterSignature;
|
||||
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
||||
import org.jetbrains.jet.codegen.signature.JvmPropertyAccessorSignature;
|
||||
import org.jetbrains.jet.codegen.signature.kotlin.JetMethodAnnotationWriter;
|
||||
import org.jetbrains.jet.codegen.signature.kotlin.JetValueParameterAnnotationWriter;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.codegen.state.GenerationStateAware;
|
||||
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||
@@ -44,8 +41,6 @@ import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
@@ -78,8 +73,7 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
JvmMethodSignature method = typeMapper.mapSignature(functionDescriptor, true, kind);
|
||||
|
||||
if (kind != OwnerKind.TRAIT_IMPL || function.getBodyExpression() != null) {
|
||||
boolean needJetAnnotations = kind != OwnerKind.TRAIT_IMPL;
|
||||
generateMethod(function, method, needJetAnnotations, functionDescriptor,
|
||||
generateMethod(function, method, functionDescriptor,
|
||||
new FunctionGenerationStrategy.FunctionDefault(state, functionDescriptor, function));
|
||||
}
|
||||
|
||||
@@ -90,17 +84,15 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
public void generateMethod(
|
||||
@Nullable PsiElement origin,
|
||||
@NotNull JvmMethodSignature jvmSignature,
|
||||
boolean needJetAnnotations,
|
||||
@NotNull FunctionDescriptor functionDescriptor,
|
||||
@NotNull FunctionGenerationStrategy strategy
|
||||
) {
|
||||
generateMethod(origin, jvmSignature, needJetAnnotations, functionDescriptor, owner.intoFunction(functionDescriptor), strategy);
|
||||
generateMethod(origin, jvmSignature, functionDescriptor, owner.intoFunction(functionDescriptor), strategy);
|
||||
}
|
||||
|
||||
public void generateMethod(
|
||||
@Nullable PsiElement origin,
|
||||
@NotNull JvmMethodSignature jvmSignature,
|
||||
boolean needJetAnnotations,
|
||||
@NotNull FunctionDescriptor functionDescriptor,
|
||||
@NotNull MethodContext methodContext,
|
||||
@NotNull FunctionGenerationStrategy strategy
|
||||
@@ -126,10 +118,6 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
AnnotationCodegen.forMethod(mv, typeMapper).genAnnotations(functionDescriptor);
|
||||
if (state.getClassBuilderMode() == ClassBuilderMode.SIGNATURES) return;
|
||||
|
||||
if (needJetAnnotations) {
|
||||
genJetAnnotations(mv, functionDescriptor, jvmSignature);
|
||||
}
|
||||
|
||||
if (isAbstractMethod(functionDescriptor, methodContext.getContextKind())) return;
|
||||
|
||||
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
||||
@@ -334,94 +322,6 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
iv.areturn(asmMethod.getReturnType());
|
||||
}
|
||||
|
||||
private void genJetAnnotations(
|
||||
@NotNull MethodVisitor mv,
|
||||
@NotNull FunctionDescriptor functionDescriptor,
|
||||
@NotNull JvmMethodSignature jvmSignature
|
||||
) {
|
||||
|
||||
if (functionDescriptor instanceof PropertyAccessorDescriptor) {
|
||||
assert jvmSignature instanceof JvmPropertyAccessorSignature : "jvmSignature for property should have JvmPropertyAccessorSignature type";
|
||||
PropertyCodegen.generateJetPropertyAnnotation(mv, (JvmPropertyAccessorSignature) jvmSignature,
|
||||
((PropertyAccessorDescriptor) functionDescriptor).getCorrespondingProperty(), functionDescriptor.getVisibility());
|
||||
}
|
||||
else if (functionDescriptor instanceof SimpleFunctionDescriptor) {
|
||||
assert !(jvmSignature instanceof JvmPropertyAccessorSignature) : "jvmSignature for function shouldn't have JvmPropertyAccessorSignature type";
|
||||
|
||||
Modality modality = functionDescriptor.getModality();
|
||||
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
|
||||
int kotlinFlags = getFlagsForVisibility(functionDescriptor.getVisibility());
|
||||
if (isInterface(functionDescriptor.getContainingDeclaration()) && modality != Modality.ABSTRACT) {
|
||||
kotlinFlags |= modality == Modality.FINAL
|
||||
? JvmStdlibNames.FLAG_FORCE_FINAL_BIT
|
||||
: JvmStdlibNames.FLAG_FORCE_OPEN_BIT;
|
||||
}
|
||||
kotlinFlags |= DescriptorKindUtils.kindToFlags(functionDescriptor.getKind());
|
||||
aw.writeFlags(kotlinFlags);
|
||||
if (jvmSignature.getKotlinTypeParameter() != null) {
|
||||
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
||||
}
|
||||
aw.writeReturnType(jvmSignature.getKotlinReturnType());
|
||||
aw.visitEnd();
|
||||
}
|
||||
else if (functionDescriptor instanceof ConstructorDescriptor) {
|
||||
AnnotationVisitor jetConstructorVisitor = mv.visitAnnotation(JvmStdlibNames.JET_CONSTRUCTOR.getDescriptor(), true);
|
||||
|
||||
int flagsValue = getFlagsForVisibility(functionDescriptor.getVisibility());
|
||||
if (JvmStdlibNames.FLAGS_DEFAULT_VALUE != flagsValue) {
|
||||
jetConstructorVisitor.visit(JvmStdlibNames.JET_FLAGS_FIELD, flagsValue);
|
||||
}
|
||||
|
||||
jetConstructorVisitor.visitEnd();
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
generateMethodParametersAnnotations(mv, functionDescriptor, jvmSignature);
|
||||
}
|
||||
|
||||
void generateMethodParametersAnnotations(
|
||||
MethodVisitor mv,
|
||||
FunctionDescriptor functionDescriptor,
|
||||
JvmMethodSignature jvmSignature
|
||||
) {
|
||||
Iterator<ValueParameterDescriptor> valueParameters = functionDescriptor.getValueParameters().iterator();
|
||||
List<JvmMethodParameterSignature> kotlinParameterTypes = jvmSignature.getKotlinParameterTypes();
|
||||
|
||||
assert kotlinParameterTypes != null;
|
||||
|
||||
for (int i = 0; i < kotlinParameterTypes.size(); i++) {
|
||||
JvmMethodParameterSignature param = kotlinParameterTypes.get(i);
|
||||
JvmMethodParameterKind kind = param.getKind();
|
||||
String parameterName = "$" + param.getKind().name().toLowerCase();
|
||||
|
||||
ValueParameterDescriptor parameterDescriptor = null;
|
||||
if (kind == JvmMethodParameterKind.VALUE) {
|
||||
parameterDescriptor = valueParameters.next();
|
||||
parameterName = parameterDescriptor.getName().asString();
|
||||
} else if (kind == JvmMethodParameterKind.ENUM_NAME || kind == JvmMethodParameterKind.ENUM_ORDINAL) {
|
||||
//we shouldn't generate annotations for invisible in runtime parameters otherwise we get bad RuntimeInvisibleParameterAnnotations error in javac
|
||||
continue;
|
||||
} else if (needIndexForVar(kind)) {
|
||||
parameterName = parameterName + "$" + i;
|
||||
}
|
||||
|
||||
AnnotationCodegen.forParameter(i, mv, typeMapper).genAnnotations(parameterDescriptor);
|
||||
JetValueParameterAnnotationWriter av = JetValueParameterAnnotationWriter.visitParameterAnnotation(mv, i);
|
||||
av.writeName(parameterName);
|
||||
if (kind == JvmMethodParameterKind.RECEIVER) {
|
||||
av.writeReceiver();
|
||||
}
|
||||
if (parameterDescriptor != null) {
|
||||
av.writeHasDefaultValue(parameterDescriptor.declaresDefaultValue());
|
||||
av.writeVararg(parameterDescriptor.getVarargElementType() != null);
|
||||
}
|
||||
av.writeType(param.getKotlinSignature());
|
||||
av.visitEnd();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean needIndexForVar(JvmMethodParameterKind kind) {
|
||||
return kind == JvmMethodParameterKind.SHARED_VAR || kind == JvmMethodParameterKind.SUPER_CALL_PARAM;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ import org.jetbrains.jet.codegen.context.ClassContext;
|
||||
import org.jetbrains.jet.codegen.context.ConstructorContext;
|
||||
import org.jetbrains.jet.codegen.context.MethodContext;
|
||||
import org.jetbrains.jet.codegen.signature.*;
|
||||
import org.jetbrains.jet.codegen.signature.kotlin.JetMethodAnnotationWriter;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
|
||||
@@ -58,7 +57,6 @@ import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
@@ -212,8 +210,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
writeInnerClasses();
|
||||
|
||||
AnnotationCodegen.forClass(v.getVisitor(), typeMapper).genAnnotations(descriptor);
|
||||
|
||||
writeClassSignatureIfNeeded(signature);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -345,22 +341,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
return typeMapper.mapType(descriptor.getDefaultType(), JetTypeMapperMode.IMPL).getInternalName();
|
||||
}
|
||||
|
||||
private void writeClassSignatureIfNeeded(JvmClassSignature signature) {
|
||||
AnnotationVisitor annotationVisitor = v.newAnnotation(JvmStdlibNames.JET_CLASS.getDescriptor(), true);
|
||||
annotationVisitor.visit(JvmStdlibNames.JET_CLASS_SIGNATURE, signature.getKotlinGenericSignature());
|
||||
int flags = getFlagsForVisibility(descriptor.getVisibility()) | getFlagsForClassKind(descriptor);
|
||||
if (JvmStdlibNames.FLAGS_DEFAULT_VALUE != flags) {
|
||||
annotationVisitor.visit(JvmStdlibNames.JET_FLAGS_FIELD, flags);
|
||||
}
|
||||
annotationVisitor.visit(JvmStdlibNames.ABI_VERSION_NAME, JvmAbi.VERSION);
|
||||
annotationVisitor.visitEnd();
|
||||
|
||||
if (descriptor.getKind() == ClassKind.CLASS_OBJECT) {
|
||||
AnnotationVisitor classObjectVisitor = v.newAnnotation(JvmStdlibNames.JET_CLASS_OBJECT.getDescriptor(), true);
|
||||
classObjectVisitor.visitEnd();
|
||||
}
|
||||
}
|
||||
|
||||
private JvmClassSignature signature() {
|
||||
List<String> superInterfaces;
|
||||
|
||||
@@ -410,8 +390,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
signatureVisitor.writeSupersEnd();
|
||||
|
||||
return new JvmClassSignature(jvmName(), superClassAsmType.getInternalName(), superInterfaces, signatureVisitor.makeJavaGenericSignature(),
|
||||
signatureVisitor.makeKotlinClassSignature());
|
||||
return new JvmClassSignature(jvmName(), superClassAsmType.getInternalName(), superInterfaces, signatureVisitor.makeJavaGenericSignature());
|
||||
}
|
||||
|
||||
private String jvmName() {
|
||||
@@ -722,7 +701,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
JvmMethodSignature signature = typeMapper.mapSignature(function);
|
||||
|
||||
FunctionCodegen fc = new FunctionCodegen(context, v, state);
|
||||
fc.generateMethod(myClass, signature, true, function, new FunctionGenerationStrategy() {
|
||||
fc.generateMethod(myClass, signature, function, new FunctionGenerationStrategy() {
|
||||
@Override
|
||||
public void generateBody(
|
||||
@NotNull MethodVisitor mv,
|
||||
@@ -746,7 +725,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
final Type thisDescriptorType = typeMapper.mapType(descriptor.getDefaultType());
|
||||
|
||||
FunctionCodegen fc = new FunctionCodegen(context, v, state);
|
||||
fc.generateMethod(myClass, methodSignature, true, function, new FunctionGenerationStrategy() {
|
||||
fc.generateMethod(myClass, methodSignature, function, new FunctionGenerationStrategy() {
|
||||
@Override
|
||||
public void generateBody(
|
||||
@NotNull MethodVisitor mv,
|
||||
@@ -787,23 +766,25 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
MethodContext functionContext = context.intoFunction(function);
|
||||
FunctionCodegen.generateDefaultIfNeeded(functionContext, state, v, methodSignature, function, OwnerKind.IMPLEMENTATION,
|
||||
new DefaultParameterValueLoader() {
|
||||
@Override
|
||||
public void putValueOnStack(
|
||||
ValueParameterDescriptor descriptor,
|
||||
ExpressionCodegen codegen
|
||||
) {
|
||||
assert (KotlinBuiltIns.getInstance().isData((ClassDescriptor) function.getContainingDeclaration()))
|
||||
: "Trying to create function with default arguments for function that isn't presented in code for class without data annotation";
|
||||
PropertyDescriptor propertyDescriptor = codegen.getBindingContext().get(
|
||||
BindingContext.VALUE_PARAMETER_AS_PROPERTY, descriptor);
|
||||
assert propertyDescriptor != null
|
||||
: "Trying to generate default value for parameter of copy function that doesn't correspond to any property";
|
||||
codegen.v.load(0, thisDescriptorType);
|
||||
Type propertyType = codegen.typeMapper.mapType(propertyDescriptor.getType());
|
||||
codegen.intermediateValueForProperty(propertyDescriptor, false, null).put(propertyType, codegen.v);
|
||||
}
|
||||
});
|
||||
new DefaultParameterValueLoader() {
|
||||
@Override
|
||||
public void putValueOnStack(
|
||||
ValueParameterDescriptor descriptor,
|
||||
ExpressionCodegen codegen
|
||||
) {
|
||||
assert (KotlinBuiltIns.getInstance()
|
||||
.isData((ClassDescriptor) function.getContainingDeclaration()))
|
||||
: "Trying to create function with default arguments for function that isn't presented in code for class without data annotation";
|
||||
PropertyDescriptor propertyDescriptor = codegen.getBindingContext().get(
|
||||
BindingContext.VALUE_PARAMETER_AS_PROPERTY, descriptor);
|
||||
assert propertyDescriptor != null
|
||||
: "Trying to generate default value for parameter of copy function that doesn't correspond to any property";
|
||||
codegen.v.load(0, thisDescriptorType);
|
||||
Type propertyType = codegen.typeMapper.mapType(propertyDescriptor.getType());
|
||||
codegen.intermediateValueForProperty(propertyDescriptor, false, null)
|
||||
.put(propertyType, codegen.v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void generateEnumMethodsAndConstInitializers() {
|
||||
@@ -861,7 +842,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
if (entry.getValue() instanceof FunctionDescriptor) {
|
||||
FunctionDescriptor bridge = (FunctionDescriptor) entry.getValue();
|
||||
final FunctionDescriptor original = (FunctionDescriptor) entry.getKey();
|
||||
functionCodegen.generateMethod(null, typeMapper.mapSignature(bridge), false, bridge,
|
||||
functionCodegen.generateMethod(null, typeMapper.mapSignature(bridge), bridge,
|
||||
new FunctionGenerationStrategy.CodegenBased<FunctionDescriptor>(state, bridge) {
|
||||
@Override
|
||||
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
|
||||
@@ -878,7 +859,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
PropertyGetterDescriptor getter = bridge.getGetter();
|
||||
assert getter != null;
|
||||
functionCodegen.generateMethod(null, typeMapper.mapGetterSignature(bridge, OwnerKind.IMPLEMENTATION), false, getter,
|
||||
functionCodegen.generateMethod(null, typeMapper.mapGetterSignature(bridge, OwnerKind.IMPLEMENTATION), getter,
|
||||
new FunctionGenerationStrategy.CodegenBased<PropertyGetterDescriptor>(state, getter) {
|
||||
@Override
|
||||
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
|
||||
@@ -898,7 +879,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
PropertySetterDescriptor setter = bridge.getSetter();
|
||||
assert setter != null;
|
||||
|
||||
functionCodegen.generateMethod(null, typeMapper.mapSetterSignature(bridge, OwnerKind.IMPLEMENTATION), false, setter,
|
||||
functionCodegen.generateMethod(null, typeMapper.mapSetterSignature(bridge, OwnerKind.IMPLEMENTATION), setter,
|
||||
new FunctionGenerationStrategy.CodegenBased<PropertySetterDescriptor>(state, setter) {
|
||||
@Override
|
||||
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
|
||||
@@ -1055,7 +1036,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
assert constructorDescriptor != null;
|
||||
final JvmMethodSignature constructorSignature = typeMapper.mapConstructorSignature(constructorDescriptor, closure);
|
||||
|
||||
functionCodegen.generateMethod(null, constructorSignature, true, constructorDescriptor, constructorContext,
|
||||
functionCodegen.generateMethod(null, constructorSignature, constructorDescriptor, constructorContext,
|
||||
new FunctionGenerationStrategy.CodegenBased<ConstructorDescriptor>(state, constructorDescriptor) {
|
||||
|
||||
@NotNull
|
||||
@@ -1386,9 +1367,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
genStubCode(mv);
|
||||
}
|
||||
else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||
writeAnnotationForDelegateToTraitImpl(fun, inheritedFun, mv);
|
||||
functionCodegen.generateMethodParametersAnnotations(mv, fun, typeMapper.mapSignature(fun));
|
||||
|
||||
Type returnType = methodToGenerate.getReturnType();
|
||||
|
||||
mv.visitCode();
|
||||
@@ -1438,14 +1416,14 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
PropertyDescriptor property = ((PropertyAccessorDescriptor) fun).getCorrespondingProperty();
|
||||
PropertyDescriptor original = property.getOriginal();
|
||||
if (fun instanceof PropertyGetterDescriptor) {
|
||||
JvmPropertyAccessorSignature toGenerate = typeMapper.mapGetterSignature(property, OwnerKind.IMPLEMENTATION);
|
||||
JvmPropertyAccessorSignature inTrait = typeMapper.mapGetterSignature(original, OwnerKind.IMPLEMENTATION);
|
||||
JvmMethodSignature toGenerate = typeMapper.mapGetterSignature(property, OwnerKind.IMPLEMENTATION);
|
||||
JvmMethodSignature inTrait = typeMapper.mapGetterSignature(original, OwnerKind.IMPLEMENTATION);
|
||||
return new TraitImplDelegateInfo(
|
||||
toGenerate.getAsmMethod(), inTrait.getAsmMethod());
|
||||
}
|
||||
else if (fun instanceof PropertySetterDescriptor) {
|
||||
JvmPropertyAccessorSignature toGenerate = typeMapper.mapSetterSignature(property, OwnerKind.IMPLEMENTATION);
|
||||
JvmPropertyAccessorSignature inTrait = typeMapper.mapSetterSignature(original, OwnerKind.IMPLEMENTATION);
|
||||
JvmMethodSignature toGenerate = typeMapper.mapSetterSignature(property, OwnerKind.IMPLEMENTATION);
|
||||
JvmMethodSignature inTrait = typeMapper.mapSetterSignature(original, OwnerKind.IMPLEMENTATION);
|
||||
return new TraitImplDelegateInfo(
|
||||
toGenerate.getAsmMethod(), inTrait.getAsmMethod());
|
||||
}
|
||||
@@ -1460,28 +1438,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeAnnotationForDelegateToTraitImpl(
|
||||
@NotNull FunctionDescriptor fun,
|
||||
@NotNull FunctionDescriptor inheritedFun,
|
||||
@NotNull MethodVisitor mv
|
||||
) {
|
||||
JvmMethodSignature jvmSignature = typeMapper.mapSignature(inheritedFun, true, OwnerKind.IMPLEMENTATION);
|
||||
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
|
||||
int kotlinFlags = getFlagsForVisibility(fun.getVisibility());
|
||||
if (fun instanceof PropertyAccessorDescriptor) {
|
||||
kotlinFlags |= JvmStdlibNames.FLAG_PROPERTY_BIT;
|
||||
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
||||
aw.writePropertyType(jvmSignature.getKotlinReturnType());
|
||||
}
|
||||
else {
|
||||
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
||||
aw.writeReturnType(jvmSignature.getKotlinReturnType());
|
||||
}
|
||||
kotlinFlags |= DescriptorKindUtils.kindToFlags(inheritedFun.getKind());
|
||||
aw.writeFlags(kotlinFlags);
|
||||
aw.visitEnd();
|
||||
}
|
||||
|
||||
private void generateDelegatorToConstructorCall(
|
||||
InstructionAdapter iv, ExpressionCodegen codegen,
|
||||
ConstructorDescriptor constructorDescriptor
|
||||
|
||||
@@ -104,13 +104,7 @@ public class NamespaceCodegen extends MemberCodegen {
|
||||
List<MemberMap> namespaceMembers = new ArrayList<MemberMap>(files.size() + 1);
|
||||
|
||||
if (shouldGenerateNSClass(files)) {
|
||||
ClassBuilder cv = v.getClassBuilder();
|
||||
|
||||
AnnotationVisitor packageClassAnnotation = cv.newAnnotation(JvmStdlibNames.JET_PACKAGE_CLASS.getDescriptor(), true);
|
||||
packageClassAnnotation.visit(JvmStdlibNames.ABI_VERSION_NAME, JvmAbi.VERSION);
|
||||
packageClassAnnotation.visitEnd();
|
||||
|
||||
namespaceMembers.add(cv.getMemberMap());
|
||||
namespaceMembers.add(v.getClassBuilder().getMemberMap());
|
||||
}
|
||||
|
||||
for (JetFile file : files) {
|
||||
@@ -331,4 +325,4 @@ public class NamespaceCodegen extends MemberCodegen {
|
||||
JvmClassName namespaceJvmClassName = getJVMClassNameForKotlinNs(fqName);
|
||||
return getMultiFileNamespaceInternalName(namespaceJvmClassName.getFqName(), file).getInternalName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,6 @@ import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||
import org.jetbrains.jet.codegen.context.CodegenContext;
|
||||
import org.jetbrains.jet.codegen.context.FieldOwnerContext;
|
||||
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
||||
import org.jetbrains.jet.codegen.signature.JvmPropertyAccessorSignature;
|
||||
import org.jetbrains.jet.codegen.signature.kotlin.JetMethodAnnotationWriter;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.codegen.state.GenerationStateAware;
|
||||
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||
@@ -40,8 +38,6 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
@@ -51,7 +47,8 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import static org.jetbrains.asm4.Opcodes.*;
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.getDeprecatedAccessFlag;
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.getVisibilityForSpecialPropertyBackingField;
|
||||
import static org.jetbrains.jet.codegen.CodegenUtil.*;
|
||||
import static org.jetbrains.jet.codegen.CodegenUtil.getParentBodyCodegen;
|
||||
import static org.jetbrains.jet.codegen.CodegenUtil.isInterface;
|
||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||
|
||||
public class PropertyCodegen extends GenerationStateAware {
|
||||
@@ -231,7 +228,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
||||
|
||||
//TODO: Now it's not enough information to properly resolve property from bytecode without generated getter and setter
|
||||
//if (!defaultGetter || isExternallyAccessible(propertyDescriptor)) {
|
||||
JvmPropertyAccessorSignature signature = typeMapper.mapGetterSignature(propertyDescriptor, kind);
|
||||
JvmMethodSignature signature = typeMapper.mapGetterSignature(propertyDescriptor, kind);
|
||||
PropertyGetterDescriptor getterDescriptor = propertyDescriptor.getGetter();
|
||||
getterDescriptor = getterDescriptor != null ? getterDescriptor : DescriptorResolver.createDefaultGetter(propertyDescriptor);
|
||||
|
||||
@@ -250,7 +247,6 @@ public class PropertyCodegen extends GenerationStateAware {
|
||||
}
|
||||
functionCodegen.generateMethod(getter != null ? getter : p,
|
||||
signature,
|
||||
true,
|
||||
getterDescriptor,
|
||||
strategy);
|
||||
}
|
||||
@@ -262,7 +258,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
||||
|
||||
//TODO: Now it's not enough information to properly resolve property from bytecode without generated getter and setter
|
||||
if (/*!defaultSetter || isExternallyAccessible(propertyDescriptor) &&*/ propertyDescriptor.isVar()) {
|
||||
JvmPropertyAccessorSignature signature = typeMapper.mapSetterSignature(propertyDescriptor, kind);
|
||||
JvmMethodSignature signature = typeMapper.mapSetterSignature(propertyDescriptor, kind);
|
||||
PropertySetterDescriptor setterDescriptor = propertyDescriptor.getSetter();
|
||||
setterDescriptor = setterDescriptor != null ? setterDescriptor : DescriptorResolver.createDefaultSetter(propertyDescriptor);
|
||||
|
||||
@@ -281,7 +277,6 @@ public class PropertyCodegen extends GenerationStateAware {
|
||||
}
|
||||
functionCodegen.generateMethod(setter != null ? setter : p,
|
||||
signature,
|
||||
true,
|
||||
setterDescriptor,
|
||||
strategy);
|
||||
}
|
||||
@@ -384,24 +379,6 @@ public class PropertyCodegen extends GenerationStateAware {
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateJetPropertyAnnotation(
|
||||
MethodVisitor mv, @NotNull JvmPropertyAccessorSignature propertyAccessorSignature,
|
||||
@NotNull PropertyDescriptor propertyDescriptor, @NotNull Visibility visibility
|
||||
) {
|
||||
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
|
||||
Modality modality = propertyDescriptor.getModality();
|
||||
int flags = getFlagsForVisibility(visibility) | JvmStdlibNames.FLAG_PROPERTY_BIT;
|
||||
if (isInterface(propertyDescriptor.getContainingDeclaration()) && modality != Modality.ABSTRACT) {
|
||||
flags |= modality == Modality.FINAL
|
||||
? JvmStdlibNames.FLAG_FORCE_FINAL_BIT
|
||||
: JvmStdlibNames.FLAG_FORCE_OPEN_BIT;
|
||||
}
|
||||
aw.writeFlags(flags | DescriptorKindUtils.kindToFlags(propertyDescriptor.getKind()));
|
||||
aw.writeTypeParameters(propertyAccessorSignature.getKotlinTypeParameter());
|
||||
aw.writePropertyType(propertyAccessorSignature.getPropertyTypeKotlinSignature());
|
||||
aw.visitEnd();
|
||||
}
|
||||
|
||||
public static String getterName(Name propertyName) {
|
||||
return JvmAbi.GETTER_PREFIX + StringUtil.capitalizeWithJavaBeanConvention(propertyName.asString());
|
||||
}
|
||||
|
||||
@@ -74,11 +74,7 @@ public class BothSignatureWriter {
|
||||
|
||||
private JetSignatureWriter jetSignatureWriter;
|
||||
|
||||
private String kotlinClassParameters;
|
||||
private String kotlinClassSignature;
|
||||
|
||||
private final List<JvmMethodParameterSignature> kotlinParameterTypes = new ArrayList<JvmMethodParameterSignature>();
|
||||
private String kotlinReturnType;
|
||||
|
||||
private int jvmCurrentTypeArrayLevel;
|
||||
private Type jvmCurrentType;
|
||||
@@ -304,7 +300,7 @@ public class BothSignatureWriter {
|
||||
public void writeFormalTypeParametersEnd() {
|
||||
jetSignatureWriter.visitSuperclass(); // just to call endFormals
|
||||
|
||||
kotlinClassParameters = jetSignatureWriter.toString();
|
||||
String kotlinClassParameters = jetSignatureWriter.toString();
|
||||
|
||||
jetSignatureWriter = null;
|
||||
|
||||
@@ -421,7 +417,7 @@ public class BothSignatureWriter {
|
||||
public void writeReturnTypeEnd() {
|
||||
pop();
|
||||
|
||||
kotlinReturnType = jetSignatureWriter.toString();
|
||||
String kotlinReturnType = jetSignatureWriter.toString();
|
||||
|
||||
if (jvmCurrentType == null) {
|
||||
throw new IllegalStateException();
|
||||
@@ -451,7 +447,7 @@ public class BothSignatureWriter {
|
||||
}
|
||||
|
||||
public void writeSupersEnd() {
|
||||
kotlinClassSignature = jetSignatureWriter.toString();
|
||||
String kotlinClassSignature = jetSignatureWriter.toString();
|
||||
jetSignatureWriter = null;
|
||||
|
||||
if (DEBUG_SIGNATURE_WRITER) {
|
||||
@@ -514,51 +510,12 @@ public class BothSignatureWriter {
|
||||
return kotlinParameterTypes;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String makeKotlinReturnTypeSignature() {
|
||||
checkState(State.METHOD_END);
|
||||
return kotlinReturnType;
|
||||
}
|
||||
|
||||
protected String makeKotlinMethodTypeParameters() {
|
||||
checkState(State.METHOD_END);
|
||||
return kotlinClassParameters;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String makeKotlinClassSignature() {
|
||||
checkState(State.CLASS_END);
|
||||
if (kotlinClassParameters == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
if (kotlinClassSignature == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return kotlinClassParameters + kotlinClassSignature;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature makeJvmMethodSignature(String name) {
|
||||
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
|
||||
makeKotlinParameterTypes()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.codegen.signature;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
@@ -26,17 +25,12 @@ public class JvmClassSignature {
|
||||
private final String superclassName;
|
||||
private final List<String> interfaces;
|
||||
private final String javaGenericSignature;
|
||||
private final String kotlinGenericSignature;
|
||||
|
||||
public JvmClassSignature(
|
||||
String name, String superclassName, List<String> interfaces,
|
||||
@Nullable String javaGenericSignature, @NotNull String kotlinGenericSignature
|
||||
) {
|
||||
public JvmClassSignature(String name, String superclassName, List<String> interfaces, @Nullable String javaGenericSignature) {
|
||||
this.name = name;
|
||||
this.superclassName = superclassName;
|
||||
this.interfaces = interfaces;
|
||||
this.javaGenericSignature = javaGenericSignature;
|
||||
this.kotlinGenericSignature = kotlinGenericSignature;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -54,9 +48,4 @@ public class JvmClassSignature {
|
||||
public String getJavaGenericSignature() {
|
||||
return javaGenericSignature;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getKotlinGenericSignature() {
|
||||
return kotlinGenericSignature;
|
||||
}
|
||||
}
|
||||
|
||||
-8
@@ -23,15 +23,12 @@ public class JvmMethodParameterSignature {
|
||||
@NotNull
|
||||
private final Type asmType;
|
||||
@NotNull
|
||||
private final String kotlinSignature;
|
||||
@NotNull
|
||||
private final JvmMethodParameterKind kind;
|
||||
|
||||
public JvmMethodParameterSignature(
|
||||
@NotNull Type asmType, @NotNull String kotlinSignature, @NotNull JvmMethodParameterKind kind
|
||||
) {
|
||||
this.asmType = asmType;
|
||||
this.kotlinSignature = kotlinSignature;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
@@ -40,11 +37,6 @@ public class JvmMethodParameterSignature {
|
||||
return asmType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getKotlinSignature() {
|
||||
return kotlinSignature;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodParameterKind getKind() {
|
||||
return kind;
|
||||
|
||||
@@ -32,47 +32,17 @@ public class JvmMethodSignature {
|
||||
* Null when we don't care about type parameters
|
||||
*/
|
||||
private final String genericsSignature;
|
||||
private final String kotlinTypeParameter;
|
||||
@NotNull
|
||||
private final List<JvmMethodParameterSignature> kotlinParameterTypes;
|
||||
@NotNull
|
||||
private final String kotlinReturnType;
|
||||
|
||||
/**
|
||||
* Generics info is generated. However it can be trivial (e.g. fields are null).
|
||||
*/
|
||||
private final boolean genericsAvailable;
|
||||
|
||||
protected JvmMethodSignature(
|
||||
@NotNull Method asmMethod,
|
||||
@Nullable String genericsSignature,
|
||||
@Nullable String kotlinTypeParameters,
|
||||
@NotNull List<JvmMethodParameterSignature> kotlinParameterTypes,
|
||||
@NotNull String kotlinReturnType,
|
||||
boolean genericsAvailable
|
||||
@NotNull List<JvmMethodParameterSignature> kotlinParameterTypes
|
||||
) {
|
||||
this.asmMethod = asmMethod;
|
||||
this.genericsSignature = genericsSignature;
|
||||
this.kotlinTypeParameter = kotlinTypeParameters;
|
||||
this.kotlinParameterTypes = kotlinParameterTypes;
|
||||
this.kotlinReturnType = kotlinReturnType;
|
||||
this.genericsAvailable = genericsAvailable;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Type> getTypes(@NotNull List<JvmMethodParameterSignature> signatures) {
|
||||
List<Type> r = new ArrayList<Type>(signatures.size());
|
||||
for (JvmMethodParameterSignature signature : signatures) {
|
||||
r.add(signature.getAsmType());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private void checkGenericsAvailable() {
|
||||
if (!genericsAvailable) {
|
||||
// TODO: uncomment following line and fix all broken tests
|
||||
//throw new IllegalStateException("incorrect call sequence");
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -81,38 +51,14 @@ public class JvmMethodSignature {
|
||||
}
|
||||
|
||||
public String getGenericsSignature() {
|
||||
checkGenericsAvailable();
|
||||
return genericsSignature;
|
||||
}
|
||||
|
||||
public String getKotlinTypeParameter() {
|
||||
checkGenericsAvailable();
|
||||
return kotlinTypeParameter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JvmMethodParameterSignature> getKotlinParameterTypes() {
|
||||
checkGenericsAvailable();
|
||||
return kotlinParameterTypes;
|
||||
}
|
||||
|
||||
public int getParameterCount() {
|
||||
// TODO: slow
|
||||
return asmMethod.getArgumentTypes().length;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getKotlinParameterType(int i) {
|
||||
checkGenericsAvailable();
|
||||
return kotlinParameterTypes.get(i).getKotlinSignature();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getKotlinReturnType() {
|
||||
checkGenericsAvailable();
|
||||
return kotlinReturnType;
|
||||
}
|
||||
|
||||
public List<Type> getValueParameterTypes() {
|
||||
List<Type> r = new ArrayList<Type>(kotlinParameterTypes.size());
|
||||
for (JvmMethodParameterSignature p : kotlinParameterTypes) {
|
||||
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.jet.codegen.signature;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.asm4.commons.Method;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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 String getPropertyTypeKotlinSignature() {
|
||||
return isGetter ? getKotlinReturnType() : getKotlinParameterType(getParameterCount() - 1);
|
||||
}
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.jet.codegen.signature.kotlin;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.asm4.AnnotationVisitor;
|
||||
import org.jetbrains.asm4.MethodVisitor;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
|
||||
public class JetMethodAnnotationWriter {
|
||||
private final AnnotationVisitor av;
|
||||
|
||||
private JetMethodAnnotationWriter(AnnotationVisitor av) {
|
||||
this.av = av;
|
||||
}
|
||||
|
||||
public void writeFlags(int flags) {
|
||||
if (flags != JvmStdlibNames.FLAGS_DEFAULT_VALUE) {
|
||||
av.visit(JvmStdlibNames.JET_FLAGS_FIELD, flags);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeTypeParameters(@NotNull String typeParameters) {
|
||||
if (typeParameters.length() > 0) {
|
||||
av.visit(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, typeParameters);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeReturnType(@NotNull String returnType) {
|
||||
if (returnType.length() > 0) {
|
||||
av.visit(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, returnType);
|
||||
}
|
||||
}
|
||||
|
||||
public void writePropertyType(@NotNull String propertyType) {
|
||||
if (propertyType.length() > 0) {
|
||||
av.visit(JvmStdlibNames.JET_METHOD_PROPERTY_TYPE_FIELD, propertyType);
|
||||
}
|
||||
}
|
||||
|
||||
public void visitEnd() {
|
||||
av.visitEnd();
|
||||
}
|
||||
|
||||
public static JetMethodAnnotationWriter visitAnnotation(MethodVisitor mv) {
|
||||
return new JetMethodAnnotationWriter(mv.visitAnnotation(JvmStdlibNames.JET_METHOD.getDescriptor(), true));
|
||||
}
|
||||
}
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.jet.codegen.signature.kotlin;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.asm4.AnnotationVisitor;
|
||||
import org.jetbrains.asm4.MethodVisitor;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
|
||||
public class JetValueParameterAnnotationWriter {
|
||||
private final AnnotationVisitor av;
|
||||
|
||||
private JetValueParameterAnnotationWriter(AnnotationVisitor av) {
|
||||
this.av = av;
|
||||
}
|
||||
|
||||
public void writeName(@NotNull String name) {
|
||||
if (name.length() > 0) {
|
||||
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, name);
|
||||
}
|
||||
}
|
||||
|
||||
public static JetValueParameterAnnotationWriter visitParameterAnnotation(MethodVisitor mv, int n) {
|
||||
return new JetValueParameterAnnotationWriter(
|
||||
mv.visitParameterAnnotation(n, JvmStdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true));
|
||||
}
|
||||
|
||||
public void writeReceiver() {
|
||||
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD, true);
|
||||
}
|
||||
|
||||
public void writeType(@NotNull String kotlinSignature) {
|
||||
if (kotlinSignature.length() > 0) {
|
||||
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, kotlinSignature);
|
||||
}
|
||||
}
|
||||
|
||||
public void visitEnd() {
|
||||
av.visitEnd();
|
||||
}
|
||||
|
||||
public void writeHasDefaultValue(boolean hasDefaultValue) {
|
||||
if (hasDefaultValue) {
|
||||
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeVararg(boolean vararg) {
|
||||
if (vararg) {
|
||||
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_VARARG, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,10 @@ import org.jetbrains.jet.codegen.binding.BindingTraceAware;
|
||||
import org.jetbrains.jet.codegen.binding.CalculatedClosure;
|
||||
import org.jetbrains.jet.codegen.binding.CodegenBinding;
|
||||
import org.jetbrains.jet.codegen.context.EnclosedValueDescriptor;
|
||||
import org.jetbrains.jet.codegen.signature.*;
|
||||
import org.jetbrains.jet.codegen.signature.BothSignatureWriter;
|
||||
import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind;
|
||||
import org.jetbrains.jet.codegen.signature.JvmMethodParameterSignature;
|
||||
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
@@ -775,7 +778,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmPropertyAccessorSignature mapGetterSignature(PropertyDescriptor descriptor, OwnerKind kind) {
|
||||
public JvmMethodSignature mapGetterSignature(PropertyDescriptor descriptor, OwnerKind kind) {
|
||||
// TODO: do not genClassOrObject generics if not needed
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true);
|
||||
|
||||
@@ -791,12 +794,12 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
signatureWriter.writeReturnTypeEnd();
|
||||
|
||||
String name = getPropertyAccessorName(descriptor, true);
|
||||
return signatureWriter.makeJvmPropertyAccessorSignature(name, true);
|
||||
return signatureWriter.makeJvmMethodSignature(name);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public JvmPropertyAccessorSignature mapSetterSignature(PropertyDescriptor descriptor, OwnerKind kind) {
|
||||
public JvmMethodSignature mapSetterSignature(PropertyDescriptor descriptor, OwnerKind kind) {
|
||||
assert descriptor.isVar();
|
||||
|
||||
// TODO: generics signature is not always needed
|
||||
@@ -813,7 +816,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
signatureWriter.writeVoidReturn();
|
||||
|
||||
String name = getPropertyAccessorName(descriptor, false);
|
||||
return signatureWriter.makeJvmPropertyAccessorSignature(name, false);
|
||||
return signatureWriter.makeJvmMethodSignature(name);
|
||||
}
|
||||
|
||||
private void writeParameter(@NotNull BothSignatureWriter signatureWriter, @NotNull JetType outType) {
|
||||
|
||||
@@ -59,7 +59,6 @@ public class JvmStdlibNames {
|
||||
public static final int FLAG_METHOD_KIND_SYNTHESIZED = 3 << 6;
|
||||
|
||||
public static final int FLAG_CLASS_KIND_MASK = 7 << 6;
|
||||
public static final int FLAG_CLASS_KIND_DEFAULT = 0 << 6;
|
||||
public static final int FLAG_CLASS_KIND_OBJECT = 1 << 6;
|
||||
|
||||
public static final JvmClassName JET_CONSTRUCTOR = JvmClassName.byFqNameWithoutInnerClasses("jet.runtime.typeinfo.JetConstructor");
|
||||
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.jet.lang.resolve.java.kt;
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
|
||||
public class DescriptorKindUtils {
|
||||
private DescriptorKindUtils() {
|
||||
}
|
||||
|
||||
public static int kindToFlags(CallableMemberDescriptor.Kind kind) {
|
||||
switch (kind) {
|
||||
case DECLARATION: return JvmStdlibNames.FLAG_METHOD_KIND_DECLARATION;
|
||||
case FAKE_OVERRIDE: return JvmStdlibNames.FLAG_METHOD_KIND_FAKE_OVERRIDE;
|
||||
case DELEGATION: return JvmStdlibNames.FLAG_METHOD_KIND_DELEGATION;
|
||||
case SYNTHESIZED: return JvmStdlibNames.FLAG_METHOD_KIND_SYNTHESIZED;
|
||||
default: throw new IllegalArgumentException("Unknown kind: " + kind);
|
||||
}
|
||||
}
|
||||
|
||||
public static CallableMemberDescriptor.Kind flagsToKind(int value) {
|
||||
switch (value & JvmStdlibNames.FLAG_METHOD_KIND_MASK) {
|
||||
case JvmStdlibNames.FLAG_METHOD_KIND_DECLARATION: return CallableMemberDescriptor.Kind.DECLARATION;
|
||||
case JvmStdlibNames.FLAG_METHOD_KIND_FAKE_OVERRIDE: return CallableMemberDescriptor.Kind.FAKE_OVERRIDE;
|
||||
case JvmStdlibNames.FLAG_METHOD_KIND_DELEGATION: return CallableMemberDescriptor.Kind.DELEGATION;
|
||||
case JvmStdlibNames.FLAG_METHOD_KIND_SYNTHESIZED: return CallableMemberDescriptor.Kind.SYNTHESIZED;
|
||||
default: throw new IllegalArgumentException("Unknown int value of kind: " + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user