Add inspection to detect use of callable reference as a lambda body

So #KT-17053 Fixed
This commit is contained in:
shiraji
2017-04-20 00:03:06 +09:00
committed by Mikhail Glukhikh
parent 53e11cbeb5
commit 0eceef1519
21 changed files with 292 additions and 5 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.MoveSuspiciousCallableReferenceIntoParenthesesInspection
@@ -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 }
}
@@ -0,0 +1,6 @@
// PROBLEM: Suspicious callable reference as the only lambda element
// WITH_RUNTIME
fun foo() {
listOf(1,2,3).map(Int::toString)
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo() {
listOf(1,2,3).map {<caret> it::toString }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo() {
listOf(1,2,3).map(Int::toString)
}
@@ -0,0 +1,13 @@
// WITH_RUNTIME
fun foo() {
x(1) {<caret> ::y }
}
fun y() {
}
fun x(number: Int, func: () -> Unit) {
}
@@ -0,0 +1,13 @@
// WITH_RUNTIME
fun foo() {
x(1, ::y)
}
fun y() {
}
fun x(number: Int, func: () -> Unit) {
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// PROBLEM: none
fun foo() {
listOf(1,2,3).map {<caret>
println(it)
Int::toString
}
}
@@ -0,0 +1,6 @@
// PROBLEM: none
// WITH_RUNTIME
fun foo() {
listOf(1,2,3).map {<caret>}
}
@@ -0,0 +1,6 @@
// PROBLEM: none
// WITH_RUNTIME
fun foo() {
listOf(1,2,3).map {<caret> println(it) }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo() {
listOf(1,2,3).map {<caret> Int::toString }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo() {
listOf(1,2,3).map(Int::toString)
}
@@ -0,0 +1,6 @@
// FIX: Move suspicious callable reference into parentheses '()'
// WITH_RUNTIME
fun foo() {
listOf(1,2,3).map {<caret> bar -> bar::toString }
}
@@ -0,0 +1,6 @@
// FIX: Move suspicious callable reference into parentheses '()'
// WITH_RUNTIME
fun foo() {
listOf(1,2,3).map(Int::toString)
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
listOf(1,2,3).map { bar -> bar::toString }
listOf(4,5).map {<caret> bar -> bar::toString }
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
listOf(1,2,3).map { bar -> bar::toString }
listOf(4,5).map(Int::toString)
}