anonymous packages supported

This commit is contained in:
Sergey Ignatov
2011-11-08 14:35:31 +04:00
parent 39112d6327
commit 76995743d8
12 changed files with 7 additions and 35 deletions
+4 -2
View File
@@ -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?
@@ -9,4 +8,3 @@ 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 {
@@ -14,4 +13,3 @@ 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 {
} }
@@ -15,4 +14,3 @@ 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?
} }
@@ -7,4 +6,3 @@ open fun main() : Unit {
Library.myString?.isEmpty() Library.myString?.isEmpty()
} }
} }
}
-2
View File
@@ -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() {
} }
}
-2
View File
@@ -1,4 +1,3 @@
namespace {
open class A() { open class A() {
open fun a() : Unit { open fun a() : Unit {
} }
@@ -7,4 +6,3 @@ 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 {
} }
@@ -11,4 +10,3 @@ 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
} }
@@ -9,4 +8,3 @@ super@A.foo()
} }
} }
} }
}
@@ -1,4 +1,3 @@
namespace {
open class Base() { open class Base() {
open fun foo() : Unit { open fun foo() : Unit {
} }
@@ -10,4 +9,3 @@ this@A.foo()
} }
} }
} }
}