KT-9664 Add quickfix to convert a piece of code to pretty look SAM-style
#KT-9664 Fixed
This commit is contained in:
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.intentions.ObjectLiteralToLambdaIntention
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(runnable: Runnable) {}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>object : Runnable {
|
||||
override fun run() {
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(runnable: Runnable) {}
|
||||
|
||||
fun bar() {
|
||||
foo(Runnable { })
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
|
||||
fun foo(filter: FileFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>object: FileFilter {
|
||||
override fun accept(file: File) = file.name.startsWith("a")
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
|
||||
fun foo(filter: FileFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(FileFilter { file -> file.name.startsWith("a") })
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(runnable: Runnable) {}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>object : Runnable {
|
||||
val v = "a".hashCode()
|
||||
|
||||
override fun run() {
|
||||
print(v)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
interface I
|
||||
|
||||
fun foo(runnable: Runnable) {}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>object : Runnable, I {
|
||||
override fun run() {
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FilenameFilter
|
||||
|
||||
fun foo(filter: FilenameFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>object: FilenameFilter {
|
||||
override fun accept(file: File, name: String) = name == "x"
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FilenameFilter
|
||||
|
||||
fun foo(filter: FilenameFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(FilenameFilter { file, name -> name == "x" })
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
fun bar() {
|
||||
SwingUtilities.invokeLater(<caret>object: Runnable {
|
||||
override fun run() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
fun bar() {
|
||||
SwingUtilities.invokeLater({ throw UnsupportedOperationException() })
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(runnable: Runnable) {}
|
||||
|
||||
fun bar() {
|
||||
foo(object : Runnable <caret>{
|
||||
override fun run() {
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(runnable: Runnable) {}
|
||||
|
||||
fun bar() {
|
||||
foo<caret>(object : Runnable {
|
||||
override fun run() {
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
interface MyRunnable {
|
||||
fun run()
|
||||
}
|
||||
|
||||
fun foo(runnable: MyRunnable) {}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>object : MyRunnable {
|
||||
override fun run() {
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FilenameFilter
|
||||
|
||||
fun foo(filter: FilenameFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>object: FilenameFilter {
|
||||
override fun accept(file: File, name: String) = true
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FilenameFilter
|
||||
|
||||
fun foo(filter: FilenameFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(FilenameFilter { true })
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(runnable: Runnable) {}
|
||||
|
||||
fun bar(list: List<String>) {
|
||||
foo(<caret>object : Runnable {
|
||||
override fun run() {
|
||||
list.filter(fun (element: String): Boolean {
|
||||
if (element == "a") return false
|
||||
if (element == "b") return@run
|
||||
return true
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(runnable: Runnable) {}
|
||||
|
||||
fun bar(list: List<String>) {
|
||||
foo(Runnable {
|
||||
list.filter(fun (element: String): Boolean {
|
||||
if (element == "a") return false
|
||||
if (element == "b") return@Runnable
|
||||
return true
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(runnable: Runnable) {}
|
||||
|
||||
fun bar(p: Int) {
|
||||
foo(<caret>object : Runnable {
|
||||
override fun run() {
|
||||
if (p < 0) return
|
||||
println("a")
|
||||
println("b")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(runnable: Runnable) {}
|
||||
|
||||
fun bar(p: Int) {
|
||||
foo(Runnable {
|
||||
if (p < 0) return@Runnable
|
||||
println("a")
|
||||
println("b")
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FilenameFilter
|
||||
|
||||
fun foo(filter: FilenameFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>object: FilenameFilter {
|
||||
override fun accept(file: File, name: String): Boolean {
|
||||
if (file.isDirectory) return true
|
||||
return name == "x"
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FilenameFilter
|
||||
|
||||
fun foo(filter: FilenameFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(FilenameFilter { file, name ->
|
||||
if (file.isDirectory) return@FilenameFilter true
|
||||
name == "x"
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
|
||||
fun foo(filter: FileFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>object: FileFilter {
|
||||
override fun accept(file: File): Boolean {
|
||||
val name = file.name
|
||||
if (name.startsWith("a")) {
|
||||
return false
|
||||
}
|
||||
else {
|
||||
if (name.endsWith("b"))
|
||||
return true
|
||||
else {
|
||||
val l = name.length
|
||||
return l > 10
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
|
||||
fun foo(filter: FileFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(FileFilter { file ->
|
||||
val name = file.name
|
||||
if (name.startsWith("a")) {
|
||||
false
|
||||
}
|
||||
else {
|
||||
if (name.endsWith("b"))
|
||||
true
|
||||
else {
|
||||
val l = name.length
|
||||
l > 10
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
|
||||
fun foo(filter: FileFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>object: FileFilter {
|
||||
override fun accept(file: File): Boolean {
|
||||
val name = file.name
|
||||
when (name) {
|
||||
"foo" -> return true
|
||||
|
||||
"bar" -> return false
|
||||
|
||||
else -> {
|
||||
if (name.startsWith("a")) return true
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
|
||||
fun foo(filter: FileFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(FileFilter { file ->
|
||||
val name = file.name
|
||||
when (name) {
|
||||
"foo" -> true
|
||||
|
||||
"bar" -> false
|
||||
|
||||
else -> {
|
||||
if (name.startsWith("a")) return@FileFilter true
|
||||
false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(runnable: Runnable) {}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>object : Runnable {
|
||||
override fun run() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(runnable: Runnable) {}
|
||||
|
||||
fun bar() {
|
||||
foo(Runnable { throw UnsupportedOperationException() })
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
|
||||
fun foo(filter: FileFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>object: FileFilter {
|
||||
override fun accept(file: File): Boolean {
|
||||
return file.name.startsWith("a")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
|
||||
fun foo(filter: FileFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(FileFilter { file -> file.name.startsWith("a") })
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
|
||||
fun foo(filter: FileFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>object: FileFilter {
|
||||
override fun accept(file: File): Boolean {
|
||||
val name = file.name
|
||||
return name.startsWith("a")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
|
||||
fun foo(filter: FileFilter) {}
|
||||
|
||||
fun bar() {
|
||||
foo(FileFilter { file ->
|
||||
val name = file.name
|
||||
name.startsWith("a")
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(runnable: Runnable) {}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>object : Runnable {
|
||||
override fun run() {
|
||||
f()
|
||||
}
|
||||
|
||||
fun f() {}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<problems>
|
||||
<problem>
|
||||
<file>StatementAndReturn.kt</file>
|
||||
<line>8</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="StatementAndReturn.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>SingleReturn.kt</file>
|
||||
<line>8</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="SingleReturn.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>Simple.kt</file>
|
||||
<line>6</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="Simple.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>ReturnNoValue.kt</file>
|
||||
<line>6</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="ReturnNoValue.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>ReturnNotLast.kt</file>
|
||||
<line>8</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="ReturnNotLast.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>ParametersNotUsed.kt</file>
|
||||
<line>8</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="ParametersNotUsed.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>NoSamAdapterNeeded.kt</file>
|
||||
<line>6</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="NoSamAdapterNeeded.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>MultipleParameters.kt</file>
|
||||
<line>8</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="MultipleParameters.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>ExpressionBody.kt</file>
|
||||
<line>8</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="ExpressionBody.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>EmptyBody.kt</file>
|
||||
<line>6</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="EmptyBody.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>ReturnsInWhen.kt</file>
|
||||
<line>8</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="ReturnsInWhen.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>ReturnsInIf.kt</file>
|
||||
<line>8</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="ReturnsInIf.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>NotInRange2.kt</file>
|
||||
<line>7</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="NotInRange2.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>NotInRange1.kt</file>
|
||||
<line>7</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="NotInRange1.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>QualifiedReturn.kt</file>
|
||||
<line>6</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="QualifiedReturn.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Convert object literal to lambda</problem_class>
|
||||
<description>Convert to lambda</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+1
@@ -0,0 +1 @@
|
||||
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.intentions.ObjectLiteralToLambdaInspection
|
||||
Reference in New Issue
Block a user