KT-546 Enum constructor invocations

This commit is contained in:
Sergey Ignatov
2011-12-06 14:20:14 +04:00
parent 3be18e69e2
commit 6cc8caa1eb
10 changed files with 60 additions and 18 deletions
+13 -7
View File
@@ -305,11 +305,8 @@ public class Converter {
modifiers.add(Modifier.OVERRIDE);
if (method.getParent() instanceof PsiClass && ((PsiClass) method.getParent()).isInterface())
modifiers.remove(Modifier.ABSTRACT);
if (method.getParent() instanceof PsiClass) {
final PsiModifierList parentModifierList = ((PsiClass) method.getParent()).getModifierList();
if (parentModifierList != null && parentModifierList.hasExplicitModifier(Modifier.FINAL))
modifiers.add(Modifier.NOT_OPEN);
}
if (isNotOpenMethod(method))
modifiers.add(Modifier.NOT_OPEN);
if (method.isConstructor()) { // TODO: simplify
boolean isPrimary = isConstructorPrimary(method);
@@ -333,6 +330,15 @@ public class Converter {
);
}
private static boolean isNotOpenMethod(final PsiMethod method) {
if (method.getParent() instanceof PsiClass) {
final PsiModifierList parentModifierList = ((PsiClass) method.getParent()).getModifierList();
if ((parentModifierList != null && parentModifierList.hasExplicitModifier(Modifier.FINAL)) || ((PsiClass) method.getParent()).isEnum())
return true;
}
return false;
}
private static boolean isOverrideAnyMethodExceptMethodsFromObject(@NotNull PsiMethod method) {
int counter = 0;
for (HierarchicalMethodSignature s : method.getHierarchicalMethodSignature().getSuperSignatures()) {
@@ -418,14 +424,14 @@ public class Converter {
public static Type typeToType(PsiType type, boolean notNull) {
Type result = typeToType(type);
if (notNull)
result.convertToNotNull();
result.convertedToNotNull();
return result;
}
@NotNull
private static List<Type> typesToNotNullableTypeList(@NotNull PsiType[] types) {
List<Type> result = new LinkedList<Type>(typesToTypeList(types));
for (Type p : result) p.convertToNotNull();
for (Type p : result) p.convertedToNotNull();
return result;
}
@@ -9,7 +9,7 @@ import java.util.Set;
*/
public class EnumConstant extends Field {
public EnumConstant(Identifier identifier, Set<String> modifiers, Type type, Element params) {
super(identifier, modifiers, type, params);
super(identifier, modifiers, type.convertedToNotNull(), params);
}
@NotNull
@@ -17,6 +17,6 @@ public class EnumConstant extends Field {
public String toKotlin() {
if (myInitializer.toKotlin().isEmpty())
return myIdentifier.toKotlin();
return myIdentifier.toKotlin() + "(" + myInitializer.toKotlin() + ")";
return myIdentifier.toKotlin() + SPACE + COLON + SPACE + myType.toKotlin() + "(" + myInitializer.toKotlin() + ")";
}
}
+1 -1
View File
@@ -14,7 +14,7 @@ import static org.jetbrains.jet.j2k.Converter.getDefaultInitializer;
*/
public class Field extends Member {
final Identifier myIdentifier;
private final Type myType;
final Type myType;
final Element myInitializer;
public Field(Identifier identifier, Set<String> modifiers, Type type, Element initializer) {
+2 -1
View File
@@ -15,8 +15,9 @@ public abstract class Type extends Element {
return Kind.TYPE;
}
public void convertToNotNull() {
public Type convertedToNotNull() {
myNullable = false;
return this;
}
public boolean isNullable() {
+16
View File
@@ -0,0 +1,16 @@
package demo;
enum MyEnum {
RED(10),
BLUE(20);
private final int color;
private MyEnum(int _color) {
color = _color;
}
public int getColor() {
return color;
}
}
+14
View File
@@ -0,0 +1,14 @@
namespace demo
enum class MyEnum(_color : Int) {
{
$color = _color
}
RED : MyEnum(10)
BLUE : MyEnum(20)
private val color : Int = 0
public fun getColor() : Int {
return color
}
public fun name() : String { return "" }
public fun order() : Int { return 0 }
}
@@ -1,14 +1,16 @@
enum Color(c: Int) {
enum class Color(c : Int) {
{
$code = c
}
WHITE : Color(21)
BLACK : Color(22)
RED : Color(23)
YELLOW : Color(24)
BLUE : Color(25)
private var code : Int
{
$code = c
}
open public fun getCode() : Int {
private var code : Int = 0
public fun getCode() : Int {
return code
}
public fun name() : String { return "" }
public fun order() : Int { return 0 }
}
@@ -1,3 +1,5 @@
package demo;
enum Color {
private int code;
@@ -1,9 +1,10 @@
namespace demo
enum class Color(c : Int) {
{
$code = c
}
private var code : Int = 0
open public fun getCode() : Int {
public fun getCode() : Int {
return code
}
public fun name() : String { return "" }