enum entries which overrides methods
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
@@ -58,11 +59,16 @@ public class ClassCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (JetDeclaration declaration : aClass.getDeclarations()) {
|
for (JetDeclaration declaration : aClass.getDeclarations()) {
|
||||||
if (declaration instanceof JetClass && !(declaration instanceof JetEnumEntry)) {
|
if (declaration instanceof JetClass) {
|
||||||
|
if (declaration instanceof JetEnumEntry && !state.getInjector().getClosureAnnotator().enumEntryNeedSubclass(
|
||||||
|
(JetEnumEntry) declaration)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
generate(contextForInners, (JetClass) declaration);
|
generate(contextForInners, (JetClass) declaration);
|
||||||
}
|
}
|
||||||
if (declaration instanceof JetClassObject) {
|
if (declaration instanceof JetClassObject) {
|
||||||
generate(contextForInners, ((JetClassObject)declaration).getObjectDeclaration());
|
generate(contextForInners, ((JetClassObject) declaration).getObjectDeclaration());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,15 +79,22 @@ public class ClassCodegen {
|
|||||||
classBuilder.done();
|
classBuilder.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateImplementation(CodegenContext context, JetClassOrObject aClass, OwnerKind kind, HashMap<DeclarationDescriptor, DeclarationDescriptor> accessors, ClassBuilder classBuilder) {
|
private void generateImplementation(
|
||||||
|
CodegenContext context,
|
||||||
|
JetClassOrObject aClass,
|
||||||
|
OwnerKind kind,
|
||||||
|
HashMap<DeclarationDescriptor, DeclarationDescriptor> accessors,
|
||||||
|
ClassBuilder classBuilder
|
||||||
|
) {
|
||||||
ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass);
|
ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass);
|
||||||
CodegenContext classContext = context.intoClass(descriptor, kind, jetTypeMapper);
|
CodegenContext classContext = context.intoClass(descriptor, kind, jetTypeMapper);
|
||||||
classContext.copyAccessors(accessors);
|
classContext.copyAccessors(accessors);
|
||||||
new ImplementationBodyCodegen(aClass, classContext, classBuilder, state).generate();
|
new ImplementationBodyCodegen(aClass, classContext, classBuilder, state).generate();
|
||||||
|
|
||||||
if (aClass instanceof JetClass && ((JetClass)aClass).isTrait()) {
|
if (aClass instanceof JetClass && ((JetClass) aClass).isTrait()) {
|
||||||
ClassBuilder traitBuilder = state.forTraitImplementation(descriptor);
|
ClassBuilder traitBuilder = state.forTraitImplementation(descriptor);
|
||||||
new TraitImplBodyCodegen(aClass, context.intoClass(descriptor, OwnerKind.TRAIT_IMPL, jetTypeMapper), traitBuilder, state).generate();
|
new TraitImplBodyCodegen(aClass, context.intoClass(descriptor, OwnerKind.TRAIT_IMPL, jetTypeMapper), traitBuilder, state)
|
||||||
|
.generate();
|
||||||
traitBuilder.done();
|
traitBuilder.done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ public class ClosureAnnotator {
|
|||||||
|
|
||||||
private BindingContext bindingContext;
|
private BindingContext bindingContext;
|
||||||
private List<JetFile> files;
|
private List<JetFile> files;
|
||||||
|
private final Map<ClassDescriptor, Boolean> enumEntryNeedSubclass = new HashMap<ClassDescriptor, Boolean>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public void setBindingContext(BindingContext bindingContext) {
|
public void setBindingContext(BindingContext bindingContext) {
|
||||||
@@ -229,6 +230,16 @@ public class ClosureAnnotator {
|
|||||||
return other != null;
|
return other != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean enumEntryNeedSubclass(JetEnumEntry enumEntry) {
|
||||||
|
ClassDescriptor descriptor = bindingContext.get(BindingContext.CLASS, enumEntry);
|
||||||
|
return enumEntryNeedSubclass.get(descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean enumEntryNeedSubclass(ClassDescriptor enumEntry) {
|
||||||
|
Boolean aBoolean = enumEntryNeedSubclass.get(enumEntry);
|
||||||
|
return aBoolean != null && aBoolean;
|
||||||
|
}
|
||||||
|
|
||||||
private class MyJetVisitorVoid extends JetVisitorVoid {
|
private class MyJetVisitorVoid extends JetVisitorVoid {
|
||||||
private final LinkedList<ClassDescriptor> classStack = new LinkedList<ClassDescriptor>();
|
private final LinkedList<ClassDescriptor> classStack = new LinkedList<ClassDescriptor>();
|
||||||
private final LinkedList<String> nameStack = new LinkedList<String>();
|
private final LinkedList<String> nameStack = new LinkedList<String>();
|
||||||
@@ -285,6 +296,13 @@ public class ClosureAnnotator {
|
|||||||
nameStack.pop();
|
nameStack.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitEnumEntry(JetEnumEntry enumEntry) {
|
||||||
|
ClassDescriptor descriptor = bindingContext.get(BindingContext.CLASS, enumEntry);
|
||||||
|
enumEntryNeedSubclass.put(descriptor, !enumEntry.getDeclarations().isEmpty());
|
||||||
|
super.visitEnumEntry(enumEntry);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitClassObject(JetClassObject classObject) {
|
public void visitClassObject(JetClassObject classObject) {
|
||||||
JvmClassName name = recordClassObject(classObject);
|
JvmClassName name = recordClassObject(classObject);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class ConstructorFrameMap extends FrameMap {
|
public class ConstructorFrameMap extends FrameMap {
|
||||||
private int myOuterThisIndex = -1;
|
private int myOuterThisIndex = -1;
|
||||||
private int myTypeInfoIndex = -1;
|
private int myTypeInfoIndex = -1;
|
||||||
|
|
||||||
public ConstructorFrameMap(CallableMethod callableMethod, @Nullable ConstructorDescriptor descriptor, boolean hasThis0) {
|
public ConstructorFrameMap(CallableMethod callableMethod, @Nullable ConstructorDescriptor descriptor, boolean hasThis0) {
|
||||||
enterTemp(); // this
|
enterTemp(); // this
|
||||||
@@ -43,14 +43,16 @@ public class ConstructorFrameMap extends FrameMap {
|
|||||||
|
|
||||||
List<Type> explicitArgTypes = callableMethod.getValueParameterTypes();
|
List<Type> explicitArgTypes = callableMethod.getValueParameterTypes();
|
||||||
|
|
||||||
if(descriptor != null && descriptor.getContainingDeclaration().getKind() == ClassKind.ENUM_CLASS) {
|
if (descriptor != null &&
|
||||||
|
(descriptor.getContainingDeclaration().getKind() == ClassKind.ENUM_CLASS ||
|
||||||
|
descriptor.getContainingDeclaration().getKind() == ClassKind.ENUM_ENTRY)) {
|
||||||
enterTemp(); // name
|
enterTemp(); // name
|
||||||
enterTemp(); // ordinal
|
enterTemp(); // ordinal
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ValueParameterDescriptor> paramDescrs = descriptor != null
|
List<ValueParameterDescriptor> paramDescrs = descriptor != null
|
||||||
? descriptor.getValueParameters()
|
? descriptor.getValueParameters()
|
||||||
: Collections.<ValueParameterDescriptor>emptyList();
|
: Collections.<ValueParameterDescriptor>emptyList();
|
||||||
for (int i = 0; i < paramDescrs.size(); i++) {
|
for (int i = 0; i < paramDescrs.size(); i++) {
|
||||||
ValueParameterDescriptor parameter = paramDescrs.get(i);
|
ValueParameterDescriptor parameter = paramDescrs.get(i);
|
||||||
enter(parameter, explicitArgTypes.get(i).getSize());
|
enter(parameter, explicitArgTypes.get(i).getSize());
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -84,8 +84,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
if (myClass instanceof JetClass) {
|
if (myClass instanceof JetClass) {
|
||||||
JetClass jetClass = (JetClass) myClass;
|
JetClass jetClass = (JetClass) myClass;
|
||||||
if (jetClass.hasModifier(JetTokens.ABSTRACT_KEYWORD))
|
if (jetClass.hasModifier(JetTokens.ABSTRACT_KEYWORD)) {
|
||||||
isAbstract = true;
|
isAbstract = true;
|
||||||
|
}
|
||||||
if (jetClass.isTrait()) {
|
if (jetClass.isTrait()) {
|
||||||
isAbstract = true;
|
isAbstract = true;
|
||||||
isInterface = true;
|
isInterface = true;
|
||||||
@@ -132,7 +133,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
access |= ACC_ENUM;
|
access |= ACC_ENUM;
|
||||||
}
|
}
|
||||||
v.defineClass(myClass, V1_6,
|
v.defineClass(myClass, V1_6,
|
||||||
access,
|
access,
|
||||||
signature.getName(),
|
signature.getName(),
|
||||||
signature.getJavaGenericSignature(),
|
signature.getJavaGenericSignature(),
|
||||||
signature.getSuperclassName(),
|
signature.getSuperclassName(),
|
||||||
@@ -170,7 +171,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
if (descriptor.getClassObjectDescriptor() != null) {
|
if (descriptor.getClassObjectDescriptor() != null) {
|
||||||
int innerClassAccess = ACC_PUBLIC | ACC_FINAL | ACC_STATIC;
|
int innerClassAccess = ACC_PUBLIC | ACC_FINAL | ACC_STATIC;
|
||||||
String outerClassInernalName = typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.IMPL).getInternalName();
|
String outerClassInernalName = typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.IMPL).getInternalName();
|
||||||
v.visitInnerClass(outerClassInernalName + JvmAbi.CLASS_OBJECT_SUFFIX, outerClassInernalName, JvmAbi.CLASS_OBJECT_CLASS_NAME, innerClassAccess);
|
v.visitInnerClass(outerClassInernalName + JvmAbi.CLASS_OBJECT_SUFFIX, outerClassInernalName, JvmAbi.CLASS_OBJECT_CLASS_NAME,
|
||||||
|
innerClassAccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
AnnotationCodegen.forClass(v.getVisitor(), typeMapper).genAnnotations(descriptor);
|
AnnotationCodegen.forClass(v.getVisitor(), typeMapper).genAnnotations(descriptor);
|
||||||
@@ -245,7 +247,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
signatureVisitor.writeSupersEnd();
|
signatureVisitor.writeSupersEnd();
|
||||||
|
|
||||||
return new JvmClassSignature(jvmName(), superClass, superInterfaces, signatureVisitor.makeJavaString(), signatureVisitor.makeKotlinClassSignature());
|
return new JvmClassSignature(jvmName(), superClass, superInterfaces, signatureVisitor.makeJavaString(),
|
||||||
|
signatureVisitor.makeKotlinClassSignature());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String jvmName() {
|
private String jvmName() {
|
||||||
@@ -261,8 +264,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
List<JetDelegationSpecifier> delegationSpecifiers = myClass.getDelegationSpecifiers();
|
List<JetDelegationSpecifier> delegationSpecifiers = myClass.getDelegationSpecifiers();
|
||||||
|
|
||||||
if (myClass instanceof JetClass && ((JetClass) myClass).isTrait())
|
if (myClass instanceof JetClass && ((JetClass) myClass).isTrait()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (kind != OwnerKind.IMPLEMENTATION) {
|
if (kind != OwnerKind.IMPLEMENTATION) {
|
||||||
throw new IllegalStateException("must be impl to reach this code: " + kind);
|
throw new IllegalStateException("must be impl to reach this code: " + kind);
|
||||||
@@ -281,10 +285,14 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(superClassType == null) {
|
if (superClassType == null) {
|
||||||
if (myClass instanceof JetClass && ((JetClass) myClass).hasModifier(JetTokens.ENUM_KEYWORD)) {
|
if (descriptor.getKind() == ClassKind.ENUM_CLASS) {
|
||||||
superClassType = JetStandardLibrary.getInstance().getEnumType(descriptor.getDefaultType());
|
superClassType = JetStandardLibrary.getInstance().getEnumType(descriptor.getDefaultType());
|
||||||
superClass = typeMapper.mapType(superClassType,MapTypeMode.VALUE).getInternalName();
|
superClass = typeMapper.mapType(superClassType, MapTypeMode.VALUE).getInternalName();
|
||||||
|
}
|
||||||
|
if (descriptor.getKind() == ClassKind.ENUM_ENTRY) {
|
||||||
|
superClassType = descriptor.getTypeConstructor().getSupertypes().iterator().next();
|
||||||
|
superClass = typeMapper.mapType(superClassType, MapTypeMode.VALUE).getInternalName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -300,10 +308,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
catch (CompilationException e) {
|
catch (CompilationException e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
catch(ProcessCanceledException e) {
|
catch (ProcessCanceledException e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
catch(RuntimeException e) {
|
catch (RuntimeException e) {
|
||||||
throw new RuntimeException("Error generating primary constructor of class " + myClass.getName() + " with kind " + kind, e);
|
throw new RuntimeException("Error generating primary constructor of class " + myClass.getName() + " with kind " + kind, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,18 +323,20 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void generateEnumMethods() {
|
private void generateEnumMethods() {
|
||||||
if(myEnumConstants.size() > 0) {
|
if (myEnumConstants.size() > 0) {
|
||||||
{
|
{
|
||||||
Type type = typeMapper.mapType(JetStandardLibrary.getInstance().getArrayType(descriptor.getDefaultType()), MapTypeMode.IMPL);
|
Type type =
|
||||||
|
typeMapper.mapType(JetStandardLibrary.getInstance().getArrayType(descriptor.getDefaultType()), MapTypeMode.IMPL);
|
||||||
|
|
||||||
MethodVisitor mv =
|
MethodVisitor mv =
|
||||||
v.newMethod(myClass, ACC_PUBLIC | ACC_STATIC, "values", "()" + type.getDescriptor(), null, null);
|
v.newMethod(myClass, ACC_PUBLIC | ACC_STATIC, "values", "()" + type.getDescriptor(), null, null);
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
mv.visitFieldInsn(GETSTATIC, typeMapper.mapType(descriptor.getDefaultType(),MapTypeMode.VALUE).getInternalName(), VALUES, type.getDescriptor());
|
mv.visitFieldInsn(GETSTATIC, typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.VALUE).getInternalName(), VALUES,
|
||||||
|
type.getDescriptor());
|
||||||
mv.visitMethodInsn(INVOKEVIRTUAL, type.getInternalName(), "clone", "()Ljava/lang/Object;");
|
mv.visitMethodInsn(INVOKEVIRTUAL, type.getInternalName(), "clone", "()Ljava/lang/Object;");
|
||||||
mv.visitTypeInsn(CHECKCAST, type.getInternalName());
|
mv.visitTypeInsn(CHECKCAST, type.getInternalName());
|
||||||
mv.visitInsn(ARETURN);
|
mv.visitInsn(ARETURN);
|
||||||
FunctionCodegen.endVisit(mv,"values()",myClass);
|
FunctionCodegen.endVisit(mv, "values()", myClass);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Type type = typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.IMPL);
|
Type type = typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.IMPL);
|
||||||
@@ -339,7 +349,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Enum", "valueOf", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;");
|
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Enum", "valueOf", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;");
|
||||||
mv.visitTypeInsn(CHECKCAST, type.getInternalName());
|
mv.visitTypeInsn(CHECKCAST, type.getInternalName());
|
||||||
mv.visitInsn(ARETURN);
|
mv.visitInsn(ARETURN);
|
||||||
FunctionCodegen.endVisit(mv,"values()",myClass);
|
FunctionCodegen.endVisit(mv, "values()", myClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -393,10 +403,12 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
Method method = typeMapper.mapGetterSignature(bridge, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
Method method = typeMapper.mapGetterSignature(bridge, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||||
JvmPropertyAccessorSignature originalSignature = typeMapper.mapGetterSignature(original, OwnerKind.IMPLEMENTATION);
|
JvmPropertyAccessorSignature originalSignature = typeMapper.mapGetterSignature(original, OwnerKind.IMPLEMENTATION);
|
||||||
Method originalMethod = originalSignature.getJvmMethodSignature().getAsmMethod();
|
Method originalMethod = originalSignature.getJvmMethodSignature().getAsmMethod();
|
||||||
MethodVisitor mv = v.newMethod(null, ACC_BRIDGE | ACC_SYNTHETIC | ACC_STATIC, method.getName(), method.getDescriptor(), null, null);
|
MethodVisitor mv =
|
||||||
|
v.newMethod(null, ACC_BRIDGE | ACC_SYNTHETIC | ACC_STATIC, method.getName(), method.getDescriptor(), null, null);
|
||||||
PropertyCodegen.generateJetPropertyAnnotation(mv, originalSignature.getPropertyTypeKotlinSignature(),
|
PropertyCodegen.generateJetPropertyAnnotation(mv, originalSignature.getPropertyTypeKotlinSignature(),
|
||||||
originalSignature.getJvmMethodSignature().getKotlinTypeParameter(),
|
originalSignature.getJvmMethodSignature().getKotlinTypeParameter(),
|
||||||
original, ((PropertyDescriptor) entry.getValue()).getGetter().getVisibility());
|
original,
|
||||||
|
((PropertyDescriptor) entry.getValue()).getGetter().getVisibility());
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
||||||
StubCodegen.generateStubCode(mv);
|
StubCodegen.generateStubCode(mv);
|
||||||
}
|
}
|
||||||
@@ -406,25 +418,30 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||||
|
|
||||||
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||||
if (original.getVisibility() == Visibilities.PRIVATE)
|
if (original.getVisibility() == Visibilities.PRIVATE) {
|
||||||
iv.getfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), original.getName().getName(), originalMethod.getReturnType().getDescriptor());
|
iv.getfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), original.getName().getName(),
|
||||||
else
|
originalMethod.getReturnType().getDescriptor());
|
||||||
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), originalMethod.getName(), originalMethod.getDescriptor());
|
}
|
||||||
|
else {
|
||||||
|
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(),
|
||||||
|
originalMethod.getName(), originalMethod.getDescriptor());
|
||||||
|
}
|
||||||
|
|
||||||
iv.areturn(method.getReturnType());
|
iv.areturn(method.getReturnType());
|
||||||
FunctionCodegen.endVisit(iv, "accessor", null);
|
FunctionCodegen.endVisit(iv, "accessor", null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bridge.isVar())
|
if (bridge.isVar()) {
|
||||||
{
|
|
||||||
Method method = typeMapper.mapSetterSignature(bridge, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
Method method = typeMapper.mapSetterSignature(bridge, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||||
JvmPropertyAccessorSignature originalSignature2 = typeMapper.mapSetterSignature(original, OwnerKind.IMPLEMENTATION);
|
JvmPropertyAccessorSignature originalSignature2 = typeMapper.mapSetterSignature(original, OwnerKind.IMPLEMENTATION);
|
||||||
Method originalMethod = originalSignature2.getJvmMethodSignature().getAsmMethod();
|
Method originalMethod = originalSignature2.getJvmMethodSignature().getAsmMethod();
|
||||||
MethodVisitor mv = v.newMethod(null, ACC_STATIC | ACC_BRIDGE | ACC_FINAL, method.getName(), method.getDescriptor(), null, null);
|
MethodVisitor mv =
|
||||||
|
v.newMethod(null, ACC_STATIC | ACC_BRIDGE | ACC_FINAL, method.getName(), method.getDescriptor(), null, null);
|
||||||
PropertyCodegen.generateJetPropertyAnnotation(mv, originalSignature2.getPropertyTypeKotlinSignature(),
|
PropertyCodegen.generateJetPropertyAnnotation(mv, originalSignature2.getPropertyTypeKotlinSignature(),
|
||||||
originalSignature2.getJvmMethodSignature().getKotlinTypeParameter(),
|
originalSignature2.getJvmMethodSignature().getKotlinTypeParameter(),
|
||||||
original, ((PropertyDescriptor) entry.getValue()).getSetter().getVisibility());
|
original,
|
||||||
|
((PropertyDescriptor) entry.getValue()).getSetter().getVisibility());
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
||||||
StubCodegen.generateStubCode(mv);
|
StubCodegen.generateStubCode(mv);
|
||||||
}
|
}
|
||||||
@@ -441,10 +458,14 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
//noinspection AssignmentToForLoopParameter
|
//noinspection AssignmentToForLoopParameter
|
||||||
reg += argType.getSize();
|
reg += argType.getSize();
|
||||||
}
|
}
|
||||||
if (original.getVisibility() == Visibilities.PRIVATE && original.getModality() == Modality.FINAL)
|
if (original.getVisibility() == Visibilities.PRIVATE && original.getModality() == Modality.FINAL) {
|
||||||
iv.putfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), original.getName().getName(), originalMethod.getArgumentTypes()[0].getDescriptor());
|
iv.putfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), original.getName().getName(),
|
||||||
else
|
originalMethod.getArgumentTypes()[0].getDescriptor());
|
||||||
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), originalMethod.getName(), originalMethod.getDescriptor());
|
}
|
||||||
|
else {
|
||||||
|
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(),
|
||||||
|
originalMethod.getName(), originalMethod.getDescriptor());
|
||||||
|
}
|
||||||
|
|
||||||
iv.areturn(method.getReturnType());
|
iv.areturn(method.getReturnType());
|
||||||
FunctionCodegen.endVisit(iv, "accessor", null);
|
FunctionCodegen.endVisit(iv, "accessor", null);
|
||||||
@@ -471,7 +492,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
v.putstatic(name, "$instance", typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.VALUE).getDescriptor());
|
v.putstatic(name, "$instance", typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.VALUE).getDescriptor());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,9 +520,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
protected void generatePrimaryConstructor() {
|
protected void generatePrimaryConstructor() {
|
||||||
if (myClass instanceof JetClass) {
|
if (myClass instanceof JetClass) {
|
||||||
JetClass aClass = (JetClass)myClass;
|
JetClass aClass = (JetClass) myClass;
|
||||||
if (aClass.isTrait())
|
if (aClass.isTrait()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
if (aClass.isAnnotation()) {
|
if (aClass.isAnnotation()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -529,7 +550,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
if (hasThis0) {
|
if (hasThis0) {
|
||||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS0);
|
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS0);
|
||||||
typeMapper.mapType(typeMapper.getClosureAnnotator().getEclosingClassDescriptor(descriptor).getDefaultType(), signatureWriter, MapTypeMode.VALUE);
|
typeMapper
|
||||||
|
.mapType(typeMapper.getClosureAnnotator().getEclosingClassDescriptor(descriptor).getDefaultType(), signatureWriter,
|
||||||
|
MapTypeMode.VALUE);
|
||||||
signatureWriter.writeParameterTypeEnd();
|
signatureWriter.writeParameterTypeEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -538,10 +561,13 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
signatureWriter.writeVoidReturn();
|
signatureWriter.writeVoidReturn();
|
||||||
|
|
||||||
constructorMethod = signatureWriter.makeJvmMethodSignature("<init>");
|
constructorMethod = signatureWriter.makeJvmMethodSignature("<init>");
|
||||||
callableMethod = new CallableMethod(JvmClassName.byInternalName("Ignored"), null, null, constructorMethod, INVOKESPECIAL, null, null, null);
|
callableMethod =
|
||||||
|
new CallableMethod(JvmClassName.byInternalName("Ignored"), null, null, constructorMethod, INVOKESPECIAL, null, null,
|
||||||
|
null);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor, kind, typeMapper.hasThis0(constructorDescriptor.getContainingDeclaration()));
|
callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor, kind,
|
||||||
|
typeMapper.hasThis0(constructorDescriptor.getContainingDeclaration()));
|
||||||
constructorMethod = callableMethod.getSignature();
|
constructorMethod = callableMethod.getSignature();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,22 +592,28 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
ObjectOrClosureCodegen closure = context.closure;
|
ObjectOrClosureCodegen closure = context.closure;
|
||||||
int firstSuperArgument = -1;
|
int firstSuperArgument = -1;
|
||||||
final LinkedList<JvmMethodParameterSignature> consArgTypes = new LinkedList<JvmMethodParameterSignature>(constructorMethod.getKotlinParameterTypes());
|
final LinkedList<JvmMethodParameterSignature> consArgTypes =
|
||||||
|
new LinkedList<JvmMethodParameterSignature>(constructorMethod.getKotlinParameterTypes());
|
||||||
|
|
||||||
int insert = 0;
|
int insert = 0;
|
||||||
if (closure != null) {
|
if (closure != null) {
|
||||||
if (closure.captureThis != null) {
|
if (closure.captureThis != null) {
|
||||||
if (!hasThis0)
|
if (!hasThis0) {
|
||||||
consArgTypes.add(insert, new JvmMethodParameterSignature(Type.getObjectType(context.getThisDescriptor().getName().getName()), "", JvmMethodParameterKind.THIS0));
|
consArgTypes.add(insert,
|
||||||
|
new JvmMethodParameterSignature(Type.getObjectType(context.getThisDescriptor().getName().getName()),
|
||||||
|
"", JvmMethodParameterKind.THIS0));
|
||||||
|
}
|
||||||
insert++;
|
insert++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (hasThis0)
|
if (hasThis0) {
|
||||||
insert++;
|
insert++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closure.captureReceiver != null)
|
if (closure.captureReceiver != null) {
|
||||||
consArgTypes.add(insert++, new JvmMethodParameterSignature(closure.captureReceiver, "", JvmMethodParameterKind.RECEIVER));
|
consArgTypes.add(insert++, new JvmMethodParameterSignature(closure.captureReceiver, "", JvmMethodParameterKind.RECEIVER));
|
||||||
|
}
|
||||||
|
|
||||||
for (DeclarationDescriptor descriptor : closure.closure.keySet()) {
|
for (DeclarationDescriptor descriptor : closure.closure.keySet()) {
|
||||||
if (descriptor instanceof VariableDescriptor && !(descriptor instanceof PropertyDescriptor)) {
|
if (descriptor instanceof VariableDescriptor && !(descriptor instanceof PropertyDescriptor)) {
|
||||||
@@ -591,7 +623,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
type = sharedVarType;
|
type = sharedVarType;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
type = state.getInjector().getJetTypeMapper().mapType(((VariableDescriptor) descriptor).getType(), MapTypeMode.VALUE);
|
type = state.getInjector().getJetTypeMapper()
|
||||||
|
.mapType(((VariableDescriptor) descriptor).getType(), MapTypeMode.VALUE);
|
||||||
}
|
}
|
||||||
consArgTypes.add(insert++, new JvmMethodParameterSignature(type, "", JvmMethodParameterKind.SHARED_VAR));
|
consArgTypes.add(insert++, new JvmMethodParameterSignature(type, "", JvmMethodParameterKind.SHARED_VAR));
|
||||||
}
|
}
|
||||||
@@ -603,16 +636,20 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
if (myClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) myClass).isObjectLiteral()) {
|
if (myClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) myClass).isObjectLiteral()) {
|
||||||
if (superCall instanceof JetDelegatorToSuperCall) {
|
if (superCall instanceof JetDelegatorToSuperCall) {
|
||||||
if (closure != null)
|
if (closure != null) {
|
||||||
closure.superCall = (JetDelegatorToSuperCall) superCall;
|
closure.superCall = (JetDelegatorToSuperCall) superCall;
|
||||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, ((JetDelegatorToSuperCall) superCall).getCalleeExpression().getConstructorReferenceExpression());
|
}
|
||||||
|
DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET,
|
||||||
|
((JetDelegatorToSuperCall) superCall).getCalleeExpression()
|
||||||
|
.getConstructorReferenceExpression());
|
||||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||||
declarationDescriptor = ((ClassDescriptorFromSource) declarationDescriptor).getUnsubstitutedPrimaryConstructor();
|
declarationDescriptor = ((ClassDescriptorFromSource) declarationDescriptor).getUnsubstitutedPrimaryConstructor();
|
||||||
}
|
}
|
||||||
ConstructorDescriptor superConstructor = (ConstructorDescriptor) declarationDescriptor;
|
ConstructorDescriptor superConstructor = (ConstructorDescriptor) declarationDescriptor;
|
||||||
CallableMethod superCallable = typeMapper.mapToCallableMethod(superConstructor, OwnerKind.IMPLEMENTATION, typeMapper.hasThis0(superConstructor.getContainingDeclaration()));
|
CallableMethod superCallable = typeMapper.mapToCallableMethod(superConstructor, OwnerKind.IMPLEMENTATION, typeMapper
|
||||||
|
.hasThis0(superConstructor.getContainingDeclaration()));
|
||||||
firstSuperArgument = insert;
|
firstSuperArgument = insert;
|
||||||
for(Type t : superCallable.getSignature().getAsmMethod().getArgumentTypes()) {
|
for (Type t : superCallable.getSignature().getAsmMethod().getArgumentTypes()) {
|
||||||
consArgTypes.add(insert++, new JvmMethodParameterSignature(t, "", JvmMethodParameterKind.SHARED_VAR));
|
consArgTypes.add(insert++, new JvmMethodParameterSignature(t, "", JvmMethodParameterKind.SHARED_VAR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -621,7 +658,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int flags = JetTypeMapper.getAccessModifiers(constructorDescriptor, 0);
|
int flags = JetTypeMapper.getAccessModifiers(constructorDescriptor, 0);
|
||||||
final MethodVisitor mv = v.newMethod(myClass, flags, constructorMethod.getName(), constructorMethod.getAsmMethod().getDescriptor(), constructorMethod.getGenericsSignature(), null);
|
final MethodVisitor mv = v.newMethod(myClass, flags, constructorMethod.getName(), constructorMethod.getAsmMethod().getDescriptor(),
|
||||||
|
constructorMethod.getGenericsSignature(), null);
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.SIGNATURES) return;
|
if (state.getClassBuilderMode() == ClassBuilderMode.SIGNATURES) return;
|
||||||
|
|
||||||
AnnotationVisitor jetConstructorVisitor = mv.visitAnnotation(JvmStdlibNames.JET_CONSTRUCTOR.getDescriptor(), true);
|
AnnotationVisitor jetConstructorVisitor = mv.visitAnnotation(JvmStdlibNames.JET_CONSTRUCTOR.getDescriptor(), true);
|
||||||
@@ -642,13 +680,14 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(myClass instanceof JetClass && ((JetClass)myClass).hasModifier(JetTokens.ENUM_KEYWORD)) {
|
if (descriptor.getKind() == ClassKind.ENUM_CLASS || descriptor.getKind() == ClassKind.ENUM_ENTRY) {
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ValueParameterDescriptor valueParameter : constructorDescriptor.getValueParameters()) {
|
for (ValueParameterDescriptor valueParameter : constructorDescriptor.getValueParameters()) {
|
||||||
AnnotationCodegen.forParameter(i, mv, state.getInjector().getJetTypeMapper()).genAnnotations(valueParameter);
|
AnnotationCodegen.forParameter(i, mv, state.getInjector().getJetTypeMapper()).genAnnotations(valueParameter);
|
||||||
JetValueParameterAnnotationWriter jetValueParameterAnnotation = JetValueParameterAnnotationWriter.visitParameterAnnotation(mv, i);
|
JetValueParameterAnnotationWriter jetValueParameterAnnotation =
|
||||||
|
JetValueParameterAnnotationWriter.visitParameterAnnotation(mv, i);
|
||||||
jetValueParameterAnnotation.writeName(valueParameter.getName().getName());
|
jetValueParameterAnnotation.writeName(valueParameter.getName().getName());
|
||||||
jetValueParameterAnnotation.writeHasDefaultValue(valueParameter.declaresDefaultValue());
|
jetValueParameterAnnotation.writeHasDefaultValue(valueParameter.declaresDefaultValue());
|
||||||
jetValueParameterAnnotation.writeType(constructorMethod.getKotlinParameterType(i));
|
jetValueParameterAnnotation.writeType(constructorMethod.getKotlinParameterType(i));
|
||||||
@@ -665,20 +704,20 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
|
|
||||||
List<ValueParameterDescriptor> paramDescrs = constructorDescriptor != null
|
List<ValueParameterDescriptor> paramDescrs = constructorDescriptor != null
|
||||||
? constructorDescriptor.getValueParameters()
|
? constructorDescriptor.getValueParameters()
|
||||||
: Collections.<ValueParameterDescriptor>emptyList();
|
: Collections.<ValueParameterDescriptor>emptyList();
|
||||||
|
|
||||||
ConstructorFrameMap frameMap = new ConstructorFrameMap(callableMethod, constructorDescriptor, hasThis0);
|
ConstructorFrameMap frameMap = new ConstructorFrameMap(callableMethod, constructorDescriptor, hasThis0);
|
||||||
|
|
||||||
final InstructionAdapter iv = new InstructionAdapter(mv);
|
final InstructionAdapter iv = new InstructionAdapter(mv);
|
||||||
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, constructorContext, state);
|
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, constructorContext, state);
|
||||||
|
|
||||||
// for(int slot = 0; slot != frameMap.getTypeParameterCount(); ++slot) {
|
// for(int slot = 0; slot != frameMap.getTypeParameterCount(); ++slot) {
|
||||||
// if (constructorDescriptor != null)
|
// if (constructorDescriptor != null)
|
||||||
// codegen.addTypeParameter(constructorDescriptor.getTypeParameters().get(slot), StackValue.local(frameMap.getFirstTypeParameter() + slot, JetTypeMapper.TYPE_TYPEINFO));
|
// codegen.addTypeParameter(constructorDescriptor.getTypeParameters().get(slot), StackValue.local(frameMap.getFirstTypeParameter() + slot, JetTypeMapper.TYPE_TYPEINFO));
|
||||||
// else
|
// else
|
||||||
// codegen.addTypeParameter(descriptor.getTypeConstructor().getParameters().get(slot), StackValue.local(frameMap.getFirstTypeParameter() + slot, JetTypeMapper.TYPE_TYPEINFO));
|
// codegen.addTypeParameter(descriptor.getTypeConstructor().getParameters().get(slot), StackValue.local(frameMap.getFirstTypeParameter() + slot, JetTypeMapper.TYPE_TYPEINFO));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
Type classType = typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.IMPL);
|
Type classType = typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.IMPL);
|
||||||
JvmClassName classname = JvmClassName.byType(classType);
|
JvmClassName classname = JvmClassName.byType(classType);
|
||||||
@@ -694,7 +733,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
if (superCall == null) {
|
if (superCall == null) {
|
||||||
iv.load(0, Type.getType("L" + superClass + ";"));
|
iv.load(0, Type.getType("L" + superClass + ";"));
|
||||||
if(descriptor.getKind() == ClassKind.ENUM_CLASS) {
|
if (descriptor.getKind() == ClassKind.ENUM_CLASS || descriptor.getKind() == ClassKind.ENUM_ENTRY) {
|
||||||
iv.load(1, JetTypeMapper.JL_STRING_TYPE);
|
iv.load(1, JetTypeMapper.JL_STRING_TYPE);
|
||||||
iv.load(2, Type.INT_TYPE);
|
iv.load(2, Type.INT_TYPE);
|
||||||
iv.invokespecial(superClass, "<init>", "(Ljava/lang/String;I)V");
|
iv.invokespecial(superClass, "<init>", "(Ljava/lang/String;I)V");
|
||||||
@@ -711,14 +750,20 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor();
|
ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor();
|
||||||
if (typeMapper.hasThis0(superClassDescriptor)) {
|
if (typeMapper.hasThis0(superClassDescriptor)) {
|
||||||
iv.load(1, JetTypeMapper.TYPE_OBJECT);
|
iv.load(1, JetTypeMapper.TYPE_OBJECT);
|
||||||
parameterTypes.add(typeMapper.mapType(typeMapper.getClosureAnnotator().getEclosingClassDescriptor(descriptor).getDefaultType(), MapTypeMode.VALUE));
|
parameterTypes.add(typeMapper.mapType(
|
||||||
|
typeMapper.getClosureAnnotator().getEclosingClassDescriptor(descriptor).getDefaultType(), MapTypeMode.VALUE));
|
||||||
}
|
}
|
||||||
Method superCallMethod = new Method("<init>", Type.VOID_TYPE, parameterTypes.toArray(new Type[parameterTypes.size()]));
|
Method superCallMethod = new Method("<init>", Type.VOID_TYPE, parameterTypes.toArray(new Type[parameterTypes.size()]));
|
||||||
iv.invokespecial(typeMapper.mapType(superClassDescriptor.getDefaultType(), MapTypeMode.VALUE).getInternalName(), "<init>", superCallMethod.getDescriptor());
|
iv.invokespecial(typeMapper.mapType(superClassDescriptor.getDefaultType(), MapTypeMode.VALUE).getInternalName(), "<init>",
|
||||||
|
superCallMethod.getDescriptor());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ConstructorDescriptor constructorDescriptor1 = (ConstructorDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET, ((JetDelegatorToSuperCall) superCall).getCalleeExpression().getConstructorReferenceExpression());
|
ConstructorDescriptor constructorDescriptor1 = (ConstructorDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET,
|
||||||
generateDelegatorToConstructorCall(iv, codegen, (JetDelegatorToSuperCall) superCall, constructorDescriptor1, frameMap, firstSuperArgument);
|
((JetDelegatorToSuperCall) superCall)
|
||||||
|
.getCalleeExpression()
|
||||||
|
.getConstructorReferenceExpression());
|
||||||
|
generateDelegatorToConstructorCall(iv, codegen, (JetDelegatorToSuperCall) superCall, constructorDescriptor1, frameMap,
|
||||||
|
firstSuperArgument);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ClassDescriptor outerDescriptor = typeMapper.getClosureAnnotator().getEclosingClassDescriptor(descriptor);
|
final ClassDescriptor outerDescriptor = typeMapper.getClosureAnnotator().getEclosingClassDescriptor(descriptor);
|
||||||
@@ -738,7 +783,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
if (closure.captureReceiver != null) {
|
if (closure.captureReceiver != null) {
|
||||||
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||||
iv.load(1, closure.captureReceiver);
|
iv.load(1, closure.captureReceiver);
|
||||||
iv.putfield(typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.VALUE).getInternalName(), "receiver$0", closure.captureReceiver.getDescriptor());
|
iv.putfield(typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.VALUE).getInternalName(), "receiver$0",
|
||||||
|
closure.captureReceiver.getDescriptor());
|
||||||
k += closure.captureReceiver.getSize();
|
k += closure.captureReceiver.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -752,7 +798,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||||
iv.load(k, StackValue.refType(sharedVarType));
|
iv.load(k, StackValue.refType(sharedVarType));
|
||||||
k += StackValue.refType(sharedVarType).getSize();
|
k += StackValue.refType(sharedVarType).getSize();
|
||||||
iv.putfield(typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.VALUE).getInternalName(), "$" + varDescr.getName(), sharedVarType.getDescriptor());
|
iv.putfield(typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.VALUE).getInternalName(),
|
||||||
|
"$" + varDescr.getName(), sharedVarType.getDescriptor());
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -760,8 +807,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (JetDelegationSpecifier specifier : myClass.getDelegationSpecifiers()) {
|
for (JetDelegationSpecifier specifier : myClass.getDelegationSpecifiers()) {
|
||||||
if (specifier == superCall)
|
if (specifier == superCall) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (specifier instanceof JetDelegatorByExpressionSpecifier) {
|
if (specifier instanceof JetDelegatorByExpressionSpecifier) {
|
||||||
iv.load(0, classType);
|
iv.load(0, classType);
|
||||||
@@ -779,8 +827,13 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
JetClass superClass = (JetClass) BindingContextUtils.classDescriptorToDeclaration(bindingContext, superClassDescriptor);
|
JetClass superClass = (JetClass) BindingContextUtils.classDescriptorToDeclaration(bindingContext, superClassDescriptor);
|
||||||
final CodegenContext delegateContext = context.intoClass(superClassDescriptor,
|
final CodegenContext delegateContext = context.intoClass(superClassDescriptor,
|
||||||
new OwnerKind.DelegateKind(StackValue.field(fieldType, classname, delegateField, false),
|
new OwnerKind.DelegateKind(StackValue.field(fieldType, classname,
|
||||||
typeMapper.mapType(superClassDescriptor.getDefaultType(), MapTypeMode.IMPL).getInternalName()), state.getInjector().getJetTypeMapper());
|
delegateField, false),
|
||||||
|
typeMapper.mapType(superClassDescriptor
|
||||||
|
.getDefaultType(),
|
||||||
|
MapTypeMode.IMPL)
|
||||||
|
.getInternalName()),
|
||||||
|
state.getInjector().getJetTypeMapper());
|
||||||
generateDelegates(superClass, delegateContext, field);
|
generateDelegates(superClass, delegateContext, field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -803,12 +856,15 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
mv.visitInsn(RETURN);
|
mv.visitInsn(RETURN);
|
||||||
FunctionCodegen.endVisit(mv, "constructor", myClass);
|
FunctionCodegen.endVisit(mv, "constructor", myClass);
|
||||||
|
|
||||||
FunctionCodegen.generateDefaultIfNeeded(constructorContext, state, v, constructorMethod.getAsmMethod(), constructorDescriptor, OwnerKind.IMPLEMENTATION);
|
FunctionCodegen.generateDefaultIfNeeded(constructorContext, state, v, constructorMethod.getAsmMethod(), constructorDescriptor,
|
||||||
|
OwnerKind.IMPLEMENTATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateTraitMethods() {
|
private void generateTraitMethods() {
|
||||||
if (myClass instanceof JetClass && (((JetClass)myClass).isTrait() || ((JetClass)myClass).hasModifier(JetTokens.ABSTRACT_KEYWORD)))
|
if (myClass instanceof JetClass &&
|
||||||
|
(((JetClass) myClass).isTrait() || ((JetClass) myClass).hasModifier(JetTokens.ABSTRACT_KEYWORD))) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (Pair<CallableMemberDescriptor, CallableMemberDescriptor> needDelegates : getTraitImplementations(descriptor)) {
|
for (Pair<CallableMemberDescriptor, CallableMemberDescriptor> needDelegates : getTraitImplementations(descriptor)) {
|
||||||
CallableMemberDescriptor callableDescriptor = needDelegates.first;
|
CallableMemberDescriptor callableDescriptor = needDelegates.first;
|
||||||
@@ -843,11 +899,15 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
PropertyDescriptor property = ((PropertyAccessorDescriptor) fun).getCorrespondingProperty();
|
PropertyDescriptor property = ((PropertyAccessorDescriptor) fun).getCorrespondingProperty();
|
||||||
if (fun instanceof PropertyGetterDescriptor) {
|
if (fun instanceof PropertyGetterDescriptor) {
|
||||||
function = typeMapper.mapGetterSignature(property, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
function = typeMapper.mapGetterSignature(property, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||||
functionOriginal = typeMapper.mapGetterSignature(property.getOriginal(), OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
functionOriginal =
|
||||||
|
typeMapper.mapGetterSignature(property.getOriginal(), OwnerKind.IMPLEMENTATION).getJvmMethodSignature()
|
||||||
|
.getAsmMethod();
|
||||||
}
|
}
|
||||||
else if (fun instanceof PropertySetterDescriptor) {
|
else if (fun instanceof PropertySetterDescriptor) {
|
||||||
function = typeMapper.mapSetterSignature(property, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
function = typeMapper.mapSetterSignature(property, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||||
functionOriginal = typeMapper.mapSetterSignature(property.getOriginal(), OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
functionOriginal =
|
||||||
|
typeMapper.mapSetterSignature(property.getOriginal(), OwnerKind.IMPLEMENTATION).getJvmMethodSignature()
|
||||||
|
.getAsmMethod();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalStateException("Accessor is neither getter, nor setter, what is it?");
|
throw new IllegalStateException("Accessor is neither getter, nor setter, what is it?");
|
||||||
@@ -861,14 +921,16 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
final MethodVisitor mv = v.newMethod(myClass, flags, function.getName(), function.getDescriptor(), null, null);
|
final MethodVisitor mv = v.newMethod(myClass, flags, function.getName(), function.getDescriptor(), null, null);
|
||||||
AnnotationCodegen.forMethod(mv, state.getInjector().getJetTypeMapper()).genAnnotations(fun);
|
AnnotationCodegen.forMethod(mv, state.getInjector().getJetTypeMapper()).genAnnotations(fun);
|
||||||
|
|
||||||
JvmMethodSignature jvmSignature = typeMapper.mapToCallableMethod(inheritedFun, false, OwnerKind.IMPLEMENTATION).getSignature();
|
JvmMethodSignature jvmSignature =
|
||||||
|
typeMapper.mapToCallableMethod(inheritedFun, false, OwnerKind.IMPLEMENTATION).getSignature();
|
||||||
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
|
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
|
||||||
BitSet kotlinFlags = CodegenUtil.getFlagsForVisibility(fun.getVisibility());
|
BitSet kotlinFlags = CodegenUtil.getFlagsForVisibility(fun.getVisibility());
|
||||||
if (fun instanceof PropertyAccessorDescriptor) {
|
if (fun instanceof PropertyAccessorDescriptor) {
|
||||||
kotlinFlags.set(JvmStdlibNames.FLAG_PROPERTY_BIT);
|
kotlinFlags.set(JvmStdlibNames.FLAG_PROPERTY_BIT);
|
||||||
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
||||||
aw.writePropertyType(jvmSignature.getKotlinReturnType());
|
aw.writePropertyType(jvmSignature.getKotlinReturnType());
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
aw.writeNullableReturnType(fun.getReturnType().isNullable());
|
aw.writeNullableReturnType(fun.getReturnType().isNullable());
|
||||||
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
||||||
aw.writeReturnType(jvmSignature.getKotlinReturnType());
|
aw.writeReturnType(jvmSignature.getKotlinReturnType());
|
||||||
@@ -882,7 +944,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
FrameMap frameMap = context.prepareFrame(state.getInjector().getJetTypeMapper());
|
FrameMap frameMap = context.prepareFrame(state.getInjector().getJetTypeMapper());
|
||||||
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, jvmSignature.getAsmMethod().getReturnType(), context, state);
|
ExpressionCodegen codegen =
|
||||||
|
new ExpressionCodegen(mv, frameMap, jvmSignature.getAsmMethod().getReturnType(), context, state);
|
||||||
codegen.generateThisOrOuter(descriptor); // ??? wouldn't it be a good idea to put it?
|
codegen.generateThisOrOuter(descriptor); // ??? wouldn't it be a good idea to put it?
|
||||||
|
|
||||||
Type[] argTypes = function.getArgumentTypes();
|
Type[] argTypes = function.getArgumentTypes();
|
||||||
@@ -904,10 +967,12 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
type = typeMapper.mapType(jetType, MapTypeMode.IMPL);
|
type = typeMapper.mapType(jetType, MapTypeMode.IMPL);
|
||||||
}
|
}
|
||||||
|
|
||||||
String fdescriptor = functionOriginal.getDescriptor().replace("(","(" + type.getDescriptor());
|
String fdescriptor = functionOriginal.getDescriptor().replace("(", "(" + type.getDescriptor());
|
||||||
Type type1 = typeMapper.mapType(((ClassDescriptor) fun.getContainingDeclaration()).getDefaultType(), MapTypeMode.TRAIT_IMPL);
|
Type type1 =
|
||||||
|
typeMapper.mapType(((ClassDescriptor) fun.getContainingDeclaration()).getDefaultType(), MapTypeMode.TRAIT_IMPL);
|
||||||
iv.invokestatic(type1.getInternalName(), function.getName(), fdescriptor);
|
iv.invokestatic(type1.getInternalName(), function.getName(), fdescriptor);
|
||||||
if (function.getReturnType().getSort() == Type.OBJECT && !function.getReturnType().equals(functionOriginal.getReturnType())) {
|
if (function.getReturnType().getSort() == Type.OBJECT &&
|
||||||
|
!function.getReturnType().equals(functionOriginal.getReturnType())) {
|
||||||
iv.checkcast(function.getReturnType());
|
iv.checkcast(function.getReturnType());
|
||||||
}
|
}
|
||||||
iv.areturn(function.getReturnType());
|
iv.areturn(function.getReturnType());
|
||||||
@@ -919,28 +984,38 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateDelegatorToConstructorCall(InstructionAdapter iv, ExpressionCodegen codegen, JetCallElement constructorCall,
|
private void generateDelegatorToConstructorCall(
|
||||||
ConstructorDescriptor constructorDescriptor,
|
InstructionAdapter iv, ExpressionCodegen codegen, JetCallElement constructorCall,
|
||||||
ConstructorFrameMap frameMap, int firstSuperArgument) {
|
ConstructorDescriptor constructorDescriptor,
|
||||||
|
ConstructorFrameMap frameMap, int firstSuperArgument
|
||||||
|
) {
|
||||||
ClassDescriptor classDecl = constructorDescriptor.getContainingDeclaration();
|
ClassDescriptor classDecl = constructorDescriptor.getContainingDeclaration();
|
||||||
|
|
||||||
iv.load(0, TYPE_OBJECT);
|
iv.load(0, TYPE_OBJECT);
|
||||||
if(classDecl.getKind() == ClassKind.ENUM_CLASS) {
|
if (classDecl.getKind() == ClassKind.ENUM_CLASS || classDecl.getKind() == ClassKind.ENUM_ENTRY) {
|
||||||
iv.load(1, JetTypeMapper.TYPE_OBJECT);
|
iv.load(1, JetTypeMapper.TYPE_OBJECT);
|
||||||
iv.load(2, Type.INT_TYPE);
|
iv.load(2, Type.INT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classDecl.getContainingDeclaration() instanceof ClassDescriptor) {
|
if (classDecl.getContainingDeclaration() instanceof ClassDescriptor) {
|
||||||
iv.load(frameMap.getOuterThisIndex(), typeMapper.mapType(((ClassDescriptor) descriptor.getContainingDeclaration()).getDefaultType(), MapTypeMode.IMPL));
|
iv.load(frameMap.getOuterThisIndex(),
|
||||||
|
typeMapper.mapType(((ClassDescriptor) descriptor.getContainingDeclaration()).getDefaultType(), MapTypeMode.IMPL));
|
||||||
}
|
}
|
||||||
|
|
||||||
CallableMethod method = typeMapper.mapToCallableMethod(constructorDescriptor, kind, typeMapper.hasThis0(constructorDescriptor.getContainingDeclaration()));
|
CallableMethod method = typeMapper
|
||||||
|
.mapToCallableMethod(constructorDescriptor, kind, typeMapper.hasThis0(constructorDescriptor.getContainingDeclaration()));
|
||||||
|
|
||||||
if (myClass instanceof JetObjectDeclaration && superCall instanceof JetDelegatorToSuperCall && ((JetObjectDeclaration) myClass).isObjectLiteral()) {
|
if (myClass instanceof JetObjectDeclaration &&
|
||||||
ConstructorDescriptor superConstructor = (ConstructorDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET, ((JetDelegatorToSuperCall) superCall).getCalleeExpression().getConstructorReferenceExpression());
|
superCall instanceof JetDelegatorToSuperCall &&
|
||||||
CallableMethod superCallable = typeMapper.mapToCallableMethod(superConstructor, OwnerKind.IMPLEMENTATION, typeMapper.hasThis0(superConstructor.getContainingDeclaration()));
|
((JetObjectDeclaration) myClass).isObjectLiteral()) {
|
||||||
int nextVar = firstSuperArgument+1;
|
ConstructorDescriptor superConstructor = (ConstructorDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET,
|
||||||
for(Type t : superCallable.getSignature().getAsmMethod().getArgumentTypes()) {
|
((JetDelegatorToSuperCall) superCall)
|
||||||
|
.getCalleeExpression()
|
||||||
|
.getConstructorReferenceExpression());
|
||||||
|
CallableMethod superCallable = typeMapper.mapToCallableMethod(superConstructor, OwnerKind.IMPLEMENTATION,
|
||||||
|
typeMapper.hasThis0(superConstructor.getContainingDeclaration()));
|
||||||
|
int nextVar = firstSuperArgument + 1;
|
||||||
|
for (Type t : superCallable.getSignature().getAsmMethod().getArgumentTypes()) {
|
||||||
iv.load(nextVar, t);
|
iv.load(nextVar, t);
|
||||||
nextVar += t.getSize();
|
nextVar += t.getSize();
|
||||||
}
|
}
|
||||||
@@ -999,7 +1074,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
iv.iconst(ordinal);
|
iv.iconst(ordinal);
|
||||||
|
|
||||||
// TODO type and constructor parameters
|
// TODO type and constructor parameters
|
||||||
String implClass = typeMapper.mapType(myType, MapTypeMode.IMPL).getInternalName();
|
ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, enumConstant);
|
||||||
|
String implClass = typeMapper.mapType(classDescriptor.getDefaultType(), MapTypeMode.IMPL).getInternalName();
|
||||||
|
|
||||||
final List<JetDelegationSpecifier> delegationSpecifiers = enumConstant.getDelegationSpecifiers();
|
final List<JetDelegationSpecifier> delegationSpecifiers = enumConstant.getDelegationSpecifiers();
|
||||||
if (delegationSpecifiers.size() > 1) {
|
if (delegationSpecifiers.size() > 1) {
|
||||||
@@ -1016,8 +1092,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
final JetDelegationSpecifier specifier = delegationSpecifiers.get(0);
|
final JetDelegationSpecifier specifier = delegationSpecifiers.get(0);
|
||||||
if (specifier instanceof JetDelegatorToSuperCall) {
|
if (specifier instanceof JetDelegatorToSuperCall) {
|
||||||
final JetDelegatorToSuperCall superCall = (JetDelegatorToSuperCall) specifier;
|
final JetDelegatorToSuperCall superCall = (JetDelegatorToSuperCall) specifier;
|
||||||
ConstructorDescriptor constructorDescriptor = (ConstructorDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET, superCall.getCalleeExpression().getConstructorReferenceExpression());
|
ConstructorDescriptor constructorDescriptor = (ConstructorDescriptor) bindingContext
|
||||||
CallableMethod method = typeMapper.mapToCallableMethod(constructorDescriptor, OwnerKind.IMPLEMENTATION, typeMapper.hasThis0(constructorDescriptor.getContainingDeclaration()));
|
.get(BindingContext.REFERENCE_TARGET, superCall.getCalleeExpression().getConstructorReferenceExpression());
|
||||||
|
CallableMethod method = typeMapper.mapToCallableMethod(constructorDescriptor, OwnerKind.IMPLEMENTATION, typeMapper
|
||||||
|
.hasThis0(constructorDescriptor.getContainingDeclaration()));
|
||||||
codegen.invokeMethodWithArguments(method, superCall, StackValue.none());
|
codegen.invokeMethodWithArguments(method, superCall, StackValue.none());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1028,14 +1106,16 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
iv.invokespecial(implClass, "<init>", "(Ljava/lang/String;I)V");
|
iv.invokespecial(implClass, "<init>", "(Ljava/lang/String;I)V");
|
||||||
}
|
}
|
||||||
iv.dup();
|
iv.dup();
|
||||||
iv.putstatic(implClass, enumConstant.getName(), "L" + implClass + ";");
|
iv.putstatic(myAsmType.getInternalName(), enumConstant.getName(), "L" + myAsmType.getInternalName() + ";");
|
||||||
iv.astore(TYPE_OBJECT);
|
iv.astore(TYPE_OBJECT);
|
||||||
}
|
}
|
||||||
iv.putstatic(myAsmType.getInternalName(), "$VALUES", arrayAsmType.getDescriptor());
|
iv.putstatic(myAsmType.getInternalName(), "$VALUES", arrayAsmType.getDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateInitializers(@NotNull ExpressionCodegen codegen, @NotNull InstructionAdapter iv, @NotNull List<JetDeclaration> declarations,
|
public static void generateInitializers(
|
||||||
@NotNull BindingContext bindingContext, @NotNull JetTypeMapper typeMapper) {
|
@NotNull ExpressionCodegen codegen, @NotNull InstructionAdapter iv, @NotNull List<JetDeclaration> declarations,
|
||||||
|
@NotNull BindingContext bindingContext, @NotNull JetTypeMapper typeMapper
|
||||||
|
) {
|
||||||
for (JetDeclaration declaration : declarations) {
|
for (JetDeclaration declaration : declarations) {
|
||||||
if (declaration instanceof JetProperty) {
|
if (declaration instanceof JetProperty) {
|
||||||
final PropertyDescriptor propertyDescriptor = (PropertyDescriptor) bindingContext.get(BindingContext.VARIABLE, declaration);
|
final PropertyDescriptor propertyDescriptor = (PropertyDescriptor) bindingContext.get(BindingContext.VARIABLE, declaration);
|
||||||
@@ -1048,34 +1128,44 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
Object value = compileTimeValue.getValue();
|
Object value = compileTimeValue.getValue();
|
||||||
Type type = typeMapper.mapType(propertyDescriptor.getType(), MapTypeMode.VALUE);
|
Type type = typeMapper.mapType(propertyDescriptor.getType(), MapTypeMode.VALUE);
|
||||||
if (JetTypeMapper.isPrimitive(type)) {
|
if (JetTypeMapper.isPrimitive(type)) {
|
||||||
if ( !propertyDescriptor.getType().isNullable() && value instanceof Number) {
|
if (!propertyDescriptor.getType().isNullable() && value instanceof Number) {
|
||||||
if (type == Type.INT_TYPE && ((Number)value).intValue() == 0)
|
if (type == Type.INT_TYPE && ((Number) value).intValue() == 0) {
|
||||||
continue;
|
continue;
|
||||||
if (type == Type.BYTE_TYPE && ((Number)value).byteValue() == 0)
|
}
|
||||||
|
if (type == Type.BYTE_TYPE && ((Number) value).byteValue() == 0) {
|
||||||
continue;
|
continue;
|
||||||
if (type == Type.LONG_TYPE && ((Number)value).longValue() == 0L)
|
}
|
||||||
|
if (type == Type.LONG_TYPE && ((Number) value).longValue() == 0L) {
|
||||||
continue;
|
continue;
|
||||||
if (type == Type.SHORT_TYPE && ((Number)value).shortValue() == 0)
|
}
|
||||||
|
if (type == Type.SHORT_TYPE && ((Number) value).shortValue() == 0) {
|
||||||
continue;
|
continue;
|
||||||
if (type == Type.DOUBLE_TYPE && ((Number)value).doubleValue() == 0d)
|
}
|
||||||
|
if (type == Type.DOUBLE_TYPE && ((Number) value).doubleValue() == 0d) {
|
||||||
continue;
|
continue;
|
||||||
if (type == Type.FLOAT_TYPE && ((Number)value).byteValue() == 0f)
|
}
|
||||||
|
if (type == Type.FLOAT_TYPE && ((Number) value).byteValue() == 0f) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (type == Type.BOOLEAN_TYPE && value instanceof Boolean && !((Boolean)value))
|
if (type == Type.BOOLEAN_TYPE && value instanceof Boolean && !((Boolean) value)) {
|
||||||
continue;
|
continue;
|
||||||
if (type == Type.CHAR_TYPE && value instanceof Character && ((Character)value) == 0)
|
}
|
||||||
|
if (type == Type.CHAR_TYPE && value instanceof Character && ((Character) value) == 0) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (value == null)
|
if (value == null) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||||
Type type = codegen.expressionType(initializer);
|
Type type = codegen.expressionType(initializer);
|
||||||
if (propertyDescriptor.getType().isNullable())
|
if (propertyDescriptor.getType().isNullable()) {
|
||||||
type = JetTypeMapper.boxType(type);
|
type = JetTypeMapper.boxType(type);
|
||||||
|
}
|
||||||
codegen.gen(initializer, type);
|
codegen.gen(initializer, type);
|
||||||
// @todo write directly to the field. Fix test excloset.jet::test6
|
// @todo write directly to the field. Fix test excloset.jet::test6
|
||||||
JvmClassName owner = typeMapper.getOwner(propertyDescriptor, OwnerKind.IMPLEMENTATION);
|
JvmClassName owner = typeMapper.getOwner(propertyDescriptor, OwnerKind.IMPLEMENTATION);
|
||||||
@@ -1083,7 +1173,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
StackValue.property(propertyDescriptor.getName().getName(), owner, owner,
|
StackValue.property(propertyDescriptor.getName().getName(), owner, owner,
|
||||||
propType, false, false, false, null, null, 0).store(propType, iv);
|
propType, false, false, false, null, null, 0).store(propType, iv);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (declaration instanceof JetClassInitializer) {
|
else if (declaration instanceof JetClassInitializer) {
|
||||||
@@ -1105,7 +1194,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
for (CallableMemberDescriptor overriddenDescriptor : overriddenDescriptors) {
|
for (CallableMemberDescriptor overriddenDescriptor : overriddenDescriptors) {
|
||||||
if (overriddenDescriptor.getContainingDeclaration() == classDescriptor) {
|
if (overriddenDescriptor.getContainingDeclaration() == classDescriptor) {
|
||||||
if (declaration instanceof PropertyDescriptor) {
|
if (declaration instanceof PropertyDescriptor) {
|
||||||
propertyCodegen.genDelegate((PropertyDescriptor) declaration, (PropertyDescriptor) overriddenDescriptor, field);
|
propertyCodegen
|
||||||
|
.genDelegate((PropertyDescriptor) declaration, (PropertyDescriptor) overriddenDescriptor, field);
|
||||||
}
|
}
|
||||||
else if (declaration instanceof SimpleFunctionDescriptor) {
|
else if (declaration instanceof SimpleFunctionDescriptor) {
|
||||||
functionCodegen.genDelegate((SimpleFunctionDescriptor) declaration, overriddenDescriptor, field);
|
functionCodegen.genDelegate((SimpleFunctionDescriptor) declaration, overriddenDescriptor, field);
|
||||||
@@ -1141,7 +1231,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<CallableMemberDescriptor> overriddenDeclarations = OverridingUtil.getOverriddenDeclarations(callableMemberDescriptor);
|
Collection<CallableMemberDescriptor> overriddenDeclarations =
|
||||||
|
OverridingUtil.getOverriddenDeclarations(callableMemberDescriptor);
|
||||||
for (CallableMemberDescriptor overriddenDeclaration : overriddenDeclarations) {
|
for (CallableMemberDescriptor overriddenDeclaration : overriddenDeclarations) {
|
||||||
if (overriddenDeclaration.getModality() != Modality.ABSTRACT) {
|
if (overriddenDeclaration.getModality() != Modality.ABSTRACT) {
|
||||||
if (!CodegenUtil.isInterface(overriddenDeclaration.getContainingDeclaration())) {
|
if (!CodegenUtil.isInterface(overriddenDeclaration.getContainingDeclaration())) {
|
||||||
@@ -1159,5 +1250,4 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -306,11 +306,13 @@ public class JetTypeMapper {
|
|||||||
return JvmClassName.byInternalName(r.toString());
|
return JvmClassName.byInternalName(r.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull public Type mapReturnType(@NotNull final JetType jetType) {
|
@NotNull
|
||||||
|
public Type mapReturnType(@NotNull final JetType jetType) {
|
||||||
return mapReturnType(jetType, null);
|
return mapReturnType(jetType, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull private Type mapReturnType(@NotNull final JetType jetType, @Nullable BothSignatureWriter signatureVisitor) {
|
@NotNull
|
||||||
|
private Type mapReturnType(@NotNull final JetType jetType, @Nullable BothSignatureWriter signatureVisitor) {
|
||||||
if (jetType.equals(JetStandardClasses.getUnitType())) {
|
if (jetType.equals(JetStandardClasses.getUnitType())) {
|
||||||
if (signatureVisitor != null) {
|
if (signatureVisitor != null) {
|
||||||
signatureVisitor.writeAsmType(Type.VOID_TYPE, false);
|
signatureVisitor.writeAsmType(Type.VOID_TYPE, false);
|
||||||
@@ -375,7 +377,12 @@ public class JetTypeMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (klass.getKind() == ClassKind.ENUM_ENTRY) {
|
else if (klass.getKind() == ClassKind.ENUM_ENTRY) {
|
||||||
return getJvmInternalFQName(klass.getContainingDeclaration());
|
if (closureAnnotator.enumEntryNeedSubclass(klass)) {
|
||||||
|
return getJvmInternalFQName(klass.getContainingDeclaration()) + "$" + klass.getName().getName();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return getJvmInternalFQName(klass.getContainingDeclaration());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,8 +469,8 @@ public class JetTypeMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor instanceof ClassDescriptor
|
if (descriptor instanceof ClassDescriptor
|
||||||
&& JetStandardLibraryNames.ARRAY.is((ClassDescriptor) descriptor)
|
&& JetStandardLibraryNames.ARRAY.is((ClassDescriptor) descriptor)
|
||||||
&& mapBuiltinsToJava) {
|
&& mapBuiltinsToJava) {
|
||||||
if (jetType.getArguments().size() != 1) {
|
if (jetType.getArguments().size() != 1) {
|
||||||
throw new UnsupportedOperationException("arrays must have one type argument");
|
throw new UnsupportedOperationException("arrays must have one type argument");
|
||||||
}
|
}
|
||||||
@@ -511,7 +518,8 @@ public class JetTypeMapper {
|
|||||||
|
|
||||||
Type type = mapType(((TypeParameterDescriptor) descriptor).getUpperBoundsAsType(), kind);
|
Type type = mapType(((TypeParameterDescriptor) descriptor).getUpperBoundsAsType(), kind);
|
||||||
if (signatureVisitor != null) {
|
if (signatureVisitor != null) {
|
||||||
TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) jetType.getConstructor().getDeclarationDescriptor();
|
TypeParameterDescriptor typeParameterDescriptor =
|
||||||
|
(TypeParameterDescriptor) jetType.getConstructor().getDeclarationDescriptor();
|
||||||
assert typeParameterDescriptor != null;
|
assert typeParameterDescriptor != null;
|
||||||
signatureVisitor.writeTypeVariable(typeParameterDescriptor.getName(), jetType.isNullable(), type);
|
signatureVisitor.writeTypeVariable(typeParameterDescriptor.getName(), jetType.isNullable(), type);
|
||||||
}
|
}
|
||||||
@@ -584,11 +592,13 @@ public class JetTypeMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CallableMethod mapToCallableMethod(FunctionDescriptor functionDescriptor, boolean superCall, OwnerKind kind) {
|
public CallableMethod mapToCallableMethod(FunctionDescriptor functionDescriptor, boolean superCall, OwnerKind kind) {
|
||||||
if (functionDescriptor == null) { return null; }
|
if (functionDescriptor == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
final DeclarationDescriptor functionParent = functionDescriptor.getOriginal().getContainingDeclaration();
|
final DeclarationDescriptor functionParent = functionDescriptor.getOriginal().getContainingDeclaration();
|
||||||
|
|
||||||
while(functionDescriptor.getKind()==CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
while (functionDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||||
functionDescriptor = functionDescriptor.getOverriddenDescriptors().iterator().next();
|
functionDescriptor = functionDescriptor.getOverriddenDescriptors().iterator().next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,7 +624,8 @@ public class JetTypeMapper {
|
|||||||
thisClass = null;
|
thisClass = null;
|
||||||
}
|
}
|
||||||
else if (functionParent instanceof ScriptDescriptor) {
|
else if (functionParent instanceof ScriptDescriptor) {
|
||||||
thisClass = owner = ownerForDefaultParam = ownerForDefaultImpl = closureAnnotator.classNameForScriptDescriptor((ScriptDescriptor) functionParent);
|
thisClass = owner =
|
||||||
|
ownerForDefaultParam = ownerForDefaultImpl = closureAnnotator.classNameForScriptDescriptor((ScriptDescriptor) functionParent);
|
||||||
invokeOpcode = INVOKEVIRTUAL;
|
invokeOpcode = INVOKEVIRTUAL;
|
||||||
}
|
}
|
||||||
else if (functionParent instanceof ClassDescriptor) {
|
else if (functionParent instanceof ClassDescriptor) {
|
||||||
@@ -647,8 +658,8 @@ public class JetTypeMapper {
|
|||||||
ownerForDefaultParam.getInternalName() + (originalIsInterface ? JvmAbi.TRAIT_IMPL_SUFFIX : ""));
|
ownerForDefaultParam.getInternalName() + (originalIsInterface ? JvmAbi.TRAIT_IMPL_SUFFIX : ""));
|
||||||
|
|
||||||
invokeOpcode = isInterface
|
invokeOpcode = isInterface
|
||||||
? (superCall ? Opcodes.INVOKESTATIC : Opcodes.INVOKEINTERFACE)
|
? (superCall ? Opcodes.INVOKESTATIC : Opcodes.INVOKEINTERFACE)
|
||||||
: (isAccessor ? Opcodes.INVOKESTATIC : (superCall ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL));
|
: (isAccessor ? Opcodes.INVOKESTATIC : (superCall ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL));
|
||||||
if (isInterface && superCall) {
|
if (isInterface && superCall) {
|
||||||
descriptor = mapSignature(functionDescriptor, false, OwnerKind.TRAIT_IMPL);
|
descriptor = mapSignature(functionDescriptor, false, OwnerKind.TRAIT_IMPL);
|
||||||
owner = JvmClassName.byInternalName(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
owner = JvmClassName.byInternalName(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
||||||
@@ -673,7 +684,9 @@ public class JetTypeMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isAccessor(FunctionDescriptor functionDescriptor) {
|
private static boolean isAccessor(FunctionDescriptor functionDescriptor) {
|
||||||
return functionDescriptor instanceof AccessorForFunctionDescriptor || functionDescriptor instanceof AccessorForPropertyDescriptor.Getter || functionDescriptor instanceof AccessorForPropertyDescriptor.Setter;
|
return functionDescriptor instanceof AccessorForFunctionDescriptor ||
|
||||||
|
functionDescriptor instanceof AccessorForPropertyDescriptor.Getter ||
|
||||||
|
functionDescriptor instanceof AccessorForPropertyDescriptor.Setter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -704,9 +717,9 @@ public class JetTypeMapper {
|
|||||||
|
|
||||||
signatureVisitor.writeParametersStart();
|
signatureVisitor.writeParametersStart();
|
||||||
|
|
||||||
if(isAccessor(f)) {
|
if (isAccessor(f)) {
|
||||||
signatureVisitor.writeParameterType(JvmMethodParameterKind.THIS);
|
signatureVisitor.writeParameterType(JvmMethodParameterKind.THIS);
|
||||||
mapType(((ClassifierDescriptor)f.getContainingDeclaration()).getDefaultType(), signatureVisitor, MapTypeMode.VALUE);
|
mapType(((ClassifierDescriptor) f.getContainingDeclaration()).getDefaultType(), signatureVisitor, MapTypeMode.VALUE);
|
||||||
signatureVisitor.writeParameterTypeEnd();
|
signatureVisitor.writeParameterTypeEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -714,7 +727,7 @@ public class JetTypeMapper {
|
|||||||
ClassDescriptor containingDeclaration = (ClassDescriptor) f.getContainingDeclaration();
|
ClassDescriptor containingDeclaration = (ClassDescriptor) f.getContainingDeclaration();
|
||||||
JetType jetType = TraitImplBodyCodegen.getSuperClass(containingDeclaration);
|
JetType jetType = TraitImplBodyCodegen.getSuperClass(containingDeclaration);
|
||||||
Type type = mapType(jetType, MapTypeMode.VALUE);
|
Type type = mapType(jetType, MapTypeMode.VALUE);
|
||||||
if(type.getInternalName().equals("java/lang/Object")) {
|
if (type.getInternalName().equals("java/lang/Object")) {
|
||||||
jetType = containingDeclaration.getDefaultType();
|
jetType = containingDeclaration.getDefaultType();
|
||||||
type = mapType(jetType, MapTypeMode.VALUE);
|
type = mapType(jetType, MapTypeMode.VALUE);
|
||||||
}
|
}
|
||||||
@@ -763,7 +776,8 @@ public class JetTypeMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void writeFormalTypeParameter(TypeParameterDescriptor typeParameterDescriptor, BothSignatureWriter signatureVisitor) {
|
private void writeFormalTypeParameter(TypeParameterDescriptor typeParameterDescriptor, BothSignatureWriter signatureVisitor) {
|
||||||
signatureVisitor.writeFormalTypeParameter(typeParameterDescriptor.getName().getName(), typeParameterDescriptor.getVariance(), typeParameterDescriptor.isReified());
|
signatureVisitor.writeFormalTypeParameter(typeParameterDescriptor.getName().getName(), typeParameterDescriptor.getVariance(),
|
||||||
|
typeParameterDescriptor.isReified());
|
||||||
|
|
||||||
classBound:
|
classBound:
|
||||||
{
|
{
|
||||||
@@ -801,7 +815,6 @@ public class JetTypeMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
signatureVisitor.writeFormalTypeParameterEnd();
|
signatureVisitor.writeFormalTypeParameterEnd();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public JvmMethodSignature mapSignature(Name name, FunctionDescriptor f) {
|
public JvmMethodSignature mapSignature(Name name, FunctionDescriptor f) {
|
||||||
@@ -813,9 +826,9 @@ public class JetTypeMapper {
|
|||||||
|
|
||||||
signatureWriter.writeParametersStart();
|
signatureWriter.writeParametersStart();
|
||||||
|
|
||||||
if(isAccessor(f)) {
|
if (isAccessor(f)) {
|
||||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
||||||
mapType(((ClassifierDescriptor)f.getContainingDeclaration()).getDefaultType(), signatureWriter, MapTypeMode.VALUE);
|
mapType(((ClassifierDescriptor) f.getContainingDeclaration()).getDefaultType(), signatureWriter, MapTypeMode.VALUE);
|
||||||
signatureWriter.writeParameterTypeEnd();
|
signatureWriter.writeParameterTypeEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -854,16 +867,17 @@ public class JetTypeMapper {
|
|||||||
|
|
||||||
signatureWriter.writeParametersStart();
|
signatureWriter.writeParametersStart();
|
||||||
|
|
||||||
if(kind == OwnerKind.TRAIT_IMPL) {
|
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||||
ClassDescriptor containingDeclaration = (ClassDescriptor) parentDescriptor;
|
ClassDescriptor containingDeclaration = (ClassDescriptor) parentDescriptor;
|
||||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
||||||
mapType(containingDeclaration.getDefaultType(), signatureWriter, MapTypeMode.IMPL);
|
mapType(containingDeclaration.getDefaultType(), signatureWriter, MapTypeMode.IMPL);
|
||||||
signatureWriter.writeParameterTypeEnd();
|
signatureWriter.writeParameterTypeEnd();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(descriptor instanceof AccessorForPropertyDescriptor) {
|
if (descriptor instanceof AccessorForPropertyDescriptor) {
|
||||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
||||||
mapType(((ClassifierDescriptor)descriptor.getContainingDeclaration()).getDefaultType(), signatureWriter, MapTypeMode.VALUE);
|
mapType(((ClassifierDescriptor) descriptor.getContainingDeclaration()).getDefaultType(), signatureWriter,
|
||||||
|
MapTypeMode.VALUE);
|
||||||
signatureWriter.writeParameterTypeEnd();
|
signatureWriter.writeParameterTypeEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -908,9 +922,10 @@ public class JetTypeMapper {
|
|||||||
signatureWriter.writeParameterTypeEnd();
|
signatureWriter.writeParameterTypeEnd();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(descriptor instanceof AccessorForPropertyDescriptor) {
|
if (descriptor instanceof AccessorForPropertyDescriptor) {
|
||||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
||||||
mapType(((ClassifierDescriptor)descriptor.getContainingDeclaration()).getDefaultType(), signatureWriter, MapTypeMode.VALUE);
|
mapType(((ClassifierDescriptor) descriptor.getContainingDeclaration()).getDefaultType(), signatureWriter,
|
||||||
|
MapTypeMode.VALUE);
|
||||||
signatureWriter.writeParameterTypeEnd();
|
signatureWriter.writeParameterTypeEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -930,7 +945,8 @@ public class JetTypeMapper {
|
|||||||
signatureWriter.writeVoidReturn();
|
signatureWriter.writeVoidReturn();
|
||||||
|
|
||||||
JvmMethodSignature jvmMethodSignature = signatureWriter.makeJvmMethodSignature(name);
|
JvmMethodSignature jvmMethodSignature = signatureWriter.makeJvmMethodSignature(name);
|
||||||
return new JvmPropertyAccessorSignature(jvmMethodSignature, jvmMethodSignature.getKotlinParameterType(jvmMethodSignature.getParameterCount() - 1));
|
return new JvmPropertyAccessorSignature(jvmMethodSignature,
|
||||||
|
jvmMethodSignature.getKotlinParameterType(jvmMethodSignature.getParameterCount() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private JvmMethodSignature mapConstructorSignature(ConstructorDescriptor descriptor, boolean hasThis0) {
|
private JvmMethodSignature mapConstructorSignature(ConstructorDescriptor descriptor, boolean hasThis0) {
|
||||||
@@ -947,11 +963,12 @@ public class JetTypeMapper {
|
|||||||
ClassDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
ClassDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||||
if (hasThis0) {
|
if (hasThis0) {
|
||||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS0);
|
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS0);
|
||||||
mapType(closureAnnotator.getEclosingClassDescriptor(containingDeclaration).getDefaultType(), signatureWriter, MapTypeMode.VALUE);
|
mapType(closureAnnotator.getEclosingClassDescriptor(containingDeclaration).getDefaultType(), signatureWriter,
|
||||||
|
MapTypeMode.VALUE);
|
||||||
signatureWriter.writeParameterTypeEnd();
|
signatureWriter.writeParameterTypeEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(containingDeclaration.getKind() == ClassKind.ENUM_CLASS) {
|
if (containingDeclaration.getKind() == ClassKind.ENUM_CLASS || containingDeclaration.getKind() == ClassKind.ENUM_ENTRY) {
|
||||||
signatureWriter.writeParameterType(JvmMethodParameterKind.ENUM_NAME);
|
signatureWriter.writeParameterType(JvmMethodParameterKind.ENUM_NAME);
|
||||||
mapType(JetStandardLibrary.getInstance().getStringType(), signatureWriter, MapTypeMode.VALUE);
|
mapType(JetStandardLibrary.getInstance().getStringType(), signatureWriter, MapTypeMode.VALUE);
|
||||||
signatureWriter.writeParameterTypeEnd();
|
signatureWriter.writeParameterTypeEnd();
|
||||||
@@ -983,7 +1000,8 @@ public class JetTypeMapper {
|
|||||||
|
|
||||||
for (ScriptDescriptor importedScript : importedScripts) {
|
for (ScriptDescriptor importedScript : importedScripts) {
|
||||||
signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE);
|
signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE);
|
||||||
mapType(closureAnnotator.classDescriptorForScriptDescriptor(importedScript).getDefaultType(), signatureWriter, MapTypeMode.VALUE);
|
mapType(closureAnnotator.classDescriptorForScriptDescriptor(importedScript).getDefaultType(), signatureWriter,
|
||||||
|
MapTypeMode.VALUE);
|
||||||
signatureWriter.writeParameterTypeEnd();
|
signatureWriter.writeParameterTypeEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1055,28 +1073,31 @@ public class JetTypeMapper {
|
|||||||
|
|
||||||
private static boolean isForceReal(JvmClassName className) {
|
private static boolean isForceReal(JvmClassName className) {
|
||||||
return JvmPrimitiveType.getByWrapperClass(className) != null
|
return JvmPrimitiveType.getByWrapperClass(className) != null
|
||||||
|| className.getFqName().getFqName().equals("java.lang.String")
|
|| className.getFqName().getFqName().equals("java.lang.String")
|
||||||
|| className.getFqName().getFqName().equals("java.lang.CharSequence")
|
|| className.getFqName().getFqName().equals("java.lang.CharSequence")
|
||||||
|| className.getFqName().getFqName().equals("java.lang.Object")
|
|| className.getFqName().getFqName().equals("java.lang.Object")
|
||||||
|| className.getFqName().getFqName().equals("java.lang.Number")
|
|| className.getFqName().getFqName().equals("java.lang.Number")
|
||||||
|| className.getFqName().getFqName().equals("java.lang.Enum")
|
|| className.getFqName().getFqName().equals("java.lang.Enum")
|
||||||
|| className.getFqName().getFqName().equals("java.lang.Comparable");
|
|| className.getFqName().getFqName().equals("java.lang.Comparable");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isGenericsArray(JetType type) {
|
public static boolean isGenericsArray(JetType type) {
|
||||||
return JetStandardLibraryNames.ARRAY.is(type) && type.getArguments().get(0).getType().getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor;
|
return JetStandardLibraryNames.ARRAY.is(type) &&
|
||||||
|
type.getArguments().get(0).getType().getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type getSharedVarType(DeclarationDescriptor descriptor) {
|
public Type getSharedVarType(DeclarationDescriptor descriptor) {
|
||||||
if (descriptor instanceof PropertyDescriptor) {
|
if (descriptor instanceof PropertyDescriptor) {
|
||||||
return StackValue.sharedTypeForType(mapType(((PropertyDescriptor) descriptor).getReceiverParameter().getType(), MapTypeMode.VALUE));
|
return StackValue
|
||||||
|
.sharedTypeForType(mapType(((PropertyDescriptor) descriptor).getReceiverParameter().getType(), MapTypeMode.VALUE));
|
||||||
}
|
}
|
||||||
else if (descriptor instanceof SimpleFunctionDescriptor && descriptor.getContainingDeclaration() instanceof FunctionDescriptor) {
|
else if (descriptor instanceof SimpleFunctionDescriptor && descriptor.getContainingDeclaration() instanceof FunctionDescriptor) {
|
||||||
PsiElement psiElement = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
|
PsiElement psiElement = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
|
||||||
return closureAnnotator.classNameForAnonymousClass((JetElement) psiElement).getAsmType();
|
return closureAnnotator.classNameForAnonymousClass((JetElement) psiElement).getAsmType();
|
||||||
}
|
}
|
||||||
else if (descriptor instanceof FunctionDescriptor) {
|
else if (descriptor instanceof FunctionDescriptor) {
|
||||||
return StackValue.sharedTypeForType(mapType(((FunctionDescriptor) descriptor).getReceiverParameter().getType(), MapTypeMode.VALUE));
|
return StackValue
|
||||||
|
.sharedTypeForType(mapType(((FunctionDescriptor) descriptor).getReceiverParameter().getType(), MapTypeMode.VALUE));
|
||||||
}
|
}
|
||||||
else if (descriptor instanceof VariableDescriptor && isVarCapturedInClosure(descriptor)) {
|
else if (descriptor instanceof VariableDescriptor && isVarCapturedInClosure(descriptor)) {
|
||||||
JetType outType = ((VariableDescriptor) descriptor).getType();
|
JetType outType = ((VariableDescriptor) descriptor).getType();
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fun box() = IssueState.DEFAULT.ToString() + IssueState.FIXED.ToString()
|
||||||
|
|
||||||
|
open enum class IssueState {
|
||||||
|
DEFAULT
|
||||||
|
FIXED {
|
||||||
|
override fun ToString() = "K"
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun ToString() : String = "O"
|
||||||
|
}
|
||||||
@@ -100,4 +100,35 @@ public class EnumGenTest extends CodegenTestCase {
|
|||||||
public void testInClassObj() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
public void testInClassObj() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||||
blackBoxFile("enum/inclassobj.kt");
|
blackBoxFile("enum/inclassobj.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testAbstractMethod()
|
||||||
|
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||||
|
blackBoxFile("enum/abstractmethod.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testNoClassForSimpleEnum()
|
||||||
|
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
|
||||||
|
loadFile("enum/name.kt");
|
||||||
|
Class cls = loadImplementationClass(generateClassesInFile(), "State");
|
||||||
|
Field field = cls.getField("O");
|
||||||
|
assertEquals("State", field.get(null).getClass().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testYesClassForComplexEnum()
|
||||||
|
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
|
||||||
|
loadFile("enum/abstractmethod.kt");
|
||||||
|
Class cls = loadImplementationClass(generateClassesInFile(), "IssueState");
|
||||||
|
Field field = cls.getField("DEFAULT");
|
||||||
|
assertEquals("IssueState", field.get(null).getClass().getName());
|
||||||
|
field = cls.getField("FIXED");
|
||||||
|
assertEquals("IssueState", field.getType().getName());
|
||||||
|
assertEquals("IssueState$FIXED", field.get(null).getClass().getName());
|
||||||
|
assertNotNull(cls.getClassLoader().loadClass("IssueState$FIXED"));
|
||||||
|
try {
|
||||||
|
cls.getClassLoader().loadClass("IssueState$DEFAULT");
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user