Introduce "use expression body" inspection #KT-16063 Fixed
Converted from the relevant intention Reported cases: one-liners, whens Also, more exact caret detection in local inspection tests
This commit is contained in:
committed by
Mikhail Glukhikh
parent
fe9d3f16d3
commit
d08b18f5f8
+1
-1
@@ -1,3 +1,3 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val x = listOf(1, 2, 3).filter <caret>{ it % 2 != 0 }.isEmpty()
|
||||
val x = listOf(1, 2, 3).filte<caret>r { it % 2 != 0 }.isEmpty()
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val x = listOf(1, 2, 3).filter <caret>{ it % 2 != 0 }.isNotEmpty()
|
||||
val x = listOf(1, 2, 3).filte<caret>r { it % 2 != 0 }.isNotEmpty()
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val x = listOf("1", "").filter <caret>{ element -> element.isNotEmpty() }.last()
|
||||
val x = listOf("1", "").filte<caret>r { element -> element.isNotEmpty() }.last()
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val x = "5abc".filter { it.isDigit() }.<caret>singleOrNull()
|
||||
val x = "5abc".<caret>filter { it.isDigit() }.singleOrNull()
|
||||
@@ -1,4 +1,4 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val sb = StringBuilder()
|
||||
val x = listOf(1, 2, 3).map { "$it*$it" }.<caret>joinTo(buffer = sb, prefix = "= ", separator = " + ")
|
||||
val x = listOf(1, 2, 3).<caret>map { "$it*$it" }.joinTo(buffer = sb, prefix = "= ", separator = " + ")
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val x = listOf(1, 2, 3).map { "$it*$it" }.<caret>joinToString(prefix = "= ", separator = " + ")
|
||||
val x = listOf(1, 2, 3).<caret>map { "$it*$it" }.joinToString(prefix = "= ", separator = " + ")
|
||||
Vendored
+1
-1
@@ -1,3 +1,3 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val x = listOf(1, 2, 3).map(Int::toString).<caret>joinToString(prefix = "= ", separator = " + ")
|
||||
val x = listOf(1, 2, 3).<caret>map(Int::toString).joinToString(prefix = "= ", separator = " + ")
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val x = listOf(1, 0, 2).map { if (it != 0) it else null }.<caret>filterNotNull()
|
||||
val x = listOf(1, 0, 2).<caret>map { if (it != 0) it else null }.filterNotNull()
|
||||
@@ -1,5 +1,5 @@
|
||||
fun foo(vararg x: String) {}
|
||||
|
||||
fun bar() {
|
||||
foo(*arrayOf<caret>("abc"))
|
||||
foo(*<caret>arrayOf("abc"))
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun foo(vararg x: Boolean) {}
|
||||
|
||||
fun bar() {
|
||||
foo(*booleanArrayOf<caret>(true, true))
|
||||
foo(*<caret>booleanArrayOf(true, true))
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun foo(vararg x: Byte) {}
|
||||
|
||||
fun bar() {
|
||||
foo(*byteArrayOf<caret>(1))
|
||||
foo(*<caret>byteArrayOf(1))
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun foo(vararg x: Char) {}
|
||||
|
||||
fun bar() {
|
||||
foo(*charArrayOf<caret>('a', 'b'))
|
||||
foo(*<caret>charArrayOf('a', 'b'))
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun foo(vararg x: Double) {}
|
||||
|
||||
fun bar() {
|
||||
foo(*doubleArrayOf<caret>(1.0))
|
||||
foo(*<caret>doubleArrayOf(1.0))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fun foo(vararg x: String) {}
|
||||
|
||||
fun bar() {
|
||||
foo(*emptyArray<caret><String>())
|
||||
foo(*<caret>emptyArray<String>())
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun foo(vararg x: Float) {}
|
||||
|
||||
fun bar() {
|
||||
foo(*floatArrayOf<caret>(1.0f))
|
||||
foo(<caret>*floatArrayOf(1.0f))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fun foo(vararg x: Int) {}
|
||||
|
||||
fun bar() {
|
||||
foo(*intArrayOf<caret>(1))
|
||||
foo(<caret>*intArrayOf(1))
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun foo(vararg x: Long) {}
|
||||
|
||||
fun bar() {
|
||||
foo(*longArrayOf<caret>(1L))
|
||||
foo(<caret>*longArrayOf(1L))
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun foo(vararg x: String) {}
|
||||
|
||||
fun bar() {
|
||||
foo(*arrayOf<caret>("abc", "def"))
|
||||
foo(<caret>*arrayOf("abc", "def"))
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun foo(vararg x: String) {}
|
||||
|
||||
fun bar() {
|
||||
foo(*arrayOf<caret>("abc", "def"), "ghi", "jkl")
|
||||
foo(<caret>*arrayOf("abc", "def"), "ghi", "jkl")
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun foo(vararg x: String) {}
|
||||
|
||||
fun bar() {
|
||||
foo(*arrayOf<caret>(elements = "abc"))
|
||||
foo(<caret>*arrayOf(elements = "abc"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fun foo(vararg x: String) {}
|
||||
|
||||
fun bar() {
|
||||
foo(*arrayOf<caret>())
|
||||
foo(<caret>*arrayOf())
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun foo(vararg x: Short) {}
|
||||
|
||||
fun bar() {
|
||||
foo(*shortArrayOf<caret>(1))
|
||||
foo(<caret>*shortArrayOf(1))
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.inspections.UseExpressionBodyInspection
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
interface I {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
fun bar(): I {
|
||||
<caret>return object: I {
|
||||
override fun foo(): String {
|
||||
return "a"
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
interface I {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
fun bar()<selection>: I</selection> = object: I {
|
||||
override fun foo(): String {
|
||||
return "a"
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// PROBLEM: none
|
||||
|
||||
var x = 0
|
||||
|
||||
fun <caret>foo() {
|
||||
x += 1
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// PROBLEM: none
|
||||
|
||||
var a = 1
|
||||
var b = 2
|
||||
|
||||
fun foo() {
|
||||
<caret>a = b
|
||||
}
|
||||
idea/testData/inspectionsLocal/useExpressionBody/convertToExpressionBody/constructorWithEmptyBody.kt
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// PROBLEM: none
|
||||
|
||||
class C {
|
||||
constructor()<caret> {}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun foo() {
|
||||
<caret>val v = 1
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// IS_APPLICABLE: true
|
||||
|
||||
fun nullable() {}
|
||||
|
||||
fun bar() {}
|
||||
|
||||
fun foo(f: Boolean) {
|
||||
<caret>nullable() ?: if (f) bar() else bar()
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// IS_APPLICABLE: true
|
||||
|
||||
fun nullable() {}
|
||||
|
||||
fun bar() {}
|
||||
|
||||
fun foo(f: Boolean) = nullable() ?: if (f) bar() else bar()
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun nullable() {}
|
||||
|
||||
fun bar() {}
|
||||
|
||||
fun foo(f: Boolean) {
|
||||
<caret>nullable() ?: if (f) bar()
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// PROBLEM: none
|
||||
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun whenExpr(access: AccessMode) {
|
||||
<caret>println("result") ?: when (access) {
|
||||
AccessMode.READ -> println("read")
|
||||
AccessMode.WRITE -> println("write")
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(): List<String> {
|
||||
ret<caret>urn emptyList()
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(): List<String> = emptyList()
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun foo(p: Boolean): String {
|
||||
<caret>return bar() ?: return "a"
|
||||
}
|
||||
|
||||
fun bar(): String? = null
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun foo(p: Boolean): String {
|
||||
if (p) {
|
||||
<caret>return "abc"
|
||||
}
|
||||
else {
|
||||
return "def"
|
||||
}
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
fun <caret>foo() {
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
fun foo() = Unit
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
fun <caret>foo(): Unit {
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
fun foo(): Unit = Unit
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
<caret>throw UnsupportedOperationException()
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo()<selection>: Unit</selection> = throw UnsupportedOperationException()
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun foo() = <caret>"abc"
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(): Nothing {
|
||||
<caret>throw UnsupportedOperationException()
|
||||
}
|
||||
idea/testData/inspectionsLocal/useExpressionBody/convertToExpressionBody/funWithNothingType.kt.after
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo()<selection>: Nothing</selection> = throw UnsupportedOperationException()
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun foo(): String {
|
||||
<caret>return "abc"
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
fun foo()<selection>: String</selection> = "abc"
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
fun foo() {
|
||||
<caret>bar()
|
||||
}
|
||||
|
||||
fun bar() { }
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
fun foo() = bar()
|
||||
|
||||
fun bar() { }
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun foo() {
|
||||
<caret>bar()
|
||||
}
|
||||
|
||||
fun bar(): String = "abc"
|
||||
idea/testData/inspectionsLocal/useExpressionBody/convertToExpressionBody/funWithUnitTypeWithThrow.kt
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(): Unit {
|
||||
<caret>throw UnsupportedOperationException()
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo()<selection>: Unit</selection> = throw UnsupportedOperationException()
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun foo(handler: () -> Unit) { }
|
||||
|
||||
fun bar() {
|
||||
foo { <caret>zoo() }
|
||||
}
|
||||
|
||||
fun zoo(){}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
val foo: String
|
||||
get() {
|
||||
<caret>return "abc"
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
val foo: String
|
||||
get() = "abc"
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// IS_APPLICABLE: true
|
||||
|
||||
fun bar() {}
|
||||
|
||||
fun foo(f: Boolean) {
|
||||
<caret>if (f) bar() else bar()
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// IS_APPLICABLE: true
|
||||
|
||||
fun bar() {}
|
||||
|
||||
fun foo(f: Boolean) = if (f) bar() else bar()
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun bar() {}
|
||||
|
||||
fun foo(f: Boolean) {
|
||||
<caret>if (f) bar()
|
||||
}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// IS_APPLICABLE: true
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun whenExpr(mode: Boolean, access: AccessMode) {
|
||||
<caret>if (mode) {
|
||||
when (access) {
|
||||
AccessMode.READ -> println("read")
|
||||
AccessMode.WRITE -> println("write")
|
||||
AccessMode.RW -> println("both")
|
||||
}
|
||||
}
|
||||
else {
|
||||
when (access) {
|
||||
AccessMode.READ -> println("noread")
|
||||
AccessMode.WRITE -> println("nowrite")
|
||||
AccessMode.RW -> println("no both")
|
||||
}
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// IS_APPLICABLE: true
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun whenExpr(mode: Boolean, access: AccessMode) = if (mode) {
|
||||
when (access) {
|
||||
AccessMode.READ -> println("read")
|
||||
AccessMode.WRITE -> println("write")
|
||||
AccessMode.RW -> println("both")
|
||||
}
|
||||
}
|
||||
else {
|
||||
when (access) {
|
||||
AccessMode.READ -> println("noread")
|
||||
AccessMode.WRITE -> println("nowrite")
|
||||
AccessMode.RW -> println("no both")
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// PROBLEM: none
|
||||
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun whenExpr(mode: Boolean, access: AccessMode) {
|
||||
<caret>if (mode) {
|
||||
when (access) {
|
||||
AccessMode.READ -> println("read")
|
||||
AccessMode.WRITE -> println("write")
|
||||
}
|
||||
}
|
||||
else {
|
||||
when (access) {
|
||||
AccessMode.READ -> println("noread")
|
||||
AccessMode.WRITE -> println("nowrite")
|
||||
AccessMode.RW -> println("no both")
|
||||
}
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun getText(): String {
|
||||
<caret>return "xxx" //TODO
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
fun getText(): String = "xxx" //TODO
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun getText(): String {
|
||||
// let's return xxx
|
||||
<caret>return "xxx" //TODO
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
fun getText(): String = // let's return xxx
|
||||
"xxx" //TODO
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun getText(): String { // let's return xxx
|
||||
<caret>return "xxx"
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
fun getText(): String = // let's return xxx
|
||||
"xxx"
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun getText(): String {
|
||||
/* let's return xxx */
|
||||
<caret>return "xxx" /* TODO */
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
fun getText(): String = /* let's return xxx */
|
||||
"xxx" /* TODO */
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// IS_APPLICABLE: true
|
||||
|
||||
fun <T> run(f: () -> T) = f()
|
||||
fun whenExpr(flag: Boolean) {
|
||||
<caret>run {
|
||||
println("run")
|
||||
if (flag) {
|
||||
println("flag")
|
||||
}
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// IS_APPLICABLE: true
|
||||
|
||||
fun <T> run(f: () -> T) = f()
|
||||
fun whenExpr(flag: Boolean) = run {
|
||||
println("run")
|
||||
if (flag) {
|
||||
println("flag")
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// IS_APPLICABLE: true
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun <T> run(f: () -> T) = f()
|
||||
fun whenExpr(access: AccessMode) {
|
||||
<caret>run {
|
||||
println("run")
|
||||
when (access) {
|
||||
AccessMode.READ -> println("read")
|
||||
AccessMode.WRITE -> println("write")
|
||||
}
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// IS_APPLICABLE: true
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun <T> run(f: () -> T) = f()
|
||||
fun whenExpr(access: AccessMode) = run {
|
||||
println("run")
|
||||
when (access) {
|
||||
AccessMode.READ -> println("read")
|
||||
AccessMode.WRITE -> println("write")
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun foo(): String {
|
||||
val v = 1
|
||||
<caret>return "abc"
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
open class A {
|
||||
public open fun foo(): String = ""
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
public override fun foo(): String {
|
||||
<caret>return "abc"
|
||||
}
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
open class A {
|
||||
public open fun foo(): String = ""
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
public override fun foo()<selection>: String</selection> = "abc"
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
public fun List<String>.fn() : List<String> {
|
||||
<caret>return map {
|
||||
if (it.isEmpty()) return@map "<empty>"
|
||||
it
|
||||
}
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
public fun List<String>.fn() <selection>: List<String></selection><caret> = map {
|
||||
if (it.isEmpty()) return@map "<empty>"
|
||||
it
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
public fun List<String>.fn() : List<String> {
|
||||
<caret>return map {
|
||||
if (it.isEmpty()) return emptyList()
|
||||
it
|
||||
}
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
public fun List<String>.fn() : List<String> = map {
|
||||
if (it.isEmpty()) return emptyList()
|
||||
it
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun foo() {
|
||||
<caret>return
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// IS_APPLICABLE: true
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun whenExpr(mode: Boolean, access: AccessMode) {
|
||||
<caret>when (access) {
|
||||
AccessMode.READ -> if (mode) println("read") else println("noread")
|
||||
AccessMode.WRITE -> if (mode) println("write") else println("nowrite")
|
||||
AccessMode.RW -> if (mode) println("both") else println("no both")
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// IS_APPLICABLE: true
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun whenExpr(mode: Boolean, access: AccessMode) = when (access) {
|
||||
AccessMode.READ -> if (mode) println("read") else println("noread")
|
||||
AccessMode.WRITE -> if (mode) println("write") else println("nowrite")
|
||||
AccessMode.RW -> if (mode) println("both") else println("no both")
|
||||
}
|
||||
fun println(s: String) {}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// PROBLEM: none
|
||||
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun whenExpr(mode: Boolean, access: AccessMode) {
|
||||
<caret>when (access) {
|
||||
AccessMode.READ -> if (mode) println("read") else println("noread")
|
||||
AccessMode.WRITE -> if (mode) println("write")
|
||||
AccessMode.RW -> if (mode) println("both") else println("no both")
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun whenExpr(access: AccessMode) {
|
||||
<caret>when (access) {
|
||||
AccessMode.READ -> println("read")
|
||||
AccessMode.WRITE -> println("write")
|
||||
AccessMode.RW -> println("rw")
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
idea/testData/inspectionsLocal/useExpressionBody/convertToExpressionBody/whenUnitExhaustive.kt.after
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun whenExpr(access: AccessMode) = when (access) {
|
||||
AccessMode.READ -> println("read")
|
||||
AccessMode.WRITE -> println("write")
|
||||
AccessMode.RW -> println("rw")
|
||||
}
|
||||
fun println(s: String) {}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// PROBLEM: none
|
||||
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun whenExpr(access: AccessMode) {
|
||||
<caret>when (access) {
|
||||
AccessMode.READ -> println("read")
|
||||
AccessMode.WRITE -> println("write")
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun whenExpr(access: AccessMode) {
|
||||
<caret>when (access) {
|
||||
AccessMode.READ -> println("read")
|
||||
AccessMode.WRITE -> println("write")
|
||||
else -> println("else")
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun whenExpr(access: AccessMode) = when (access) {
|
||||
AccessMode.READ -> println("read")
|
||||
AccessMode.WRITE -> println("write")
|
||||
else -> println("else")
|
||||
}
|
||||
fun println(s: String) {}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// PROBLEM: none
|
||||
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun whenExpr(mode: Boolean, access: AccessMode) {
|
||||
<caret>when (access) {
|
||||
AccessMode.READ -> when (mode) {
|
||||
true -> println("read")
|
||||
false -> println("noread")
|
||||
}
|
||||
AccessMode.WRITE -> when (mode) {
|
||||
true -> println("write")
|
||||
}
|
||||
AccessMode.RW -> when (mode) {
|
||||
true -> println("both")
|
||||
else -> println("no both")
|
||||
}
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun foo(p: Boolean): String {
|
||||
<caret>while(true) { }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
|
||||
fun abs(x: Int): Int {
|
||||
// No highlighting here
|
||||
<caret>return if (x > 0) {
|
||||
x
|
||||
}
|
||||
else {
|
||||
-x
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
|
||||
fun abs(x: Int): Int = // No highlighting here
|
||||
if (x > 0) {
|
||||
x
|
||||
}
|
||||
else {
|
||||
-x
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
|
||||
fun Int?.orZero(): Int {
|
||||
retur<caret>n this
|
||||
?: 0
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
|
||||
fun Int?.orZero(): Int = this
|
||||
?: 0
|
||||
@@ -0,0 +1,3 @@
|
||||
fun sqr(x: Int): Int {
|
||||
<caret>return x * x
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
fun sqr(x: Int): Int = x * x
|
||||
@@ -0,0 +1,7 @@
|
||||
fun sign(x: Int): Int {
|
||||
<caret>return when {
|
||||
x < 0 -> -1
|
||||
x > 0 -> 1
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun sign(x: Int): Int = when {
|
||||
x < 0 -> -1
|
||||
x > 0 -> 1
|
||||
else -> 0
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user