Files
kotlin-fork/plugins/uast-kotlin/testData/ControlStructures.kt
T
2016-04-08 15:39:58 +03:00

120 lines
2.3 KiB
Kotlin
Vendored

class ControlStructures {
val prop = 3
fun nullFun(): String? = null
fun test(): Boolean {
" "
"Z"
"Z Z"
'c'
5
5.0
5.0f
-5
+5
0.0
-0.0
1E10
1E-10
val qwe = 2
" $qwe "
"a\"b"
"a'b\r\n"
"5\n 2"
"\t\t\t"
if (5 > 3) {
println("5 > 3")
}
for (c in "ABC") {
println(c)
}
for (c: Char in "DEF") {
println(c.toByte())
}
var i = 5
while (i > 0) {
i--
if (i == 3) break
if (i == 2) {
continue
}
}
"" is String
("" as Any) as String?
super.equals(this)
this.equals(this)
this@ControlStructures.equals(this)
ControlStructures::test
ControlStructures::prop
ControlStructures::class.java
outer@ for (outerVal in 1..2) {
inner@ for (innerVal in 3..4) {
continue@outer
}
break@outer
}
nullFun()?.let { println(it) }
i = 5
do {
i -= 1
} while (i > 0)
"ABC".forEach { println(it.toString()[0]) }
"ABC".zip("DEF").forEach { println(it.first + " " + it.second) }
val arr = arrayOf("A", "B", "C")
println(arr[2])
val (a, b) = "ABC".zip("DEF")
val value = if (5 > 3) "a" else "b"
val list = listOf("A")
val list2 = listOf("A")
val type = when (value) {
in list -> "inlist"
!in list2 -> "notinlist2"
is String -> "string"
is CharSequence -> "cs"
else -> "unknown"
}
val x = when {
value == "b" -> "B"
5 % 2 == 0 -> {
println("A")
"Q"
}
false -> "!"
else -> "A"
}
try {
5 + 1
throw Exception()
} catch (e: Exception) {
e.printStackTrace()
} catch (thr: Throwable) {
System.out.println("error!")
} finally {
System.out.println("finally")
}
return false
}
}