KT-7151 Convert 'System.out.println()' to just 'println()'

#KT-7151 Fixed
This commit is contained in:
Valentin Kipyatkov
2015-03-29 19:03:14 +03:00
parent 39f94d7d45
commit 1465418c2b
89 changed files with 198 additions and 140 deletions
@@ -274,7 +274,7 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
if (target is PsiMethod) { if (target is PsiMethod) {
val specialMethod = SpecialMethod.values().firstOrNull { it.matches(target) } val specialMethod = SpecialMethod.values().firstOrNull { it.matches(target) }
if (specialMethod != null && arguments.size() == specialMethod.parameterCount) { if (specialMethod != null && (specialMethod.parameterCount == null || specialMethod.parameterCount == arguments.size())) {
val converted = specialMethod.convertCall(methodExpr.getQualifierExpression(), arguments, typeArguments, codeConverter) val converted = specialMethod.convertCall(methodExpr.getQualifierExpression(), arguments, typeArguments, codeConverter)
if (converted != null) { if (converted != null) {
result = converted result = converted
@@ -16,19 +16,14 @@
package org.jetbrains.kotlin.j2k package org.jetbrains.kotlin.j2k
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiExpression
import org.jetbrains.kotlin.j2k.ast.BinaryExpression
import org.jetbrains.kotlin.j2k.ast.Expression
import org.jetbrains.kotlin.j2k.ast.MethodCallExpression
import com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT import com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT
import com.intellij.psi.PsiExpression
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiReferenceExpression
import com.intellij.psi.PsiSuperExpression import com.intellij.psi.PsiSuperExpression
import org.jetbrains.kotlin.j2k.ast.QualifiedExpression import org.jetbrains.kotlin.j2k.ast.*
import org.jetbrains.kotlin.j2k.ast.Identifier
import org.jetbrains.kotlin.j2k.ast.assignNoPrototype
import org.jetbrains.kotlin.j2k.ast.Type
enum class SpecialMethod(val qualifiedClassName: String?, val methodName: String, val parameterCount: Int) { enum class SpecialMethod(val qualifiedClassName: String?, val methodName: String, val parameterCount: Int?) {
OBJECT_EQUALS: SpecialMethod(null, "equals", 1) { OBJECT_EQUALS: SpecialMethod(null, "equals", 1) {
override fun matches(method: PsiMethod) override fun matches(method: PsiMethod)
= super.matches(method) && method.getParameterList().getParameters().single().getType().getCanonicalText() == JAVA_LANG_OBJECT = super.matches(method) && method.getParameterList().getParameters().single().getType().getCanonicalText() == JAVA_LANG_OBJECT
@@ -76,11 +71,36 @@ enum class SpecialMethod(val qualifiedClassName: String?, val methodName: String
= MethodCallExpression.build(null, "setOf", listOf(codeConverter.convertExpression(arguments.single())), typeArgumentsConverted, false) = MethodCallExpression.build(null, "setOf", listOf(codeConverter.convertExpression(arguments.single())), typeArgumentsConverted, false)
} }
SYSTEM_OUT_PRINTLN: SpecialMethod("java.io.PrintStream", "println", null) {
override fun convertCall(qualifier: PsiExpression?, arguments: Array<PsiExpression>, typeArgumentsConverted: List<Type>, codeConverter: CodeConverter)
= convertSystemOutMethodCall(methodName, qualifier, arguments, typeArgumentsConverted, codeConverter)
}
SYSTEM_OUT_PRINT: SpecialMethod("java.io.PrintStream", "print", null) {
override fun convertCall(qualifier: PsiExpression?, arguments: Array<PsiExpression>, typeArgumentsConverted: List<Type>, codeConverter: CodeConverter)
= convertSystemOutMethodCall(methodName, qualifier, arguments, typeArgumentsConverted, codeConverter)
}
open fun matches(method: PsiMethod): Boolean { open fun matches(method: PsiMethod): Boolean {
if (method.getName() != methodName) return false if (method.getName() != methodName) return false
if (qualifiedClassName != null && method.getContainingClass()?.getQualifiedName() != qualifiedClassName) return false if (qualifiedClassName != null && method.getContainingClass()?.getQualifiedName() != qualifiedClassName) return false
return method.getParameterList().getParametersCount() == parameterCount return parameterCount == null || parameterCount == method.getParameterList().getParametersCount()
} }
abstract fun convertCall(qualifier: PsiExpression?, arguments: Array<PsiExpression>, typeArgumentsConverted: List<Type>, codeConverter: CodeConverter): Expression? abstract fun convertCall(qualifier: PsiExpression?, arguments: Array<PsiExpression>, typeArgumentsConverted: List<Type>, codeConverter: CodeConverter): Expression?
} }
private fun convertSystemOutMethodCall(
methodName: String,
qualifier: PsiExpression?,
arguments: Array<PsiExpression>,
typeArgumentsConverted: List<Type>,
codeConverter: CodeConverter
): Expression? {
if (qualifier !is PsiReferenceExpression) return null
val qqualifier = qualifier.getQualifierExpression() as? PsiReferenceExpression ?: return null
if (qqualifier.getCanonicalText() != "java.lang.System") return null
if (qualifier.getReferenceName() != "out") return null
if (typeArgumentsConverted.isNotEmpty()) return null
return MethodCallExpression.build(null, methodName, arguments.map { codeConverter.convertExpression(it) }, emptyList(), false)
}
@@ -11,7 +11,7 @@ public class Test(str: String) {
public fun sout(str: String) { public fun sout(str: String) {
// UNNECESSARY_NOT_NULL_ASSERTION heuristic does not work any more, instead we can skip generating !! altogether // UNNECESSARY_NOT_NULL_ASSERTION heuristic does not work any more, instead we can skip generating !! altogether
System.out!!.println(str) println(str)
} }
public fun dummy(str: String): String { public fun dummy(str: String): String {
@@ -9,7 +9,7 @@ public class Test(str: String?) {
} }
public fun sout(str: String?) { public fun sout(str: String?) {
System.out.println(str) println(str)
} }
public fun dummy(str: String?): String? { public fun dummy(str: String?): String? {
@@ -1 +1 @@
System.out.println("Hello, world") println("Hello, world")
@@ -1,11 +1,11 @@
public object A { public object A {
public fun main(args: Array<String>) { public fun main(args: Array<String>) {
System.out.println(Void.TYPE) println(Void.TYPE)
System.out.println(Integer.TYPE) println(Integer.TYPE)
System.out.println(java.lang.Double.TYPE) println(java.lang.Double.TYPE)
System.out.println(javaClass<IntArray>()) println(javaClass<IntArray>())
System.out.println(javaClass<Array<Any>>()) println(javaClass<Array<Any>>())
System.out.println(javaClass<Array<Array<Any>>>()) println(javaClass<Array<Array<Any>>>())
} }
} }
@@ -1,6 +1,6 @@
class C { class C {
fun foo(o: Any) { fun foo(o: Any) {
if (o !is String) return if (o !is String) return
System.out.println("String") println("String")
} }
} }
@@ -10,17 +10,17 @@ import java.util.ArrayList // we need ArrayList
class A /* just a sample name*/ : Runnable /* let's implement Runnable */ { class A /* just a sample name*/ : Runnable /* let's implement Runnable */ {
fun foo/* again a sample name */(p: Int /* parameter p */, c: Char /* parameter c */) { fun foo/* again a sample name */(p: Int /* parameter p */, c: Char /* parameter c */) {
// let's print something: // let's print something:
System.out.println("1") // print 1 println("1") // print 1
System.out.println("2") // print 2 println("2") // print 2
System.out.println("3") // print 3 println("3") // print 3
// end of printing // end of printing
if (p > 0) { if (p > 0) {
// do this only when p > 0 // do this only when p > 0
// we print 4 and return // we print 4 and return
System.out.println("3") println("3")
return // do not continue return // do not continue
} }
@@ -1,6 +1,6 @@
fun foo(b: Boolean) { fun foo(b: Boolean) {
if (b) if (b)
System.out.println("true") println("true")
else else
System.out.println("false") println("false")
} }
@@ -1,11 +1,11 @@
class C(arg1: Int, arg2: Int, arg3: Int) { class C(arg1: Int, arg2: Int, arg3: Int) {
constructor(arg1: Int, arg2: Int) : this(arg1, arg2, 0) { constructor(arg1: Int, arg2: Int) : this(arg1, arg2, 0) {
System.out.println() println()
} }
constructor(arg1: Int) : this(arg1, 0) { constructor(arg1: Int) : this(arg1, 0) {
System.out.println() println()
} }
} }
@@ -36,7 +36,7 @@ class CustomerBuilder {
public object User { public object User {
public fun main() { public fun main() {
val customer = CustomerBuilder().WithFirstName("Homer").WithLastName("Simpson").Build() val customer = CustomerBuilder().WithFirstName("Homer").WithLastName("Simpson").Build()
System.out.println(customer.firstName) println(customer.firstName)
System.out.println(customer.lastName) println(customer.lastName)
} }
} }
@@ -1,6 +1,6 @@
class C(private val field: Int) { class C(private val field: Int) {
init { init {
System.out.println(field) println(field)
} }
} }
@@ -4,7 +4,7 @@ class C(p: Int) {
init { init {
var p = p var p = p
this.p = p this.p = p
System.out.println(p++) println(p++)
System.out.println(p) println(p)
} }
} }
@@ -5,7 +5,7 @@ class C(private val arg1: Int, private val arg2: Int, private val arg3: Int) {
} }
constructor(arg1: Int, arg2: Int, other: C) : this(arg1, arg2, 0) { constructor(arg1: Int, arg2: Int, other: C) : this(arg1, arg2, 0) {
System.out.println(foo(1) + this.foo(2) + other.foo(3) + staticFoo(4) + C.staticFoo(5)) println(foo(1) + this.foo(2) + other.foo(3) + staticFoo(4) + C.staticFoo(5))
} }
companion object { companion object {
@@ -3,11 +3,11 @@ class C {
} }
constructor(arg1: Int, arg2: Int) : this(arg1, arg2, 0) { constructor(arg1: Int, arg2: Int) : this(arg1, arg2, 0) {
System.out.println() println()
} }
constructor(arg: Int) { constructor(arg: Int) {
System.out.println(arg) println(arg)
} }
} }
@@ -6,7 +6,7 @@ class C(arg1: Int, arg2: Int = 0, arg3: Int = 0) {
var arg1 = arg1 var arg1 = arg1
var arg3 = arg3 var arg3 = arg3
arg1++ arg1++
System.out.print(arg1 + arg2) print(arg1 + arg2)
field = arg3 field = arg3
arg3++ arg3++
} }
@@ -1,7 +1,7 @@
class C(private val arg1: Int, private val arg2: Int, private val arg3: Int) { class C(private val arg1: Int, private val arg2: Int, private val arg3: Int) {
constructor(arg1: Int, arg2: Int, other: C) : this(arg1, arg2, 0) { constructor(arg1: Int, arg2: Int, other: C) : this(arg1, arg2, 0) {
System.out.println(this.arg1 + other.arg2) println(this.arg1 + other.arg2)
} }
} }
@@ -1,7 +1,7 @@
class C() { class C() {
constructor(p: Int) : this() { constructor(p: Int) : this() {
System.out.println(staticField1 + C.staticField2) println(staticField1 + C.staticField2)
} }
companion object { companion object {
@@ -4,7 +4,7 @@ public class X {
var value = 10 var value = 10
override fun run() { override fun run() {
System.out.println(value) println(value)
} }
} }
} }
@@ -1,6 +1,6 @@
public class Test(public var id: String?, public val name: String, public val age: Int) { public class Test(public var id: String?, public val name: String, public val age: Int) {
init { init {
System.out.println(age) println(age)
} }
} }
@@ -3,8 +3,8 @@ public class AAA {
private set private set
public fun foo(other: AAA) { public fun foo(other: AAA) {
System.out.println(x) println(x)
System.out.println(other.x) println(other.x)
x = 10 x = 10
} }
} }
@@ -3,15 +3,15 @@ public open class AAA {
protected set protected set
public fun foo(other: AAA) { public fun foo(other: AAA) {
System.out.println(x) println(x)
System.out.println(other.x) println(other.x)
x = 10 x = 10
} }
} }
class BBB : AAA() { class BBB : AAA() {
fun bar() { fun bar() {
System.out.println(x) println(x)
x = 10 x = 10
} }
} }
@@ -2,6 +2,6 @@ class C {
public val default: Int = 0 public val default: Int = 0
fun foo() { fun foo() {
System.out.println(default) println(default)
} }
} }
@@ -2,6 +2,6 @@ class C {
public val `this`: Int = 0 public val `this`: Int = 0
fun foo() { fun foo() {
System.out.println(`this`) println(`this`)
} }
} }
@@ -6,6 +6,6 @@ enum class Color : Runnable {
BLUE BLUE
override fun run() { override fun run() {
System.out.println("name()=" + name() + ", toString()=" + toString()) println("name()=" + name() + ", toString()=" + toString())
} }
} }
@@ -1,7 +1,7 @@
public class A { public class A {
fun foo(array: Array<String>) { fun foo(array: Array<String>) {
for (i in array.indices.reversed()) { for (i in array.indices.reversed()) {
System.out.println(i) println(i)
} }
} }
} }
+1 -1
View File
@@ -1,7 +1,7 @@
public class A { public class A {
fun foo() { fun foo() {
for (i in 10 downTo 0) { for (i in 10 downTo 0) {
System.out.println(i) println(i)
} }
} }
} }
+1 -1
View File
@@ -1,7 +1,7 @@
public class A { public class A {
fun foo() { fun foo() {
for (i in 10 downTo 1) { for (i in 10 downTo 1) {
System.out.println(i) println(i)
} }
} }
} }
+1 -1
View File
@@ -1,7 +1,7 @@
public class A { public class A {
fun foo(min: Int) { fun foo(min: Int) {
for (i in 10 downTo min + 1) { for (i in 10 downTo min + 1) {
System.out.println(i) println(i)
} }
} }
} }
@@ -1,7 +1,7 @@
public class A { public class A {
fun foo(array: Array<String>) { fun foo(array: Array<String>) {
for (i in array.size() downTo 0) { for (i in array.size() downTo 0) {
System.out.println(i) println(i)
} }
} }
} }
@@ -1,7 +1,7 @@
public class A { public class A {
fun foo(array: Array<String>) { fun foo(array: Array<String>) {
for (i in array.size() - 2 downTo 0) { for (i in array.size() - 2 downTo 0) {
System.out.println(i) println(i)
} }
} }
} }
@@ -1,7 +1,7 @@
public class A { public class A {
fun foo(collection: Collection<String>) { fun foo(collection: Collection<String>) {
for (i in collection.size() downTo 0) { for (i in collection.size() downTo 0) {
System.out.println(i) println(i)
} }
} }
} }
@@ -1,3 +1,3 @@
for (i in 0..N - 1) { for (i in 0..N - 1) {
System.out.println(i) println(i)
} }
@@ -3,7 +3,7 @@ import java.lang.System
class C { class C {
fun foo1(collection: Collection<String>) { fun foo1(collection: Collection<String>) {
for (i in collection.indices) { for (i in collection.indices) {
System.out.print(i) print(i)
} }
} }
} }
@@ -5,7 +5,7 @@ class X {
class C { class C {
fun foo(x: X) { fun foo(x: X) {
for (i in 0..x.length - 1) { for (i in 0..x.length - 1) {
System.out.print(i) print(i)
} }
} }
} }
@@ -7,7 +7,7 @@ class X {
class C { class C {
fun foo(x: X) { fun foo(x: X) {
for (i in 0..x.size() - 1) { for (i in 0..x.size() - 1) {
System.out.print(i) print(i)
} }
} }
} }
@@ -1,4 +1,5 @@
//statement //statement
int j = 1;
for (int i = 0; i < 10; j++, i++) { for (int i = 0; i < 10; j++, i++) {
System.out.println(i); System.out.println(i);
System.out.println(j); System.out.println(j);
@@ -1,7 +1,8 @@
var j = 1
var i = 0 var i = 0
while (i < 10) { while (i < 10) {
System.out.println(i) println(i)
System.out.println(j) println(j)
j++ j++
i++ i++
} }
@@ -1,7 +1,7 @@
public class A { public class A {
fun foo(collection: Collection<String>) { fun foo(collection: Collection<String>) {
for (i in collection.indices.reversed()) { for (i in collection.indices.reversed()) {
System.out.println(i) println(i)
} }
} }
} }
@@ -3,14 +3,14 @@ class A {
run { run {
var i = 1 var i = 1
while (i < 1000) { while (i < 1000) {
System.out.println(i) println(i)
i *= 2 i *= 2
} }
} }
var i = 1 var i = 1
while (i < 2000) { while (i < 2000) {
System.out.println(i) println(i)
i *= 2 i *= 2
} }
} }
@@ -4,7 +4,7 @@ class A {
var i = 1 var i = 1
var j = 0 var j = 0
while (i < 1000) { while (i < 1000) {
System.out.println(i) println(i)
i *= 2 i *= 2
j++ j++
} }
@@ -12,7 +12,7 @@ class A {
var j = 1 var j = 1
while (j < 2000) { while (j < 2000) {
System.out.println(j) println(j)
j *= 2 j *= 2
} }
} }
@@ -5,7 +5,7 @@ class A {
run { run {
var i = 1 var i = 1
while (i < 1000) { while (i < 1000) {
System.out.println(i) println(i)
i *= 2 i *= 2
} }
} }
@@ -3,7 +3,7 @@ class A {
run { run {
var i = 1 var i = 1
while (i < 1000) { while (i < 1000) {
System.out.println(i) println(i)
i *= 2 i *= 2
} }
} }
@@ -6,7 +6,7 @@ class A {
var i = 1 var i = 1
while (i < 1000) { while (i < 1000) {
System.out.println(i) println(i)
i *= 2 i *= 2
} }
} }
+1 -1
View File
@@ -3,7 +3,7 @@ class A {
if (p) { if (p) {
var i = 1 var i = 1
while (i < 1000) { while (i < 1000) {
System.out.println(i) println(i)
i *= 2 i *= 2
} }
} }
@@ -3,7 +3,7 @@ class A {
fun foo() { fun foo() {
for (e in list!!) { for (e in list!!) {
System.out.println(e) println(e)
} }
} }
} }
@@ -1,14 +1,14 @@
fun foo() { fun foo() {
if (a) if (a)
System.out.println("a") println("a")
else if (b) else if (b)
System.out.println("b") println("b")
else else
System.out.println("else") println("else")
if (c) { if (c) {
System.out.println("c") println("c")
} else if (d) { } else if (d) {
System.out.println("d") println("d")
} }
} }
+1 -1
View File
@@ -12,7 +12,7 @@ object FileRead {
val br = BufferedReader(InputStreamReader(`in`)) val br = BufferedReader(InputStreamReader(`in`))
val strLine: String val strLine: String
while ((strLine = br.readLine()) != null) { while ((strLine = br.readLine()) != null) {
System.out.println(strLine) println(strLine)
} }
`in`.close() `in`.close()
} catch (e: Exception) { } catch (e: Exception) {
+3 -3
View File
@@ -11,15 +11,15 @@ object One {
class Test { class Test {
fun test() { fun test() {
if (One.myContainer.myBoolean) if (One.myContainer.myBoolean)
System.out.println("Ok") println("Ok")
val s = if (One.myContainer.myBoolean) "YES" else "NO" val s = if (One.myContainer.myBoolean) "YES" else "NO"
while (One.myContainer.myBoolean) while (One.myContainer.myBoolean)
System.out.println("Ok") println("Ok")
do { do {
System.out.println("Ok") println("Ok")
} while (One.myContainer.myBoolean) } while (One.myContainer.myBoolean)
} }
} }
+6 -6
View File
@@ -4,12 +4,12 @@ class Test {
res = res and false res = res and false
res = res or false res = res or false
res = res xor false res = res xor false
System.out.println(true and false) println(true and false)
System.out.println(true or false) println(true or false)
System.out.println(true xor false) println(true xor false)
System.out.println(!true) println(!true)
System.out.println(true && false) println(true && false)
System.out.println(true || false) println(true || false)
} }
} }
+1 -1
View File
@@ -2,7 +2,7 @@ package demo
object Program { object Program {
public fun main(args: Array<String>) { public fun main(args: Array<String>) {
System.out.println("Halo!") println("Halo!")
} }
} }
+1 -1
View File
@@ -3,7 +3,7 @@ package demo
class Test { class Test {
fun test() { fun test() {
for (i in 0..9) { for (i in 0..9) {
System.out.println(i) println(i)
} }
} }
} }
+1 -1
View File
@@ -1,6 +1,6 @@
class Test { class Test {
public fun printNumbers(number: Int) { public fun printNumbers(number: Int) {
for (i in 2..Math.sqrt(number.toDouble()) + 1 - 1) for (i in 2..Math.sqrt(number.toDouble()) + 1 - 1)
System.out.println(i) println(i)
} }
} }
@@ -3,7 +3,7 @@ import kotlinApi.*
class C : KotlinClass() { class C : KotlinClass() {
fun foo() { fun foo() {
System.out.println(property) println(property)
property = "a" property = "a"
} }
} }
@@ -2,7 +2,7 @@ import kotlinApi.*
class C { class C {
fun foo(k: KotlinClass) { fun foo(k: KotlinClass) {
System.out.println(k.property) println(k.property)
k.property = "a" k.property = "a"
} }
} }
@@ -2,7 +2,7 @@ import kotlinApi.*
class C { class C {
fun foo(k: KotlinClass) { fun foo(k: KotlinClass) {
System.out.println(k.field) println(k.field)
k.field = 1 k.field = 1
} }
} }
@@ -10,4 +10,4 @@
foundIt = true foundIt = true
break@test break@test
} }
System.out.println(if (foundIt) "Found it" else "Didn't find it") println(if (foundIt) "Found it" else "Didn't find it")
@@ -6,9 +6,9 @@ class Test {
name = name.replaceAll("\\$[0-9]+", "\\$") name = name.replaceAll("\\$[0-9]+", "\\$")
val c = '$' val c = '$'
System.out.println(c) println(c)
val C = '$' val C = '$'
System.out.println(C) println(C)
} }
} }
@@ -1,6 +1,6 @@
class A { class A {
fun foo(o: Any) { fun foo(o: Any) {
System.out.println(o.javaClass) println(o.javaClass)
System.out.println(javaClass) println(javaClass)
} }
} }
@@ -0,0 +1,12 @@
class A {
void foo() {
System.out.println();
System.out.println(1);
System.out.println("1");
System.out.print("1");
System.out.print(1);
System.err.println();
System.err.println(1);
}
}
@@ -0,0 +1,12 @@
class A {
fun foo() {
println()
println(1)
println("1")
print("1")
print(1)
System.err.println()
System.err.println(1)
}
}
@@ -1,5 +1,5 @@
object : Runnable { object : Runnable {
override fun run() { override fun run() {
System.out.println("Run") println("Run")
} }
} }
@@ -4,7 +4,7 @@ class C {
fun foo() { fun foo() {
if (s == null) { if (s == null) {
System.out.print("null") print("null")
} }
} }
} }
@@ -2,7 +2,7 @@ class C(private val s: String?) {
fun foo() { fun foo() {
if (s != null) { if (s != null) {
System.out.print("not null") print("not null")
} }
} }
} }
@@ -5,7 +5,7 @@ class C {
class D { class D {
fun foo(c: C) { fun foo(c: C) {
if (null == c.s) { if (null == c.s) {
System.out.println("null") println("null")
} }
} }
} }
@@ -2,7 +2,7 @@ class C(private val s: String?) {
init { init {
if (s == null) { if (s == null) {
System.out.print("null") print("null")
} }
} }
} }
@@ -1,5 +1,5 @@
fun foo(s: String?, b: Boolean): Int { fun foo(s: String?, b: Boolean): Int {
if (s == null) System.out.println("null") if (s == null) println("null")
if (b) return s!!.length() if (b) return s!!.length()
return 10 return 10
} }
@@ -2,7 +2,7 @@ package demo
class Collection<E>(e: E) { class Collection<E>(e: E) {
init { init {
System.out.println(e) println(e)
} }
} }
@@ -5,5 +5,5 @@ public fun foo(list: List<String>) {
array[i] = i array[i] = i
} }
for (s: String in list) System.out.print(s) for (s: String in list) print(s)
} }
@@ -2,16 +2,16 @@ fun foo() {
when (a) { when (a) {
1 -> { 1 -> {
val x = 1 val x = 1
System.out.println(x) println(x)
} }
2 -> { 2 -> {
val x = 2 val x = 2
System.out.println(x) println(x)
} }
3 -> { 3 -> {
System.out.println(3) println(3)
} }
} }
} }
@@ -2,7 +2,7 @@ package demo
public object SwitchDemo { public object SwitchDemo {
public fun print(o: Any) { public fun print(o: Any) {
System.out.println(o) println(o)
} }
public fun test(i: Int) { public fun test(i: Int) {
@@ -73,7 +73,7 @@ public object SwitchDemo {
12 -> monthString = "December" 12 -> monthString = "December"
else -> monthString = "Invalid month" else -> monthString = "Invalid month"
} }
System.out.println(monthString) println(monthString)
} }
public fun main(args: Array<String>) { public fun main(args: Array<String>) {
@@ -3,11 +3,11 @@ fun foo() {
when (take()) { when (take()) {
1 -> continue 1 -> continue
2 -> { 2 -> {
System.out.println("2") println("2")
return return
} }
3 -> break@Loop 3 -> break@Loop
} }
System.out.println() println()
} }
} }
@@ -6,7 +6,7 @@ public object NonDefault {
when (value) { when (value) {
} }
System.out.println(valueString) println(valueString)
} }
} }
@@ -8,7 +8,7 @@ public object SwitchDemo {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 -> monthString = "December" 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 -> monthString = "December"
else -> monthString = "Invalid month" else -> monthString = "Invalid month"
} }
System.out.println(monthString) println(monthString)
} }
} }
@@ -4,17 +4,17 @@ public object C {
1 -> { 1 -> {
run { run {
val a = 1 val a = 1
System.out.print("1") print("1")
} }
run { run {
val a = 2 val a = 2
System.out.print("2") print("2")
} }
} }
2 -> { 2 -> {
val a = 2 val a = 2
System.out.print("2") print("2")
} }
} }
} }
@@ -1,8 +1,8 @@
fun foo() { fun foo() {
when (a) { when (a) {
-> { -> {
System.out.println("1") println("1")
System.out.println("2") println("2")
} }
} }
} }
+1 -1
View File
@@ -20,7 +20,7 @@ public object SwitchDemo {
12 -> monthString = "December" 12 -> monthString = "December"
else -> monthString = "Invalid month" else -> monthString = "Invalid month"
} }
System.out.println(monthString) println(monthString)
} }
} }
@@ -8,7 +8,7 @@ public object NonDefault {
2 -> valueString = "TWO" 2 -> valueString = "TWO"
3 -> valueString = "THREE" 3 -> valueString = "THREE"
} }
System.out.println(valueString) println(valueString)
} }
} }
@@ -1,19 +1,19 @@
fun foo(a: Int): Int { fun foo(a: Int): Int {
when (a) { when (a) {
1 -> { 1 -> {
System.out.println("1") println("1")
return 1 return 1
} }
2 -> { 2 -> {
System.out.println("2") println("2")
return 2 return 2
} }
3 -> { 3 -> {
System.out.println("3") println("3")
throw RuntimeException() throw RuntimeException()
} }
else -> { else -> {
System.out.println("default") println("default")
return 0 return 0
} }
} }
@@ -6,7 +6,7 @@ public class C {
ByteArrayInputStream(ByteArray(10)).use { stream -> ByteArrayInputStream(ByteArray(10)).use { stream ->
// reading something // reading something
val c = stream.read() val c = stream.read()
System.out.println(c) println(c)
} }
} }
} }
@@ -3,6 +3,6 @@ import java.io.*
public class C { public class C {
throws(javaClass<IOException>()) throws(javaClass<IOException>())
fun foo() { fun foo() {
ByteArrayInputStream(ByteArray(10)).use { stream -> System.out.println(stream.read()) } ByteArrayInputStream(ByteArray(10)).use { stream -> println(stream.read()) }
} }
} }
@@ -6,10 +6,10 @@ public class C {
ByteArrayInputStream(ByteArray(10)).use { stream -> ByteArrayInputStream(ByteArray(10)).use { stream ->
// reading something // reading something
val c = stream.read() val c = stream.read()
System.out.println(c) println(c)
} }
} catch (e: IOException) { } catch (e: IOException) {
System.out.println(e) println(e)
} }
} }
@@ -6,12 +6,12 @@ public class C {
ByteArrayInputStream(ByteArray(10)).use { stream -> ByteArrayInputStream(ByteArray(10)).use { stream ->
// reading something // reading something
val c = stream.read() val c = stream.read()
System.out.println(c) println(c)
} }
} catch (e: IOException) { } catch (e: IOException) {
System.out.println(e) println(e)
} finally { } finally {
System.out.println("Finally!") println("Finally!")
} }
} }
} }
@@ -6,10 +6,10 @@ public class C {
ByteArrayInputStream(ByteArray(10)).use { stream -> ByteArrayInputStream(ByteArray(10)).use { stream ->
// reading something // reading something
val c = stream.read() val c = stream.read()
System.out.println(c) println(c)
} }
} catch (e: IOException) { } catch (e: IOException) {
System.out.println(e) println(e)
} catch (e: Exception) { } catch (e: Exception) {
System.err.println(e) System.err.println(e)
} }
@@ -7,7 +7,7 @@ public class C {
ByteArrayInputStream(ByteArray(10)).use { stream -> ByteArrayInputStream(ByteArray(10)).use { stream ->
// reading something // reading something
val c = stream.read() val c = stream.read()
System.out.println(c) println(c)
} }
} finally { } finally {
// dispose something else // dispose something else
@@ -9,7 +9,7 @@ public class C {
return c return c
} }
} catch (e: IOException) { } catch (e: IOException) {
System.out.println(e) println(e)
return -1 return -1
} }
@@ -6,6 +6,6 @@ public class AAA {
} }
public fun bar(b: B) { public fun bar(b: B) {
System.out.println(b.YY) println(b.YY)
} }
} }
@@ -3064,6 +3064,12 @@ public class JavaToKotlinConverterForWebDemoTestGenerated extends AbstractJavaTo
doTest(fileName); doTest(fileName);
} }
@TestMetadata("systemOut.java")
public void testSystemOut() throws Exception {
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/methodCallExpression/systemOut.java");
doTest(fileName);
}
@TestMetadata("vararg1.java") @TestMetadata("vararg1.java")
public void testVararg1() throws Exception { public void testVararg1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/methodCallExpression/vararg1.java"); String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/methodCallExpression/vararg1.java");
@@ -3064,6 +3064,12 @@ public class JavaToKotlinConverterSingleFileTestGenerated extends AbstractJavaTo
doTest(fileName); doTest(fileName);
} }
@TestMetadata("systemOut.java")
public void testSystemOut() throws Exception {
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/methodCallExpression/systemOut.java");
doTest(fileName);
}
@TestMetadata("vararg1.java") @TestMetadata("vararg1.java")
public void testVararg1() throws Exception { public void testVararg1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/methodCallExpression/vararg1.java"); String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/methodCallExpression/vararg1.java");