Add inspection to detect use of callable reference as a lambda body
So #KT-17053 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
53e11cbeb5
commit
0eceef1519
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.inspections.MoveSuspiciousCallableReferenceIntoParenthesesInspection
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// PROBLEM: Suspicious callable reference as the only lambda element
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).map {<caret> it::toString }
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// PROBLEM: Suspicious callable reference as the only lambda element
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).map(Int::toString)
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).map {<caret> it::toString }
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).map(Int::toString)
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
x(1) {<caret> ::y }
|
||||
}
|
||||
|
||||
fun y() {
|
||||
|
||||
}
|
||||
|
||||
fun x(number: Int, func: () -> Unit) {
|
||||
|
||||
}
|
||||
idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses/lambdaWithArg.kt.after
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
x(1, ::y)
|
||||
}
|
||||
|
||||
fun y() {
|
||||
|
||||
}
|
||||
|
||||
fun x(number: Int, func: () -> Unit) {
|
||||
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
// PROBLEM: none
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).map {<caret>
|
||||
println(it)
|
||||
Int::toString
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).map {<caret>}
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).map {<caret> println(it) }
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).map {<caret> Int::toString }
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).map(Int::toString)
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// FIX: Move suspicious callable reference into parentheses '()'
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).map {<caret> bar -> bar::toString }
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// FIX: Move suspicious callable reference into parentheses '()'
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).map(Int::toString)
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).map { bar -> bar::toString }
|
||||
listOf(4,5).map {<caret> bar -> bar::toString }
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).map { bar -> bar::toString }
|
||||
listOf(4,5).map(Int::toString)
|
||||
}
|
||||
Reference in New Issue
Block a user