Converter from Java: generate "create" for factory methods instead of "init"

This commit is contained in:
Valentin Kipyatkov
2014-06-11 18:47:02 +04:00
parent da5fe7adb0
commit 93ba66b2a3
10 changed files with 38 additions and 38 deletions
@@ -58,7 +58,7 @@ class SecondaryConstructor(converter: Converter,
val block = Block(statements)
val typeParameters = ArrayList<TypeParameter>()
typeParameters.addAll(containingClass.typeParameterList.parameters)
return Function(converter, Identifier("init"), MemberComments.Empty, modifiers,
return Function(converter, Identifier("create"), MemberComments.Empty, modifiers,
ClassType(containingClass.name, typeParameters, Nullability.NotNull, converter.settings),
TypeParameterList(typeParameters), parameterList, block, false)
}
@@ -262,7 +262,7 @@ class ExpressionVisitor(private val converter: Converter,
val reference = expression.getClassReference()
val typeParameters = if (reference != null) typeConverter.convertTypes(reference.getTypeParameters()) else listOf()
return QualifiedExpression(Identifier(constructor.getName(), false),
MethodCallExpression.buildNotNull(null, "init", converter.convertExpressions(arguments), typeParameters))
MethodCallExpression.buildNotNull(null, "create", converter.convertExpressions(arguments), typeParameters))
}
return NewClassExpression(converter.convertElement(classReference),
+4 -4
View File
@@ -4,11 +4,11 @@ import java.util.HashMap
class Test private() {
class object {
fun init(): Test {
fun create(): Test {
val __ = Test()
return __
}
fun init(s: String): Test {
fun create(s: String): Test {
val __ = Test()
return __
}
@@ -20,7 +20,7 @@ class User() {
val m = HashMap(1)
val m2 = HashMap(10)
val t1 = Test.init()
val t2 = Test.init("")
val t1 = Test.create()
val t2 = Test.create("")
}
}
@@ -1,12 +1,12 @@
class C(arg1: Int, arg2: Int, arg3: Int) {
class object {
fun init(arg1: Int, arg2: Int): C {
fun create(arg1: Int, arg2: Int): C {
val __ = C(arg1, arg2, 0)
return __
}
fun init(arg1: Int): C {
fun create(arg1: Int): C {
val __ = C(arg1, 0, 0)
return __
}
@@ -17,8 +17,8 @@ public class User() {
class object {
public fun main() {
val c1 = C(100, 100, 100)
val c2 = C.init(100, 100)
val c3 = C.init(100)
val c2 = C.create(100, 100)
val c3 = C.create(100)
}
}
}
@@ -9,14 +9,14 @@ class C(val myArg1: Int) {
class object {
fun init(arg1: Int, arg2: Int, arg3: Int): C {
fun create(arg1: Int, arg2: Int, arg3: Int): C {
val __ = C(arg1)
__.myArg2 = arg2
__.myArg3 = arg3
return __
}
fun init(arg1: Int, arg2: Int): C {
fun create(arg1: Int, arg2: Int): C {
val __ = C(arg1)
__.myArg2 = arg2
__.myArg3 = 0
@@ -28,8 +28,8 @@ class C(val myArg1: Int) {
public class User() {
class object {
public fun main() {
val c1 = C.init(100, 100, 100)
val c2 = C.init(100, 100)
val c1 = C.create(100, 100, 100)
val c2 = C.create(100, 100)
val c3 = C(100)
}
}
@@ -7,18 +7,18 @@ public class Identifier<T> private(private val myName: T, private var myHasDolla
class object {
public fun <T> init(name: T): Identifier<T> {
public fun <T> create(name: T): Identifier<T> {
val __ = Identifier(name, false)
return __
}
public fun <T> init(name: T, isNullable: Boolean): Identifier<T> {
public fun <T> create(name: T, isNullable: Boolean): Identifier<T> {
val __ = Identifier(name, false)
__.myNullable = isNullable
return __
}
public fun <T> init(name: T, hasDollar: Boolean, isNullable: Boolean): Identifier<T> {
public fun <T> create(name: T, hasDollar: Boolean, isNullable: Boolean): Identifier<T> {
val __ = Identifier(name, hasDollar)
__.myNullable = isNullable
return __
@@ -29,9 +29,9 @@ public class Identifier<T> private(private val myName: T, private var myHasDolla
public class User() {
class object {
public fun main() {
val i1 = Identifier.init<String>("name", false, true)
val i2 = Identifier.init<String>("name", false)
val i3 = Identifier.init<String>("name")
val i1 = Identifier.create<String>("name", false, true)
val i2 = Identifier.create<String>("name", false)
val i3 = Identifier.create<String>("name")
}
}
}
@@ -7,18 +7,18 @@ public class Identifier private(private val myName: String, private var myHasDol
class object {
public fun init(name: String): Identifier {
public fun create(name: String): Identifier {
val __ = Identifier(name, false)
return __
}
public fun init(name: String, isNullable: Boolean): Identifier {
public fun create(name: String, isNullable: Boolean): Identifier {
val __ = Identifier(name, false)
__.myNullable = isNullable
return __
}
public fun init(name: String, hasDollar: Boolean, isNullable: Boolean): Identifier {
public fun create(name: String, hasDollar: Boolean, isNullable: Boolean): Identifier {
val __ = Identifier(name, hasDollar)
__.myNullable = isNullable
return __
@@ -29,9 +29,9 @@ public class Identifier private(private val myName: String, private var myHasDol
public class User() {
class object {
public fun main() {
val i1 = Identifier.init("name", false, true)
val i2 = Identifier.init("name", false)
val i3 = Identifier.init("name")
val i1 = Identifier.create("name", false, true)
val i2 = Identifier.create("name", false)
val i3 = Identifier.create("name")
}
}
}
@@ -1,14 +1,14 @@
class C private(arg1: Int, arg2: Int, arg3: Int) {
class object {
private fun init(arg1: Int, arg2: Int): C {
private fun create(arg1: Int, arg2: Int): C {
val __ = C(arg1, arg2, 0)
return __
}
public fun init(arg1: Int): C {
public fun create(arg1: Int): C {
val __ = C(arg1, 0, 0)
return __
}
}
}
}
@@ -1,12 +1,12 @@
public class Test private(private val myName: String, private var a: Boolean, private var b: Double, private var c: Float, private var d: Long, private var e: Int, private var f: Short, private var g: Char) {
class object {
public fun init(): Test {
public fun create(): Test {
val __ = Test(0, false, 0.toDouble(), 0.toFloat(), 0, 0, 0, ' ')
return __
}
public fun init(name: String): Test {
public fun create(name: String): Test {
val __ = Test(foo(name), false, 0.toDouble(), 0.toFloat(), 0, 0, 0, ' ')
return __
}
@@ -21,7 +21,7 @@ public class Test private(private val myName: String, private var a: Boolean, pr
public class User() {
class object {
public fun main() {
val t = Test.init("name")
val t = Test.create("name")
}
}
}
+6 -6
View File
@@ -7,18 +7,18 @@ public class Identifier<T> private(private val myName: T, private var myHasDolla
class object {
public fun <T> init(name: T): Identifier<T> {
public fun <T> create(name: T): Identifier<T> {
val __ = Identifier(name, false)
return __
}
public fun <T> init(name: T, isNullable: Boolean): Identifier<T> {
public fun <T> create(name: T, isNullable: Boolean): Identifier<T> {
val __ = Identifier(name, false)
__.myNullable = isNullable
return __
}
public fun <T> init(name: T, hasDollar: Boolean, isNullable: Boolean): Identifier<T> {
public fun <T> create(name: T, hasDollar: Boolean, isNullable: Boolean): Identifier<T> {
val __ = Identifier(name, hasDollar)
__.myNullable = isNullable
return __
@@ -29,9 +29,9 @@ public class Identifier<T> private(private val myName: T, private var myHasDolla
public class User() {
class object {
public fun main(args: Array<String>) {
val i1 = Identifier.init<String>("name", false, true)
val i2 = Identifier.init<String>("name", false)
val i3 = Identifier.init<String>("name")
val i1 = Identifier.create<String>("name", false, true)
val i2 = Identifier.create<String>("name", false)
val i3 = Identifier.create<String>("name")
}
}
}