Java to Kotlin convertor: generating of val/var constructor parameters when possible

This commit is contained in:
Valentin Kipyatkov
2014-06-02 22:03:33 +04:00
parent 846f2d9954
commit abfd2d68b9
90 changed files with 820 additions and 734 deletions
@@ -1,10 +1,8 @@
class C(arg1: Int) {
val myArg1: Int
class C(val myArg1: Int) {
var myArg2: Int = 0
var myArg3: Int = 0
{
myArg1 = arg1
myArg2 = 0
myArg3 = 0
}
@@ -1,10 +1,8 @@
open class C(arg1: Int) {
val myArg1: Int
open class C(val myArg1: Int) {
var myArg2: Int = 0
var myArg3: Int = 0
{
myArg1 = arg1
myArg2 = 0
myArg3 = 0
}
@@ -1,8 +1,6 @@
package org.test.customer
class Customer(first: String, last: String) {
public val _firstName: String
public val _lastName: String
class Customer(public val _firstName: String, public val _lastName: String) {
public fun getFirstName(): String {
return _firstName
@@ -19,8 +17,6 @@ class Customer(first: String, last: String) {
{
doSmthBefore()
_firstName = first
_lastName = last
doSmthAfter()
}
}
@@ -1,8 +1,6 @@
package org.test.customer
open class Customer(first: String?, last: String?) {
public val _firstName: String?
public val _lastName: String?
open class Customer(public val _firstName: String?, public val _lastName: String?) {
public open fun getFirstName(): String? {
return _firstName
@@ -19,8 +17,6 @@ open class Customer(first: String?, last: String?) {
{
doSmthBefore()
_firstName = first
_lastName = last
doSmthAfter()
}
}
@@ -0,0 +1 @@
class C(private val p1: Int, private val myP2: Int, public var p3: Int) {}
@@ -0,0 +1,12 @@
//file
class C {
private final int p1;
private final int myP2;
public int p3;
public C(int p1, int p2, int p3) {
this.p1 = p1;
myP2 = p2;
this.p3 = p3;
}
}
@@ -0,0 +1 @@
open class C(private val p1: Int, private val myP2: Int, public var p3: Int) {}
@@ -0,0 +1,5 @@
class C(private val field: Int) {
{
System.out.println(field)
}
}
@@ -0,0 +1,9 @@
//file
class C {
private final int field;
public C(int p) {
field = p
System.out.println(p);
}
}
@@ -0,0 +1,5 @@
open class C(private val field: Int) {
{
System.out?.println(field)
}
}
@@ -0,0 +1,9 @@
class C(p: Int) {
private val p: Int
{
this.p = p
System.out.println(p++)
System.out.println(p)
}
}
@@ -0,0 +1,10 @@
//file
class C {
private final int p;
public C(int p) {
this.p = p
System.out.println(p++);
System.out.println(p);
}
}
@@ -0,0 +1,9 @@
open class C(p: Int) {
private val p: Int
{
this.p = p
System.out?.println(p++)
System.out?.println(p)
}
}
@@ -0,0 +1,7 @@
class C(p: Int, c: C) {
public var p: Int = 0
{
c.p = p
}
}
@@ -0,0 +1,8 @@
//file
class C {
public int p;
public C(int p, C c) {
c.p = p;
}
}
@@ -0,0 +1,7 @@
open class C(p: Int, c: C?) {
public var p: Int = 0
{
c?.p = p
}
}
@@ -0,0 +1,10 @@
class C(p: Int) {
public var p: Int = 0
{
this.p = 0
if (p > 0) {
this.p = p
}
}
}
@@ -0,0 +1,11 @@
//file
class C {
public int p;
public C(int p) {
this.p = 0
if (p > 0) {
this.p = p
}
}
}
@@ -0,0 +1,10 @@
open class C(p: Int) {
public var p: Int = 0
{
this.p = 0
if (p > 0) {
this.p = p
}
}
}
@@ -0,0 +1,7 @@
class C(x: String) {
public var x: Any = 0
{
this.x = x
}
}
@@ -0,0 +1,8 @@
//file
class C {
public Object x;
public C(String x) {
this.x = x;
}
}
@@ -0,0 +1,7 @@
open class C(x: String?) {
public var x: Any? = null
{
this.x = x
}
}
@@ -0,0 +1,9 @@
class C(x: Any, b: Boolean) {
public var x: Any = 0
{
if (b) {
this.x = x
}
}
}
@@ -0,0 +1,10 @@
//file
class C {
public Object x;
public C(Object x, boolean b) {
if (b) {
this.x = x;
}
}
}
@@ -0,0 +1,9 @@
open class C(x: Any?, b: Boolean) {
public var x: Any? = null
{
if (b) {
this.x = x
}
}
}
+1 -7
View File
@@ -1,16 +1,10 @@
package demo
enum class MyEnum(_color: Int) {
enum class MyEnum(private val color: Int) {
RED : MyEnum(10)
BLUE : MyEnum(20)
private val color: Int
public fun getColor(): Int {
return color
}
{
color = _color
}
}
+1 -7
View File
@@ -1,16 +1,10 @@
package demo
enum class MyEnum(_color: Int) {
enum class MyEnum(private val color: Int) {
RED : MyEnum(10)
BLUE : MyEnum(20)
private val color: Int
public fun getColor(): Int {
return color
}
{
color = _color
}
}
@@ -1,17 +1,11 @@
enum class Color(c: Int) {
enum class Color(private var code: Int) {
WHITE : Color(21)
BLACK : Color(22)
RED : Color(23)
YELLOW : Color(24)
BLUE : Color(25)
private var code: Int = 0
public fun getCode(): Int {
return code
}
{
code = c
}
}
@@ -1,13 +1,14 @@
//class
enum Color {
WHITE(21), BLACK(22), RED(23), YELLOW(24), BLUE(25);
WHITE(21), BLACK(22), RED(23), YELLOW(24), BLUE(25);
private int code;
private int code;
private Color(int c) {
code = c;
}
private Color(int c) {
code = c;
}
public int getCode() {
return code;
}
public int getCode() {
return code;
}
}
@@ -1,17 +1,11 @@
enum class Color(c: Int) {
enum class Color(private var code: Int) {
WHITE : Color(21)
BLACK : Color(22)
RED : Color(23)
YELLOW : Color(24)
BLUE : Color(25)
private var code: Int = 0
public fun getCode(): Int {
return code
}
{
code = c
}
}
@@ -1,13 +1,8 @@
package demo
enum class Color(c: Int) {
private var code: Int = 0
enum class Color(private var code: Int) {
public fun getCode(): Int {
return code
}
{
code = c
}
}
@@ -1,13 +1,8 @@
package demo
enum class Color(c: Int) {
private var code: Int = 0
enum class Color(private var code: Int) {
public fun getCode(): Int {
return code
}
{
code = c
}
}
@@ -1,7 +1,7 @@
package demo
class Test() {
fun test(vararg var args: Any) {
fun test(vararg args: Any) {
args = array<Int>(1, 2, 3)
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
package demo
open class Test() {
open fun test(vararg var args: Any?) {
open fun test(vararg args: Any?) {
args = array<Int?>(1, 2, 3)
}
}
@@ -1,7 +1,7 @@
package demo
class Test() {
fun test(var i: Int): Int {
fun test(i: Int): Int {
i = 10
return i + 20
}
@@ -1,7 +1,7 @@
package demo
open class Test() {
open fun test(var i: Int): Int {
open fun test(i: Int): Int {
i = 10
return i + 20
}
@@ -2,14 +2,9 @@ class `$$$$$`() {}
class `$`() {}
class `$$`(`$$$$`: `$$$$$`) : `$`() {
val `$$$`: `$$$$$`
class `$$`(val `$$$`: `$$$$$`) : `$`() {
public fun `$$$$$$`(): `$$$$$` {
return `$$$`
}
{
`$$$` = `$$$$`
}
}
@@ -2,14 +2,9 @@ open class `$$$$$`() {}
open class `$`() {}
open class `$$`(`$$$$`: `$$$$$`?) : `$`() {
val `$$$`: `$$$$$`?
open class `$$`(val `$$$`: `$$$$$`?) : `$`() {
public open fun `$$$$$$`(): `$$$$$`? {
return `$$$`
}
{
`$$$` = `$$$$`
}
}
@@ -1,9 +1,3 @@
class Base<T>(name: T) {}
class One<T, K>(name: T, second: K) : Base<T>(name) {
private var mySecond: K = 0
{
mySecond = second
}
}
class One<T, K>(name: T, private var mySecond: K) : Base<T>(name) {}
@@ -1,9 +1,3 @@
open class Base<T>(name: T?) {}
open class One<T, K>(name: T?, second: K?) : Base<T?>(name) {
private var mySecond: K? = null
{
mySecond = second
}
}
open class One<T, K>(name: T?, private var mySecond: K?) : Base<T?>(name) {}
@@ -1,9 +1,3 @@
class Base(name: String) {}
class One(name: String, second: String) : Base(name) {
private var mySecond: String = 0
{
mySecond = second
}
}
class One(name: String, private var mySecond: String) : Base(name) {}
@@ -1,9 +1,3 @@
open class Base(name: String?) {}
open class One(name: String?, second: String?) : Base(name) {
private var mySecond: String? = null
{
mySecond = second
}
}
open class One(name: String?, private var mySecond: String?) : Base(name) {}
+1 -7
View File
@@ -1,9 +1,3 @@
package demo
class C(i: Int) {
private val i: Int
{
this.i = i
}
}
class C(private val i: Int) {}
+1 -7
View File
@@ -1,9 +1,3 @@
package demo
open class C(i: Int) {
private val i: Int
{
this.i = i
}
}
open class C(private val i: Int) {}
+1 -6
View File
@@ -2,16 +2,11 @@ package com.voltvoodoo.saplo4j.model
import java.io.Serializable
public class Language(code: String) : Serializable {
protected var code: String = 0
public class Language(protected var code: String) : Serializable {
override fun toString(): String {
return this.code
}
{
this.code = code
}
}
+1 -6
View File
@@ -2,16 +2,11 @@ package com.voltvoodoo.saplo4j.model
import java.io.Serializable
public open class Language(code: String?) : Serializable {
protected var code: String? = null
public open class Language(protected var code: String?) : Serializable {
override fun toString(): String? {
return this.code
}
{
this.code = code
}
}
+2 -7
View File
@@ -2,21 +2,16 @@ package com.voltvoodoo.saplo4j.model
import java.io.Serializable
public class Language(code: String) : Serializable {
protected var code: String = 0
public class Language(protected var code: String) : Serializable {
public fun equals(other: Language): Boolean {
return other.toString().equals(this.toString())
}
{
this.code = code
}
class object {
public var ENGLISH: Language = Language("en")
public var SWEDISH: Language = Language("sv")
private val serialVersionUID: Long = -2442762969929206780
}
}
+2 -7
View File
@@ -2,21 +2,16 @@ package com.voltvoodoo.saplo4j.model
import java.io.Serializable
public open class Language(code: String?) : Serializable {
protected var code: String? = null
public open class Language(protected var code: String?) : Serializable {
public open fun equals(other: Language?): Boolean {
return other?.toString()?.equals(this.toString())!!
}
{
this.code = code
}
class object {
public var ENGLISH: Language? = Language("en")
public var SWEDISH: Language? = Language("sv")
private val serialVersionUID: Long = -2442762969929206780
}
}