Java to Kotlin converter: keep original placement of primary constructor body + better preserving of comments for constructor

This commit is contained in:
Valentin Kipyatkov
2014-06-25 17:44:38 +04:00
parent 88bdbb02f4
commit 947bf3c0ed
18 changed files with 184 additions and 93 deletions
@@ -5,6 +5,10 @@ package test
public class Test(str: String) {
var myStr = "String2"
{
myStr = str
}
public fun sout(str: String) {
System.out!!.println(str)
}
@@ -21,8 +25,4 @@ public class Test(str: String) {
Test(test)
}
{
myStr = str
}
}
@@ -4,6 +4,10 @@ package test
public class Test(str: String?) {
var myStr: String? = "String2"
{
myStr = str
}
public fun sout(str: String?) {
System.out.println(str)
}
@@ -20,8 +24,4 @@ public class Test(str: String?) {
Test(test)
}
{
myStr = str
}
}
@@ -0,0 +1,25 @@
//file
class A {
private int v;
// this is a primary constructor
A(int p) {
v = 1;
} // end of primary constructor body
// this is a secondary constructor
A() {
this(1);
} // end of secondary constructor body
}
class B {
private int x;
// this constructor will disappear
B(int x) {
this.x = x;
} // end of constructor body
void foo(){}
}
@@ -0,0 +1,25 @@
class A// this is a primary constructor
(p: Int) {
private val v: Int
{
v = 1
} // end of primary constructor body
class object {
// this is a secondary constructor
fun create(): A {
val __ = A(1)
return __
} // end of secondary constructor body
}
}
class B// this constructor will disappear
(private val x: Int) // end of constructor body
{
fun foo() {
}
}
@@ -2,6 +2,11 @@ package org.test.customer
class Customer(public val _firstName: String, public val _lastName: String) {
{
doSmthBefore()
doSmthAfter()
}
public fun getFirstName(): String {
return _firstName
}
@@ -14,11 +19,6 @@ class Customer(public val _firstName: String, public val _lastName: String) {
}
private fun doSmthAfter() {
}
{
doSmthBefore()
doSmthAfter()
}
}
class CustomerBuilder() {
@@ -1,4 +1,5 @@
class C(private val field: Int) {
{
System.out.println(field)
}
+4 -4
View File
@@ -9,10 +9,6 @@ class A(private val field6: Int, private val field8: Int, a: A) {
private var field10: Int = 0
private var field11: Int = 0
fun foo() {
field3 = field2
}
{
field7 = 10
this.field9 = 10
@@ -21,4 +17,8 @@ class A(private val field6: Int, private val field8: Int, a: A) {
}
a.field11 = 10
}
fun foo() {
field3 = field2
}
}
+1 -2
View File
@@ -1,9 +1,8 @@
package demo
class C(a: Int) {
var abc = 0
{
abc = a * 2
}
var abc = 0
}
@@ -1,4 +1,5 @@
class C(private val s: String?) {
{
if (s == null) {
System.out.print("null")