anonymous packages supported
This commit is contained in:
@@ -22,9 +22,11 @@ public class File extends Node {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String toKotlin() {
|
public String toKotlin() {
|
||||||
|
final String common = AstUtil.joinNodes(myImports, N) + N2 + AstUtil.joinNodes(myClasses, N) + N;
|
||||||
|
if (myPackageName.isEmpty())
|
||||||
|
return common;
|
||||||
return "namespace" + SPACE + myPackageName + SPACE + "{" + N +
|
return "namespace" + SPACE + myPackageName + SPACE + "{" + N +
|
||||||
AstUtil.joinNodes(myImports, N) + N2 +
|
common +
|
||||||
AstUtil.joinNodes(myClasses, N) + N +
|
|
||||||
"}";
|
"}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class JavaToKotlinConverterTest extends LightDaemonAnalyzerTestCase {
|
|||||||
if (javaFile.getParent().endsWith("/expression")) actual = expressionToKotlin(javaCode);
|
if (javaFile.getParent().endsWith("/expression")) actual = expressionToKotlin(javaCode);
|
||||||
else if (javaFile.getParent().endsWith("/statement")) actual = statementToKotlin(javaCode);
|
else if (javaFile.getParent().endsWith("/statement")) actual = statementToKotlin(javaCode);
|
||||||
else if (javaFile.getParent().endsWith("/method")) actual = methodToKotlin(javaCode);
|
else if (javaFile.getParent().endsWith("/method")) actual = methodToKotlin(javaCode);
|
||||||
else if (javaFile.getParent().endsWith("/class")) actual = classToKotlin(javaCode);
|
else if (javaFile.getParent().endsWith("/class")) actual = fileToKotlin(javaCode);
|
||||||
else if (javaFile.getParent().endsWith("/file")) actual = fileToKotlin(javaCode);
|
else if (javaFile.getParent().endsWith("/file")) actual = fileToKotlin(javaCode);
|
||||||
|
|
||||||
assert !actual.equals("") : "Specify what is it: file, class, method, statement or expression";
|
assert !actual.equals("") : "Specify what is it: file, class, method, statement or expression";
|
||||||
@@ -100,25 +100,15 @@ public class JavaToKotlinConverterTest extends LightDaemonAnalyzerTestCase {
|
|||||||
configureFromFileText("test.java", text);
|
configureFromFileText("test.java", text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
protected String fileToKotlin(String text) throws IOException {
|
protected String fileToKotlin(String text) throws IOException {
|
||||||
configureFromText(text);
|
configureFromText(text);
|
||||||
return prettify(Converter.fileToFile((PsiJavaFile) myFile).toKotlin());
|
return prettify(Converter.fileToFile((PsiJavaFile) myFile).toKotlin());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
protected String classToKotlin(String text) throws IOException {
|
|
||||||
configureFromText(text);
|
|
||||||
|
|
||||||
PsiJavaFile javaFile = (PsiJavaFile) myFile;
|
|
||||||
|
|
||||||
String result = prettify(Converter.fileToFile(javaFile).toKotlin()).replaceAll("namespace \\{", "");
|
|
||||||
result = result.substring(0, result.lastIndexOf("}"));
|
|
||||||
return prettify(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected String methodToKotlin(String text) throws IOException {
|
protected String methodToKotlin(String text) throws IOException {
|
||||||
String result = classToKotlin("final class C {" + text + "}")
|
String result = fileToKotlin("final class C {" + text + "}")
|
||||||
.replaceAll("class C\\(\\) \\{", "");
|
.replaceAll("class C\\(\\) \\{", "");
|
||||||
result = result.substring(0, result.lastIndexOf("}"));
|
result = result.substring(0, result.lastIndexOf("}"));
|
||||||
return prettify(result);
|
return prettify(result);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
namespace {
|
|
||||||
open class Library() {
|
open class Library() {
|
||||||
class object {
|
class object {
|
||||||
val ourOut : PrintStream?
|
val ourOut : PrintStream?
|
||||||
@@ -8,5 +7,4 @@ open class User() {
|
|||||||
open fun main() : Unit {
|
open fun main() : Unit {
|
||||||
Library.ourOut?.print()
|
Library.ourOut?.print()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
namespace {
|
|
||||||
open class Library() {
|
open class Library() {
|
||||||
class object {
|
class object {
|
||||||
open fun call() : Unit {
|
open fun call() : Unit {
|
||||||
@@ -13,5 +12,4 @@ open fun main() : Unit {
|
|||||||
Library.call()
|
Library.call()
|
||||||
Library.getString()?.isEmpty()
|
Library.getString()?.isEmpty()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
namespace {
|
|
||||||
open class Library() {
|
open class Library() {
|
||||||
open fun call() : Unit {
|
open fun call() : Unit {
|
||||||
}
|
}
|
||||||
@@ -14,5 +13,4 @@ lib?.getString()?.isEmpty()
|
|||||||
Library().call()
|
Library().call()
|
||||||
Library().getString()?.isEmpty()
|
Library().getString()?.isEmpty()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
namespace {
|
|
||||||
open class Library() {
|
open class Library() {
|
||||||
public val myString : String?
|
public val myString : String?
|
||||||
}
|
}
|
||||||
@@ -6,5 +5,4 @@ open class User() {
|
|||||||
open fun main() : Unit {
|
open fun main() : Unit {
|
||||||
Library.myString?.isEmpty()
|
Library.myString?.isEmpty()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace {
|
|
||||||
public open class MyClass() {
|
public open class MyClass() {
|
||||||
open private fun init(arg1 : Int, arg2 : Int, arg3 : Int) : Unit {
|
open private fun init(arg1 : Int, arg2 : Int, arg3 : Int) : Unit {
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace {
|
|
||||||
class A() {
|
class A() {
|
||||||
}
|
}
|
||||||
class B() {
|
class B() {
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
namespace {
|
|
||||||
open class A() {
|
open class A() {
|
||||||
open fun a() : Unit {
|
open fun a() : Unit {
|
||||||
}
|
}
|
||||||
@@ -6,5 +5,4 @@ open fun a() : Unit {
|
|||||||
class B() : A {
|
class B() : A {
|
||||||
override fun a() : Unit {
|
override fun a() : Unit {
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
namespace {
|
|
||||||
open class A() {
|
open class A() {
|
||||||
open fun foo() : Unit {
|
open fun foo() : Unit {
|
||||||
}
|
}
|
||||||
@@ -10,5 +9,4 @@ override fun foo() : Unit {
|
|||||||
open class C() : B {
|
open class C() : B {
|
||||||
override fun foo() : Unit {
|
override fun foo() : Unit {
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
namespace {
|
|
||||||
open class Base() {
|
open class Base() {
|
||||||
open fun foo() : Unit
|
open fun foo() : Unit
|
||||||
}
|
}
|
||||||
@@ -8,5 +7,4 @@ open fun test() : Unit {
|
|||||||
super@A.foo()
|
super@A.foo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
namespace {
|
|
||||||
open class Base() {
|
open class Base() {
|
||||||
open fun foo() : Unit {
|
open fun foo() : Unit {
|
||||||
}
|
}
|
||||||
@@ -9,5 +8,4 @@ open fun test() : Unit {
|
|||||||
this@A.foo()
|
this@A.foo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user