ExpressionCodegen: take EnumEntry type from containingDeclarationDescriptor

JavaDescriptorResolver: pass to propertyDescriptor correct value of isObject parameter
This commit is contained in:
Natalia.Ukhorskaya
2012-08-22 14:29:38 +04:00
parent 6740a712d8
commit 3d9ad3f6cb
9 changed files with 63 additions and 9 deletions
@@ -1105,18 +1105,17 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
if (propertyDescriptor.isObjectDeclaration()) {
ClassDescriptor classDescriptor =
(ClassDescriptor) propertyDescriptor.getReturnType().getConstructor().getDeclarationDescriptor();
assert classDescriptor != null;
if (classDescriptor.getKind() == ClassKind.ENUM_ENTRY) {
ClassDescriptor containing = (ClassDescriptor) classDescriptor.getContainingDeclaration().getContainingDeclaration();
boolean isEnumEntry = DescriptorUtils.isEnumClassObject(propertyDescriptor.getContainingDeclaration());
if (isEnumEntry) {
ClassDescriptor containing = (ClassDescriptor) propertyDescriptor.getContainingDeclaration().getContainingDeclaration();
assert containing != null;
Type type = typeMapper.mapType(containing.getDefaultType(), MapTypeMode.VALUE);
Type entryType = typeMapper.mapType(classDescriptor.getDefaultType(), MapTypeMode.VALUE);
StackValue.field(type, JvmClassName.byType(type), classDescriptor.getName().getName(), true).put(entryType, v);
return StackValue.onStack(entryType);
StackValue.field(type, JvmClassName.byType(type), propertyDescriptor.getName().getName(), true).put(type, v);
return StackValue.onStack(type);
}
else {
ClassifierDescriptor classDescriptor = propertyDescriptor.getReturnType().getConstructor().getDeclarationDescriptor();
assert classDescriptor != null;
Type type = typeMapper.mapType(classDescriptor.getDefaultType(), MapTypeMode.VALUE);
return StackValue.field(type, JvmClassName.byType(type), "$instance", true);
}
@@ -1185,7 +1185,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
resolveModality(anyMember.getMember(), isFinal),
visibility,
isVar,
false,
DescriptorUtils.isEnumClassObject(realOwner),
propertyName,
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 {
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()
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {