KT-635 Import std.java.compatibility
This commit is contained in:
@@ -37,6 +37,14 @@ public class Converter {
|
||||
return new File(quoteKeywords(javaFile.getPackageName()), imports, classesToClassList(javaFile.getClasses()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File fileToFileWithCompatibilityImport(@NotNull PsiJavaFile javaFile) {
|
||||
final PsiImportList importList = javaFile.getImportList();
|
||||
List<Import> imports = importList == null ? Collections.<Import>emptyList() : importsToImportList(importList.getAllImportStatements());
|
||||
imports.add(new Import("std.java.compatibility.*"));
|
||||
return new File(quoteKeywords(javaFile.getPackageName()), imports, classesToClassList(javaFile.getClasses()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String quoteKeywords(@NotNull String packageName) {
|
||||
List<String> result = new LinkedList<String>();
|
||||
|
||||
@@ -47,6 +47,7 @@ public class JavaToKotlinConverterTest extends LightDaemonAnalyzerTestCase {
|
||||
else if (javaFile.getParent().endsWith("/method")) actual = methodToKotlin(javaCode);
|
||||
else if (javaFile.getParent().endsWith("/class")) actual = fileToKotlin(javaCode);
|
||||
else if (javaFile.getParent().endsWith("/file")) actual = fileToKotlin(javaCode);
|
||||
else if (javaFile.getParent().endsWith("/comp")) actual = fileToFileWithCompatibilityImport(javaCode);
|
||||
|
||||
assert !actual.isEmpty() : "Specify what is it: file, class, method, statement or expression";
|
||||
|
||||
@@ -100,9 +101,17 @@ public class JavaToKotlinConverterTest extends LightDaemonAnalyzerTestCase {
|
||||
private static void setClassIdentifiers() {
|
||||
ClassVisitor c = new ClassVisitor();
|
||||
myFile.accept(c);
|
||||
Converter.clearClassIdentifiers();
|
||||
Converter.setClassIdentifiers(c.getClassIdentifiers());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String fileToFileWithCompatibilityImport(String text) throws IOException {
|
||||
configureFromText(text);
|
||||
setClassIdentifiers();
|
||||
return prettify(Converter.fileToFileWithCompatibilityImport((PsiJavaFile) myFile).toKotlin());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String fileToKotlin(String text) throws IOException {
|
||||
configureFromText(text);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package demo;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
Integer i = 10;
|
||||
Integer j = 10;
|
||||
System.out.println(i + j);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace demo
|
||||
import std.java.compatibility.*
|
||||
open class Test() {
|
||||
open fun test() : Unit {
|
||||
var i : Int? = 10
|
||||
var j : Int? = 10
|
||||
System.out?.println((i + j))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user