abstract modifier added for classes and methods
This commit is contained in:
@@ -126,6 +126,8 @@ public class Converter {
|
||||
final Set<String> modifiers = modifiersListToModifiersSet(method.getModifierList());
|
||||
if (method.getHierarchicalMethodSignature().getSuperSignatures().size() > 0)
|
||||
modifiers.add(Modifier.OVERRIDE);
|
||||
if (method.getParent() instanceof PsiClass && ((PsiClass) method.getParent()).isInterface())
|
||||
modifiers.remove(Modifier.ABSTRACT);
|
||||
|
||||
if (method.isConstructor())
|
||||
return new Constructor(
|
||||
@@ -288,6 +290,7 @@ public class Converter {
|
||||
public static Set<String> modifiersListToModifiersSet(PsiModifierList modifierList) {
|
||||
HashSet<String> modifiersSet = new HashSet<String>();
|
||||
if (modifierList != null) {
|
||||
if (modifierList.hasModifierProperty(PsiModifier.ABSTRACT)) modifiersSet.add(Modifier.ABSTRACT);
|
||||
if (modifierList.hasModifierProperty(PsiModifier.FINAL)) modifiersSet.add(Modifier.FINAL);
|
||||
if (modifierList.hasModifierProperty(PsiModifier.STATIC)) modifiersSet.add(Modifier.STATIC);
|
||||
if (modifierList.hasModifierProperty(PsiModifier.PUBLIC)) modifiersSet.add(Modifier.PUBLIC);
|
||||
|
||||
@@ -76,6 +76,9 @@ public class Class extends Member {
|
||||
String modifiersToKotlin() {
|
||||
List<String> modifierList = new LinkedList<String>();
|
||||
|
||||
if (needAbstractModifier())
|
||||
modifierList.add(Modifier.ABSTRACT);
|
||||
|
||||
modifierList.add(accessModifier());
|
||||
|
||||
if (needOpenModifier())
|
||||
@@ -91,6 +94,10 @@ public class Class extends Member {
|
||||
return !myModifiers.contains(Modifier.FINAL);
|
||||
}
|
||||
|
||||
boolean needAbstractModifier() {
|
||||
return isAbstract();
|
||||
}
|
||||
|
||||
String bodyToKotlin() {
|
||||
return classObjectToKotlin() + N +
|
||||
AstUtil.joinNodes(getNonStatic(myFields), N) + N +
|
||||
|
||||
@@ -25,6 +25,9 @@ public class Field extends Member {
|
||||
String modifiersToKotlin() {
|
||||
List<String> modifierList = new LinkedList<String>();
|
||||
|
||||
if (isAbstract())
|
||||
modifierList.add(Modifier.ABSTRACT);
|
||||
|
||||
modifierList.add(accessModifier());
|
||||
|
||||
modifierList.add(myModifiers.contains(Modifier.FINAL) ? "val" : "var");
|
||||
|
||||
@@ -51,6 +51,9 @@ public class Function extends Member {
|
||||
String modifiersToKotlin() {
|
||||
List<String> modifierList = new LinkedList<String>();
|
||||
|
||||
if (isAbstract())
|
||||
modifierList.add(Modifier.ABSTRACT);
|
||||
|
||||
if (myModifiers.contains(Modifier.OVERRIDE))
|
||||
modifierList.add(Modifier.OVERRIDE);
|
||||
|
||||
|
||||
@@ -5,4 +5,6 @@ package org.jetbrains.jet.j2k.ast;
|
||||
*/
|
||||
public interface IMember extends INode {
|
||||
public boolean isStatic();
|
||||
|
||||
boolean isAbstract();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ public abstract class Member extends Node implements IMember {
|
||||
return EMPTY; // package local converted to internal, but we use internal by default
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstract() {
|
||||
return myModifiers.contains(Modifier.ABSTRACT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStatic() {
|
||||
return myModifiers.contains(Modifier.STATIC);
|
||||
|
||||
@@ -17,4 +17,8 @@ public class Trait extends Class {
|
||||
boolean needOpenModifier() {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean needAbstractModifier() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,10 @@ public class JavaToKotlinConverterTest extends LightDaemonAnalyzerTestCase {
|
||||
String javaPath = getTestDataPath() + File.separator + getTestFilePath();
|
||||
String kotlinPath = javaPath.replace(".jav", ".kt");
|
||||
|
||||
final String expected = readFileToString(new File(kotlinPath));
|
||||
final File kotlinFile = new File(kotlinPath);
|
||||
if (!kotlinFile.exists())
|
||||
writeStringToFile(kotlinFile, "");
|
||||
final String expected = readFileToString(kotlinFile);
|
||||
final File javaFile = new File(javaPath);
|
||||
final String javaCode = readFileToString(javaFile);
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
abstract class A {
|
||||
abstract void callme();
|
||||
|
||||
void callmetoo() {
|
||||
print("This is a concrete method.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
abstract open class A {
|
||||
abstract fun callme() : Unit
|
||||
fun callmetoo() : Unit {
|
||||
print("This is a concrete method.")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
abstract class Shape {
|
||||
public String color;
|
||||
public Shape() {
|
||||
}
|
||||
public void setColor(String c) {
|
||||
color = c;
|
||||
}
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
abstract public double area();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
abstract open class Shape {
|
||||
public var color : String?
|
||||
public fun setColor(c : String?) : Unit {
|
||||
color = c
|
||||
}
|
||||
public fun getColor() : String? {
|
||||
return color
|
||||
}
|
||||
abstract public fun area() : Double
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
abstract int getNoofGears();
|
||||
@@ -0,0 +1 @@
|
||||
abstract fun getNoofGears() : Int
|
||||
Reference in New Issue
Block a user