ExpressionCodegen: take EnumEntry type from containingDeclarationDescriptor
JavaDescriptorResolver: pass to propertyDescriptor correct value of isObject parameter
This commit is contained in:
@@ -1105,18 +1105,17 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||||
|
|
||||||
if (propertyDescriptor.isObjectDeclaration()) {
|
if (propertyDescriptor.isObjectDeclaration()) {
|
||||||
ClassDescriptor classDescriptor =
|
boolean isEnumEntry = DescriptorUtils.isEnumClassObject(propertyDescriptor.getContainingDeclaration());
|
||||||
(ClassDescriptor) propertyDescriptor.getReturnType().getConstructor().getDeclarationDescriptor();
|
if (isEnumEntry) {
|
||||||
assert classDescriptor != null;
|
ClassDescriptor containing = (ClassDescriptor) propertyDescriptor.getContainingDeclaration().getContainingDeclaration();
|
||||||
if (classDescriptor.getKind() == ClassKind.ENUM_ENTRY) {
|
|
||||||
ClassDescriptor containing = (ClassDescriptor) classDescriptor.getContainingDeclaration().getContainingDeclaration();
|
|
||||||
assert containing != null;
|
assert containing != null;
|
||||||
Type type = typeMapper.mapType(containing.getDefaultType(), MapTypeMode.VALUE);
|
Type type = typeMapper.mapType(containing.getDefaultType(), MapTypeMode.VALUE);
|
||||||
Type entryType = typeMapper.mapType(classDescriptor.getDefaultType(), MapTypeMode.VALUE);
|
StackValue.field(type, JvmClassName.byType(type), propertyDescriptor.getName().getName(), true).put(type, v);
|
||||||
StackValue.field(type, JvmClassName.byType(type), classDescriptor.getName().getName(), true).put(entryType, v);
|
return StackValue.onStack(type);
|
||||||
return StackValue.onStack(entryType);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
ClassifierDescriptor classDescriptor = propertyDescriptor.getReturnType().getConstructor().getDeclarationDescriptor();
|
||||||
|
assert classDescriptor != null;
|
||||||
Type type = typeMapper.mapType(classDescriptor.getDefaultType(), MapTypeMode.VALUE);
|
Type type = typeMapper.mapType(classDescriptor.getDefaultType(), MapTypeMode.VALUE);
|
||||||
return StackValue.field(type, JvmClassName.byType(type), "$instance", true);
|
return StackValue.field(type, JvmClassName.byType(type), "$instance", true);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1185,7 +1185,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
|||||||
resolveModality(anyMember.getMember(), isFinal),
|
resolveModality(anyMember.getMember(), isFinal),
|
||||||
visibility,
|
visibility,
|
||||||
isVar,
|
isVar,
|
||||||
false,
|
DescriptorUtils.isEnumClassObject(realOwner),
|
||||||
propertyName,
|
propertyName,
|
||||||
CallableMemberDescriptor.Kind.DECLARATION);
|
CallableMemberDescriptor.Kind.DECLARATION);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
public enum simpleJavaEnum {
|
||||||
|
A;
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import test.*
|
||||||
|
|
||||||
|
fun box() =
|
||||||
|
if (simpleJavaEnum.A.toString() == "A") "OK"
|
||||||
|
else "fail"
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import java.lang.Override;
|
||||||
|
import java.lang.String;
|
||||||
|
|
||||||
|
public enum simpleJavaEnumWithFunction {
|
||||||
|
A {
|
||||||
|
@Override
|
||||||
|
public String repr() {
|
||||||
|
return "A";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
B;
|
||||||
|
|
||||||
|
public String repr() {
|
||||||
|
return "ololol" + toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import test.simpleJavaEnumWithFunction.*
|
||||||
|
|
||||||
|
fun box() =
|
||||||
|
if (A.repr() == "A" && B.repr() == "olololB") "OK"
|
||||||
|
else "fail"
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
public enum simpleJavaEnumWithStaticImport {
|
||||||
|
A;
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import test.simpleJavaEnumWithStaticImport.A
|
||||||
|
|
||||||
|
fun box() =
|
||||||
|
if (A.toString() == "A") "OK"
|
||||||
|
else "fail"
|
||||||
@@ -105,6 +105,18 @@ public class EnumGenTest extends CodegenTestCase {
|
|||||||
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||||
blackBoxFile("enum/abstractmethod.kt");
|
blackBoxFile("enum/abstractmethod.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSimpleJavaEnum() throws Exception {
|
||||||
|
blackBoxFileWithJava("enum/simpleJavaEnum.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSimpleJavaEnumWithStaticImport() throws Exception {
|
||||||
|
blackBoxFileWithJava("enum/simpleJavaEnumWithStaticImport.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSimpleJavaEnumWithFunction() throws Exception {
|
||||||
|
blackBoxFileWithJava("enum/simpleJavaEnumWithFunction.kt");
|
||||||
|
}
|
||||||
|
|
||||||
public void testNoClassForSimpleEnum()
|
public void testNoClassForSimpleEnum()
|
||||||
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
|
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
|
||||||
|
|||||||
Reference in New Issue
Block a user