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,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
}
}
}