Move properties of enum class object to the enum class
Similar to how it's done for usual classes
This commit is contained in:
@@ -667,14 +667,17 @@ public class AsmUtil {
|
||||
|
||||
public static boolean isPropertyWithBackingFieldCopyInOuterClass(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
boolean isExtensionProperty = propertyDescriptor.getReceiverParameter() != null;
|
||||
return !propertyDescriptor.isVar() && !isExtensionProperty
|
||||
&& isClassObjectOfClassWithKind(propertyDescriptor.getContainingDeclaration(), ClassKind.TRAIT)
|
||||
DeclarationDescriptor propertyContainer = propertyDescriptor.getContainingDeclaration();
|
||||
return !propertyDescriptor.isVar()
|
||||
&& !isExtensionProperty
|
||||
&& isClassObject(propertyContainer) && isTrait(propertyContainer.getContainingDeclaration())
|
||||
&& areBothAccessorDefault(propertyDescriptor)
|
||||
&& getVisibilityForSpecialPropertyBackingField(propertyDescriptor, false) == ACC_PUBLIC;
|
||||
}
|
||||
|
||||
public static boolean isClassObjectWithBackingFieldsInOuter(@NotNull DeclarationDescriptor classObject) {
|
||||
return isClassObjectOfClassWithKind(classObject, ClassKind.CLASS);
|
||||
DeclarationDescriptor containingClass = classObject.getContainingDeclaration();
|
||||
return isClassObject(classObject) && (isClass(containingClass) || isEnumClass(containingClass));
|
||||
}
|
||||
|
||||
private static boolean areBothAccessorDefault(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
@@ -686,10 +689,6 @@ public class AsmUtil {
|
||||
return accessorDescriptor == null || !accessorDescriptor.hasBody();
|
||||
}
|
||||
|
||||
private static boolean isClassObjectOfClassWithKind(@NotNull DeclarationDescriptor classObject, @NotNull ClassKind kind) {
|
||||
return isClassObject(classObject) && isKindOf(classObject.getContainingDeclaration(), kind);
|
||||
}
|
||||
|
||||
public static Type comparisonOperandType(Type left, Type right) {
|
||||
if (left == Type.DOUBLE_TYPE || right == Type.DOUBLE_TYPE) return Type.DOUBLE_TYPE;
|
||||
if (left == Type.FLOAT_TYPE || right == Type.FLOAT_TYPE) return Type.FLOAT_TYPE;
|
||||
|
||||
@@ -11,7 +11,7 @@ enum class Game {
|
||||
|
||||
fun box(): String {
|
||||
if (Game.foo() != Game.ROCK) return "Fail 1"
|
||||
// TODO: fix initialization order and uncomment
|
||||
// TODO: fix initialization order and uncomment (KT-5761)
|
||||
// if (Game.bar != Game.PAPER) return "Fail 2: ${Game.bar}"
|
||||
if (Game.values().size != 3) return "Fail 3"
|
||||
if (Game.valueOf("SCISSORS") != Game.SCISSORS) return "Fail 4"
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
class Test {
|
||||
String test() {
|
||||
String s;
|
||||
|
||||
s = Klass.NAME;
|
||||
if (!s.equals("Klass")) throw new AssertionError("Fail class: " + s);
|
||||
|
||||
s = Trait.NAME;
|
||||
if (!s.equals("Trait")) throw new AssertionError("Fail trait: " + s);
|
||||
|
||||
s = Enoom.NAME;
|
||||
if (!s.equals("Enoom")) throw new AssertionError("Fail enum: " + s);
|
||||
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
class Klass {
|
||||
class object {
|
||||
val NAME = "Klass"
|
||||
}
|
||||
}
|
||||
|
||||
trait Trait {
|
||||
class object {
|
||||
val NAME = "Trait"
|
||||
}
|
||||
}
|
||||
|
||||
enum class Enoom {
|
||||
class object {
|
||||
val NAME = "Enoom"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Test().test()
|
||||
+18
-1
@@ -32,7 +32,7 @@ import java.util.regex.Pattern;
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("compiler/testData/codegen/boxWithJava")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@InnerTestClasses({BlackBoxWithJavaCodegenTestGenerated.PlatformStatic.class})
|
||||
@InnerTestClasses({BlackBoxWithJavaCodegenTestGenerated.PlatformStatic.class, BlackBoxWithJavaCodegenTestGenerated.Properties.class})
|
||||
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
|
||||
public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
public void testAllFilesPresentInBoxWithJava() throws Exception {
|
||||
@@ -74,4 +74,21 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxWithJava/properties")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@InnerTestClasses({})
|
||||
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
|
||||
public static class Properties extends AbstractBlackBoxCodegenTest {
|
||||
public void testAllFilesPresentInProperties() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithJava/properties"), Pattern.compile("^([^\\.]+)$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("classObjectProperties")
|
||||
public void testClassObjectProperties() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/properties/classObjectProperties/");
|
||||
doTestWithJava(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user