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
@Override
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 +
AstUtil.joinNodes(myImports, N) + N2 +
AstUtil.joinNodes(myClasses, N) + N +
common +
"}";
}
}
@@ -44,7 +44,7 @@ public class JavaToKotlinConverterTest extends LightDaemonAnalyzerTestCase {
if (javaFile.getParent().endsWith("/expression")) actual = expressionToKotlin(javaCode);
else if (javaFile.getParent().endsWith("/statement")) actual = statementToKotlin(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);
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);
}
@NotNull
protected String fileToKotlin(String text) throws IOException {
configureFromText(text);
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
protected String methodToKotlin(String text) throws IOException {
String result = classToKotlin("final class C {" + text + "}")
String result = fileToKotlin("final class C {" + text + "}")
.replaceAll("class C\\(\\) \\{", "");
result = result.substring(0, result.lastIndexOf("}"));
return prettify(result);
@@ -1,4 +1,3 @@
namespace {
open class Library() {
class object {
val ourOut : PrintStream?
@@ -8,5 +7,4 @@ open class User() {
open fun main() : Unit {
Library.ourOut?.print()
}
}
}
@@ -1,4 +1,3 @@
namespace {
open class Library() {
class object {
open fun call() : Unit {
@@ -13,5 +12,4 @@ open fun main() : Unit {
Library.call()
Library.getString()?.isEmpty()
}
}
}
@@ -1,4 +1,3 @@
namespace {
open class Library() {
open fun call() : Unit {
}
@@ -14,5 +13,4 @@ lib?.getString()?.isEmpty()
Library().call()
Library().getString()?.isEmpty()
}
}
}
@@ -1,4 +1,3 @@
namespace {
open class Library() {
public val myString : String?
}
@@ -6,5 +5,4 @@ open class User() {
open fun main() : Unit {
Library.myString?.isEmpty()
}
}
}
-2
View File
@@ -1,6 +1,4 @@
namespace {
public open class MyClass() {
open private fun init(arg1 : Int, arg2 : Int, arg3 : Int) : Unit {
}
}
}
@@ -1,6 +1,4 @@
namespace {
class A() {
}
class B() {
}
}
-2
View File
@@ -1,4 +1,3 @@
namespace {
open class A() {
open fun a() : Unit {
}
@@ -6,5 +5,4 @@ open fun a() : Unit {
class B() : A {
override fun a() : Unit {
}
}
}
@@ -1,4 +1,3 @@
namespace {
open class A() {
open fun foo() : Unit {
}
@@ -10,5 +9,4 @@ override fun foo() : Unit {
open class C() : B {
override fun foo() : Unit {
}
}
}
@@ -1,4 +1,3 @@
namespace {
open class Base() {
open fun foo() : Unit
}
@@ -8,5 +7,4 @@ open fun test() : Unit {
super@A.foo()
}
}
}
}
@@ -1,4 +1,3 @@
namespace {
open class Base() {
open fun foo() : Unit {
}
@@ -9,5 +8,4 @@ open fun test() : Unit {
this@A.foo()
}
}
}
}