KT-5287 J2K: Convert class with private constructor and static functions to "object" instead of class with "class object"

#KT-5287 Fixed
This commit is contained in:
Valentin Kipyatkov
2015-03-27 13:55:47 +03:00
parent 6dbb13c32d
commit f19eb20803
63 changed files with 550 additions and 482 deletions
@@ -1,9 +1,7 @@
class Test {
companion object {
var str: String
object Test {
var str: String
init {
str = "Ola"
}
init {
str = "Ola"
}
}
@@ -1,8 +1,6 @@
// ERROR: Property must be initialized or be abstract
class Library {
companion object {
val ourOut: java.io.PrintStream
}
object Library {
val ourOut: java.io.PrintStream
}
class User {
@@ -1,11 +1,9 @@
class Library {
companion object {
fun call() {
}
object Library {
fun call() {
}
fun getString(): String {
return ""
}
fun getString(): String {
return ""
}
}
@@ -1,7 +1,10 @@
package test;
import java.lang.String;
public class Short {
public static Short valueOf(String value) {return new Short();}
public Short(String s){}
public static Short valueOf(String value) {return new Short(value);}
}
class Test {
@@ -1,19 +1,17 @@
package test
public class Short {
public class Short(s: String) {
companion object {
public fun valueOf(value: String): Short {
return Short()
return Short(value)
}
}
}
class Test {
companion object {
public fun test() {
test.Short.valueOf("1")
test.Short.valueOf("1")
java.lang.Short.valueOf("1")
}
object Test {
public fun test() {
test.Short.valueOf("1")
test.Short.valueOf("1")
java.lang.Short.valueOf("1")
}
}
@@ -0,0 +1,7 @@
class Base {
public static final int CONSTANT = 10;
}
class Derived extends Base {
void foo(){}
}
@@ -0,0 +1,10 @@
open class Base {
companion object {
public val CONSTANT: Int = 10
}
}
class Derived : Base() {
fun foo() {
}
}
@@ -1,7 +1,5 @@
class S {
companion object {
fun staticF(): Boolean {
return true
}
object S {
fun staticF(): Boolean {
return true
}
}
@@ -1,11 +1,9 @@
class S {
companion object {
fun sB(): Boolean {
return true
}
object S {
fun sB(): Boolean {
return true
}
fun sI(): Int {
return 1
}
fun sI(): Int {
return 1
}
}
@@ -0,0 +1,6 @@
class Util {
public static void util1() {}
public static void util2() {}
public static final int CONSTANT = 10;
}
@@ -0,0 +1,9 @@
object Util {
public fun util1() {
}
public fun util2() {
}
public val CONSTANT: Int = 10
}
@@ -0,0 +1,8 @@
class Util {
private Util(){}
public static void util1() {}
public static void util2() {}
public static final int CONSTANT = 10;
}
@@ -0,0 +1,10 @@
object Util {
public fun util1() {
}
public fun util2() {
}
public val CONSTANT: Int = 10
}
@@ -0,0 +1,6 @@
abstract class Util {
public static void util1() {}
public static void util2() {}
public static final int CONSTANT = 10;
}
@@ -0,0 +1,9 @@
object Util {
public fun util1() {
}
public fun util2() {
}
public val CONSTANT: Int = 10
}
@@ -1,13 +1,11 @@
public class A {
companion object {
public fun main(args: Array<String>) {
System.out.println(Void.TYPE)
System.out.println(Integer.TYPE)
System.out.println(java.lang.Double.TYPE)
System.out.println(javaClass<IntArray>())
System.out.println(javaClass<Array<Any>>())
System.out.println(javaClass<Array<Array<Any>>>())
}
public object A {
public fun main(args: Array<String>) {
System.out.println(Void.TYPE)
System.out.println(Integer.TYPE)
System.out.println(java.lang.Double.TYPE)
System.out.println(javaClass<IntArray>())
System.out.println(javaClass<Array<Any>>())
System.out.println(javaClass<Array<Array<Any>>>())
}
}
@@ -2,12 +2,10 @@ package pack
class C(arg1: Int, arg2: Int = 0, arg3: Int = 0)
public class User {
companion object {
public fun main() {
val c1 = C(100, 100, 100)
val c2 = C(100, 100)
val c3 = C(100)
}
public object User {
public fun main() {
val c1 = C(100, 100, 100)
val c2 = C(100, 100)
val c3 = C(100)
}
}
@@ -18,12 +18,10 @@ class C(val myArg1: Int) {
}
}
public class User {
companion object {
public fun main() {
val c1 = C(100, 100, 100)
val c2 = C(100, 100)
val c3 = C(100)
}
public object User {
public fun main() {
val c1 = C(100, 100, 100)
val c2 = C(100, 100)
val c3 = C(100)
}
}
@@ -9,12 +9,10 @@ class C(arg1: Int, arg2: Int, arg3: Int) {
}
}
public class User {
companion object {
public fun main() {
val c1 = C(1, 2, 3)
val c2 = C(5, 6)
val c3 = C(7)
}
public object User {
public fun main() {
val c1 = C(1, 2, 3)
val c2 = C(5, 6)
val c3 = C(7)
}
}
@@ -33,12 +33,10 @@ class CustomerBuilder {
}
}
public class User {
companion object {
public fun main() {
val customer = CustomerBuilder().WithFirstName("Homer").WithLastName("Simpson").Build()
System.out.println(customer.firstName)
System.out.println(customer.lastName)
}
public object User {
public fun main() {
val customer = CustomerBuilder().WithFirstName("Homer").WithLastName("Simpson").Build()
System.out.println(customer.firstName)
System.out.println(customer.lastName)
}
}
@@ -20,12 +20,10 @@ public class Identifier<T> {
}
}
public class User {
companion object {
public fun main() {
val i1 = Identifier("name", false, true)
val i2 = Identifier("name", false)
val i3 = Identifier("name")
}
public object User {
public fun main() {
val i1 = Identifier("name", false, true)
val i2 = Identifier("name", false)
val i3 = Identifier("name")
}
}
@@ -20,12 +20,10 @@ public class Identifier {
}
}
public class User {
companion object {
public fun main() {
val i1 = Identifier("name", false, true)
val i2 = Identifier("name", false)
val i3 = Identifier("name")
}
public object User {
public fun main() {
val i1 = Identifier("name", false, true)
val i2 = Identifier("name", false)
val i3 = Identifier("name")
}
}
@@ -11,12 +11,10 @@ class C {
}
}
public class User {
companion object {
public fun main() {
val c1 = C(1, 2, 3)
val c2 = C(5, 6)
val c3 = C(7)
}
public object User {
public fun main() {
val c1 = C(1, 2, 3)
val c2 = C(5, 6)
val c3 = C(7)
}
}
@@ -17,12 +17,10 @@ class C(arg1: Int, arg2: Int = 0, arg3: Int = 0) {
}
}
public class User {
companion object {
public fun main() {
val c1 = C(100, 100, 100)
val c2 = C(100, 100)
val c3 = C(100)
}
public object User {
public fun main() {
val c1 = C(100, 100, 100)
val c2 = C(100, 100)
val c3 = C(100)
}
}
@@ -1,4 +1,4 @@
class Outer {
object Outer {
private class Nested1() {
public constructor(a: Int) : this() {
@@ -48,13 +48,10 @@ class Outer {
}
}
companion object {
fun foo() {
val nested1 = Nested1(1)
val nested2 = Nested2(2)
val nested3 = Nested3(3)
val nested4 = Nested4(4)
}
fun foo() {
val nested1 = Nested1(1)
val nested2 = Nested2(2)
val nested3 = Nested3(3)
val nested4 = Nested4(4)
}
}
@@ -24,10 +24,8 @@ public class Test {
}
}
public class User {
companion object {
public fun main() {
val t = Test("name")
}
public object User {
public fun main() {
val t = Test("name")
}
}
@@ -1,16 +1,14 @@
public class TestClass {
companion object {
public fun main(args: Array<String>) {
var i = 0
while (i < 10) {
if (i == 4 || i == 8) {
i++
++i
continue
}
System.err.println(i)
public object TestClass {
public fun main(args: Array<String>) {
var i = 0
while (i < 10) {
if (i == 4 || i == 8) {
i++
++i
continue
}
System.err.println(i)
++i
}
}
}
+11 -13
View File
@@ -1,19 +1,17 @@
public class TestClass {
companion object {
public fun main(args: Array<String>) {
var i = 0
var j = 1
while (i < 10) {
if (i == 4 || i == 8) {
i++
++i
j *= 2
continue
}
System.err.println(j)
public object TestClass {
public fun main(args: Array<String>) {
var i = 0
var j = 1
while (i < 10) {
if (i == 4 || i == 8) {
i++
++i
j *= 2
continue
}
System.err.println(j)
++i
j *= 2
}
}
}
@@ -1,15 +1,13 @@
public class TestClass {
companion object {
public fun main(args: Array<String>) {
var i = 1
while (i < 1000) {
if (i == 4 || i == 8) {
i *= 2
continue
}
System.err.println(i)
public object TestClass {
public fun main(args: Array<String>) {
var i = 1
while (i < 1000) {
if (i == 4 || i == 8) {
i *= 2
continue
}
System.err.println(i)
i *= 2
}
}
}
@@ -1,28 +1,26 @@
// ERROR: The label '@OuterLoop1' does not denote a loop
public class TestClass {
companion object {
public fun main(args: Array<String>) {
var i = 1
@OuterLoop1 @OuterLoop2 while (i < 1000) {
var j = 1
@InnerLoop while (j < 100) {
if (j == 3) {
j *= 3
continue@InnerLoop
}
if (i == j) {
i *= 2
continue@OuterLoop1
}
System.err.println(j)
if (j == 9) {
j *= 3
continue
}
public object TestClass {
public fun main(args: Array<String>) {
var i = 1
@OuterLoop1 @OuterLoop2 while (i < 1000) {
var j = 1
@InnerLoop while (j < 100) {
if (j == 3) {
j *= 3
continue@InnerLoop
}
i *= 2
if (i == j) {
i *= 2
continue@OuterLoop1
}
System.err.println(j)
if (j == 9) {
j *= 3
continue
}
j *= 3
}
i *= 2
}
}
}
@@ -1,28 +1,26 @@
class F {
companion object {
object F {
//c1
//c1
/*c2*/
/*c2*/
fun f1() {
}
fun f1() {
}
//c3
//c3
//c4
//c4
fun f2() {
}
fun f2() {
}
var i: Int? = 0
var i: Int? = 0
fun f3() {
}
fun f3() {
}
//c5
+1 -3
View File
@@ -1,4 +1,2 @@
companion object {
public fun main(args: Array<String>) {
}
public fun main(args: Array<String>) {
}
+2 -4
View File
@@ -1,7 +1,5 @@
public class A {
companion object {
public fun main(args: Array<String>) {
}
public object A {
public fun main(args: Array<String>) {
}
}
@@ -1,8 +1,6 @@
// !forceNotNullTypes: false
public class A {
companion object {
public fun main(args: Array<String>) {
}
public object A {
public fun main(args: Array<String>) {
}
}
@@ -1,7 +1,5 @@
class Test {
companion object {
public fun foo(args: Array<String>): Int {
return args.size()
}
object Test {
public fun foo(args: Array<String>): Int {
return args.size()
}
}
@@ -1,12 +1,9 @@
class Outer {
object Outer {
public var o: Any? = Object()
public class Nested {
public fun foo() {
o = null
}
}
companion object {
public var o: Any? = Object()
}
}
}
+8 -10
View File
@@ -1,14 +1,12 @@
package demo
class Test {
companion object {
fun subListRangeCheck(fromIndex: Int, toIndex: Int, size: Int) {
if (fromIndex < 0)
throw IndexOutOfBoundsException("fromIndex = " + fromIndex)
if (toIndex > size)
throw IndexOutOfBoundsException("toIndex = " + toIndex)
if (fromIndex > toIndex)
throw IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")")
}
object Test {
fun subListRangeCheck(fromIndex: Int, toIndex: Int, size: Int) {
if (fromIndex < 0)
throw IndexOutOfBoundsException("fromIndex = " + fromIndex)
if (toIndex > size)
throw IndexOutOfBoundsException("toIndex = " + toIndex)
if (fromIndex > toIndex)
throw IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")")
}
}
+5 -7
View File
@@ -20,13 +20,11 @@ public class Identifier<T> {
}
}
public class User {
companion object {
public fun main(args: Array<String>) {
val i1 = Identifier("name", false, true)
val i2 = Identifier("name", false)
val i3 = Identifier("name")
}
public object User {
public fun main(args: Array<String>) {
val i1 = Identifier("name", false, true)
val i2 = Identifier("name", false)
val i3 = Identifier("name")
}
}
+13 -15
View File
@@ -4,23 +4,21 @@
// ERROR: Unresolved reference: close
import java.io.*
class FileRead {
companion object {
public fun main(args: Array<String>) {
try {
val fstream = FileInputStream()
val `in` = DataInputStream(fstream)
val br = BufferedReader(InputStreamReader(`in`))
val strLine: String
while ((strLine = br.readLine()) != null) {
System.out.println(strLine)
}
`in`.close()
} catch (e: Exception) {
System.err.println("Error: " + e.getMessage())
object FileRead {
public fun main(args: Array<String>) {
try {
val fstream = FileInputStream()
val `in` = DataInputStream(fstream)
val br = BufferedReader(InputStreamReader(`in`))
val strLine: String
while ((strLine = br.readLine()) != null) {
System.out.println(strLine)
}
`in`.close()
} catch (e: Exception) {
System.err.println("Error: " + e.getMessage())
}
}
}
@@ -4,10 +4,8 @@ class Container {
var myString = "1"
}
class One {
companion object {
var myContainer = Container()
}
object One {
var myContainer = Container()
}
class StringContainer(s: String)
+2 -4
View File
@@ -4,10 +4,8 @@ class Container {
var myInt = 1
}
class One {
companion object {
var myContainer = Container()
}
object One {
var myContainer = Container()
}
class IntContainer(i: Int)
@@ -4,10 +4,8 @@ class Container {
var myInt = 1
}
class One {
companion object {
var myContainer = Container()
}
object One {
var myContainer = Container()
}
class Test {
@@ -1,8 +1,6 @@
class Test {
companion object {
public fun toFileSystemSafeName(name: String): String {
val size = name.length()
return name
}
object Test {
public fun toFileSystemSafeName(name: String): String {
val size = name.length()
return name
}
}
+2 -4
View File
@@ -4,10 +4,8 @@ class Container {
var myInt = 1
}
class One {
companion object {
var myContainer = Container()
}
object One {
var myContainer = Container()
}
class Test {
@@ -5,17 +5,15 @@ import java.io.File
/**
* User: ignatov
*/
public class Test {
companion object {
public fun isDir(parent: File?): Boolean {
if (parent == null || !parent.exists()) {
return false
}
val result = true
if (parent.isDirectory()) {
return true
} else
return false
public object Test {
public fun isDir(parent: File?): Boolean {
if (parent == null || !parent.exists()) {
return false
}
val result = true
if (parent.isDirectory()) {
return true
} else
return false
}
}
+2 -4
View File
@@ -4,10 +4,8 @@ class Container {
var myBoolean = true
}
class One {
companion object {
var myContainer = Container()
}
object One {
var myContainer = Container()
}
class Test {
+3 -5
View File
@@ -1,10 +1,8 @@
package demo
class Program {
companion object {
public fun main(args: Array<String>) {
System.out.println("Halo!")
}
object Program {
public fun main(args: Array<String>) {
System.out.println("Halo!")
}
}
+8 -10
View File
@@ -1,13 +1,11 @@
class Test {
companion object {
public fun getInt(i: Int): Int {
when (i) {
0 -> return 0
1 -> return 1
2 -> return 2
3 -> return 3
else -> return -1
}
object Test {
public fun getInt(i: Int): Int {
when (i) {
0 -> return 0
1 -> return 1
2 -> return 2
3 -> return 3
else -> return -1
}
}
}
@@ -1,11 +1,9 @@
import java.lang.reflect.Constructor
class X {
companion object {
throws(javaClass<Exception>())
fun <T> foo(constructor: Constructor<T>, args1: Array<Any>, args2: Array<Any>) {
constructor.newInstance(*args1)
constructor.newInstance(args1, args2)
}
object X {
throws(javaClass<Exception>())
fun <T> foo(constructor: Constructor<T>, args1: Array<Any>, args2: Array<Any>) {
constructor.newInstance(*args1)
constructor.newInstance(args1, args2)
}
}
@@ -1,86 +1,84 @@
package demo
public class SwitchDemo {
companion object {
public fun print(o: Any) {
System.out.println(o)
}
public object SwitchDemo {
public fun print(o: Any) {
System.out.println(o)
}
public fun test(i: Int) {
var monthString = "<empty>"
when (i) {
1 -> {
print(1)
print(2)
print(3)
print(4)
print(5)
}
2 -> {
print(2)
print(3)
print(4)
print(5)
}
3 -> {
print(3)
print(4)
print(5)
}
4 -> {
print(4)
print(5)
}
5 -> print(5)
6 -> {
print(6)
print(7)
print(8)
print(9)
print(10)
print(11)
monthString = "December"
}
7 -> {
print(7)
print(8)
print(9)
print(10)
print(11)
monthString = "December"
}
8 -> {
print(8)
print(9)
print(10)
print(11)
monthString = "December"
}
9 -> {
print(9)
print(10)
print(11)
monthString = "December"
}
10 -> {
print(10)
print(11)
monthString = "December"
}
11 -> {
print(11)
monthString = "December"
}
12 -> monthString = "December"
else -> monthString = "Invalid month"
public fun test(i: Int) {
var monthString = "<empty>"
when (i) {
1 -> {
print(1)
print(2)
print(3)
print(4)
print(5)
}
System.out.println(monthString)
2 -> {
print(2)
print(3)
print(4)
print(5)
}
3 -> {
print(3)
print(4)
print(5)
}
4 -> {
print(4)
print(5)
}
5 -> print(5)
6 -> {
print(6)
print(7)
print(8)
print(9)
print(10)
print(11)
monthString = "December"
}
7 -> {
print(7)
print(8)
print(9)
print(10)
print(11)
monthString = "December"
}
8 -> {
print(8)
print(9)
print(10)
print(11)
monthString = "December"
}
9 -> {
print(9)
print(10)
print(11)
monthString = "December"
}
10 -> {
print(10)
print(11)
monthString = "December"
}
11 -> {
print(11)
monthString = "December"
}
12 -> monthString = "December"
else -> monthString = "Invalid month"
}
System.out.println(monthString)
}
public fun main(args: Array<String>) {
for (i in 1..12)
test(i)
}
public fun main(args: Array<String>) {
for (i in 1..12)
test(i)
}
}
@@ -1,14 +1,12 @@
public class NonDefault {
companion object {
public fun main(args: Array<String>) {
public object NonDefault {
public fun main(args: Array<String>) {
val value = 3
val valueString = ""
when (value) {
val value = 3
val valueString = ""
when (value) {
}
System.out.println(valueString)
}
System.out.println(valueString)
}
}
+8 -10
View File
@@ -1,16 +1,14 @@
package switch_demo
public class SwitchDemo {
companion object {
public fun main(args: Array<String>) {
val month = 8
val monthString: String
when (month) {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 -> monthString = "December"
else -> monthString = "Invalid month"
}
System.out.println(monthString)
public object SwitchDemo {
public fun main(args: Array<String>) {
val month = 8
val monthString: String
when (month) {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 -> monthString = "December"
else -> monthString = "Invalid month"
}
System.out.println(monthString)
}
}
@@ -1,23 +1,21 @@
public class C {
companion object {
public fun main(args: Array<String>) {
when (args.size()) {
1 -> {
run {
val a = 1
System.out.print("1")
}
run {
val a = 2
System.out.print("2")
}
public object C {
public fun main(args: Array<String>) {
when (args.size()) {
1 -> {
run {
val a = 1
System.out.print("1")
}
2 -> {
run {
val a = 2
System.out.print("2")
}
}
2 -> {
val a = 2
System.out.print("2")
}
}
}
}
+19 -21
View File
@@ -1,28 +1,26 @@
package switch_demo
public class SwitchDemo {
companion object {
public fun main(args: Array<String>) {
public object SwitchDemo {
public fun main(args: Array<String>) {
val month = 8
val monthString: String
when (month) {
1 -> monthString = "January"
2 -> monthString = "February"
3 -> monthString = "March"
4 -> monthString = "April"
5 -> monthString = "May"
6 -> monthString = "June"
7 -> monthString = "July"
8 -> monthString = "August"
9 -> monthString = "September"
10 -> monthString = "October"
11 -> monthString = "November"
12 -> monthString = "December"
else -> monthString = "Invalid month"
}
System.out.println(monthString)
val month = 8
val monthString: String
when (month) {
1 -> monthString = "January"
2 -> monthString = "February"
3 -> monthString = "March"
4 -> monthString = "April"
5 -> monthString = "May"
6 -> monthString = "June"
7 -> monthString = "July"
8 -> monthString = "August"
9 -> monthString = "September"
10 -> monthString = "October"
11 -> monthString = "November"
12 -> monthString = "December"
else -> monthString = "Invalid month"
}
System.out.println(monthString)
}
}
@@ -1,16 +1,14 @@
public class NonDefault {
companion object {
public fun main(args: Array<String>) {
public object NonDefault {
public fun main(args: Array<String>) {
val value = 3
var valueString = ""
when (value) {
1 -> valueString = "ONE"
2 -> valueString = "TWO"
3 -> valueString = "THREE"
}
System.out.println(valueString)
val value = 3
var valueString = ""
when (value) {
1 -> valueString = "ONE"
2 -> valueString = "TWO"
3 -> valueString = "THREE"
}
System.out.println(valueString)
}
}
@@ -1,11 +1,9 @@
// ERROR: Type inference failed. Expected type mismatch: found: java.util.HashMap<kotlin.Any!, kotlin.Any!> required: kotlin.Map<kotlin.String, kotlin.String>
import java.util.*
class A {
companion object {
public fun foo(): Map<String, String> {
val props = Properties()
return HashMap(props as Map<Any, Any>)
}
object A {
public fun foo(): Map<String, String> {
val props = Properties()
return HashMap(props as Map<Any, Any>)
}
}