override for methods supported
This commit is contained in:
@@ -97,12 +97,15 @@ public class Converter {
|
||||
@NotNull
|
||||
private static Function methodToFunction(PsiMethod method, boolean notEmpty) {
|
||||
final IdentifierImpl identifier = new IdentifierImpl(method.getName());
|
||||
final Set<String> modifiers = modifiersListToModifiersSet(method.getModifierList());
|
||||
final Type type = typeToType(method.getReturnType());
|
||||
final Block body = blockToBlock(method.getBody(), notEmpty);
|
||||
final Element params = elementToElement(method.getParameterList());
|
||||
final List<Element> typeParameters = elementsToElementList(method.getTypeParameters());
|
||||
|
||||
final Set<String> modifiers = modifiersListToModifiersSet(method.getModifierList());
|
||||
if (method.getHierarchicalMethodSignature().getSuperSignatures().size() > 0)
|
||||
modifiers.add(Modifier.OVERRIDE);
|
||||
|
||||
if (method.isConstructor())
|
||||
return new Constructor(
|
||||
identifier,
|
||||
|
||||
@@ -51,6 +51,9 @@ public class Function extends Member {
|
||||
private String modifiersToKotlin() {
|
||||
List<String> modifierList = new LinkedList<String>();
|
||||
|
||||
if (myModifiers.contains(Modifier.OVERRIDE))
|
||||
modifierList.add(Modifier.OVERRIDE);
|
||||
|
||||
modifierList.add(accessModifier());
|
||||
|
||||
if (modifierList.size() > 0)
|
||||
|
||||
@@ -4,12 +4,13 @@ package org.jetbrains.jet.j2k.ast;
|
||||
* @author ignatov
|
||||
*/
|
||||
public abstract class Modifier {
|
||||
public static String PUBLIC = "public";
|
||||
public static String PROTECTED = "protected";
|
||||
public static String PRIVATE = "private";
|
||||
public static String INTERNAL = "internal";
|
||||
public static String STATIC = "static";
|
||||
public static String ABSTRACT = "abstract";
|
||||
public static String FINAL = "final";
|
||||
public static String OPEN = "open";
|
||||
public static final String PUBLIC = "public";
|
||||
public static final String PROTECTED = "protected";
|
||||
public static final String PRIVATE = "private";
|
||||
public static final String INTERNAL = "internal";
|
||||
public static final String STATIC = "static";
|
||||
public static final String ABSTRACT = "abstract";
|
||||
public static final String FINAL = "final";
|
||||
public static final String OPEN = "open";
|
||||
public static final String OVERRIDE = "override";
|
||||
}
|
||||
|
||||
@@ -100,12 +100,16 @@ public abstract class JetTestCaseBase extends LightDaemonAnalyzerTestCase {
|
||||
return toSingleLine(classToKotlin(text));
|
||||
}
|
||||
|
||||
String fileToKotlin(String text) throws IOException {
|
||||
protected String fileToKotlin(String text) throws IOException {
|
||||
configureFromText(text);
|
||||
return prettify(Converter.fileToFile((PsiJavaFile) myFile).toKotlin());
|
||||
}
|
||||
|
||||
String methodToKotlin(String text) throws IOException {
|
||||
protected String fileToSingleLineKotlin(String text) throws IOException {
|
||||
return toSingleLine(fileToKotlin(text));
|
||||
}
|
||||
|
||||
protected String methodToKotlin(String text) throws IOException {
|
||||
String result = classToKotlin("final class C {" + text + "}")
|
||||
.replaceAll("class C \\{", "");
|
||||
result = result.substring(0, result.lastIndexOf("}"));
|
||||
|
||||
@@ -78,4 +78,10 @@ public class FunctionTest extends JetTestCaseBase {
|
||||
public void testPublic() throws Exception {
|
||||
Assert.assertEquals(methodToSingleLineKotlin("public void test() {}"), "public fun test() : Unit { }");
|
||||
}
|
||||
|
||||
public void testOverride() throws Exception {
|
||||
Assert.assertEquals(fileToSingleLineKotlin("class A {void a() {}} final class B extends A {void a() {}}"),
|
||||
"namespace { open class A { fun a() : Unit { } } class B : A { override fun a() : Unit { } } }");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user