Intention "Convert to expression body"

This commit is contained in:
Valentin Kipyatkov
2014-01-22 19:52:58 +04:00
parent d01ff28212
commit 020ea99220
32 changed files with 391 additions and 7 deletions
@@ -0,0 +1,10 @@
// "Convert to expression body" "true"
trait I {
fun foo(): String
}
fun bar(): I = object: I {
override fun foo(): String {
return "a"
}
}
@@ -0,0 +1,2 @@
// "Convert to expression body" "true"
fun foo(): Unit = throw UnsupportedOperationException()
@@ -0,0 +1,2 @@
// "Convert to expression body" "true"
fun foo(): Nothing = throw UnsupportedOperationException()
@@ -0,0 +1,2 @@
// "Convert to expression body" "true"
fun foo(): String = "abc"
@@ -0,0 +1,4 @@
// "Convert to expression body" "true"
fun foo() = bar()
fun bar() { }
@@ -0,0 +1,2 @@
// "Convert to expression body" "true"
fun foo(): Unit = throw UnsupportedOperationException()
@@ -0,0 +1,3 @@
// "Convert to expression body" "true"
val foo: String
get() = "abc"
@@ -0,0 +1,12 @@
// "Convert to expression body" "true"
trait I {
fun foo(): String
}
fun bar(): I {
<caret>return object: I {
override fun foo(): String {
return "a"
}
}
}
@@ -0,0 +1,8 @@
// "class org.jetbrains.jet.plugin.intentions.ConvertToExpressionBodyAction" "false"
var a = 1
var b = 2
fun foo() {
<caret>a = b
}
@@ -0,0 +1,5 @@
// "class org.jetbrains.jet.plugin.intentions.ConvertToExpressionBodyAction" "false"
fun foo() {
<caret>val v = 1
}
@@ -0,0 +1,7 @@
// "class org.jetbrains.jet.plugin.intentions.ConvertToExpressionBodyAction" "false"
fun foo(p: Boolean): String {
return bar() ?: return "a"
}
fun bar(): String? = null
@@ -0,0 +1,10 @@
// "class org.jetbrains.jet.plugin.intentions.ConvertToExpressionBodyAction" "false"
fun foo(p: Boolean): String {
if (p) {
<caret>return "abc"
}
else {
return "def"
}
}
@@ -0,0 +1,4 @@
// "Convert to expression body" "true"
fun foo() {
<caret>throw UnsupportedOperationException()
}
@@ -0,0 +1,3 @@
// "class org.jetbrains.jet.plugin.intentions.ConvertToExpressionBodyAction" "false"
fun foo() = <caret>"abc"
@@ -0,0 +1,4 @@
// "Convert to expression body" "true"
fun foo(): Nothing {
<caret>throw UnsupportedOperationException()
}
@@ -0,0 +1,4 @@
// "Convert to expression body" "true"
fun <caret>foo(): String {
return "abc"
}
@@ -0,0 +1,6 @@
// "Convert to expression body" "true"
fun foo() {
<caret>bar()
}
fun bar() { }
@@ -0,0 +1,7 @@
// "class org.jetbrains.jet.plugin.intentions.ConvertToExpressionBodyAction" "false"
fun foo() {
<caret>bar()
}
fun bar(): String = "abc"
@@ -0,0 +1,4 @@
// "Convert to expression body" "true"
fun foo(): Unit {
<caret>throw UnsupportedOperationException()
}
@@ -0,0 +1,9 @@
// "class org.jetbrains.jet.plugin.intentions.ConvertToExpressionBodyAction" "false"
fun foo(handler: () -> Unit) { }
fun bar() {
foo { <caret>zoo() }
}
fun zoo(){}
@@ -0,0 +1,5 @@
// "Convert to expression body" "true"
val foo: String
<caret>get() {
return "abc"
}
@@ -0,0 +1,6 @@
// "class org.jetbrains.jet.plugin.intentions.ConvertToExpressionBodyAction" "false"
fun foo(): String {
val v = 1
<caret>return "abc"
}
@@ -0,0 +1,5 @@
// "class org.jetbrains.jet.plugin.intentions.ConvertToExpressionBodyAction" "false"
fun foo() {
<caret>return
}
@@ -0,0 +1,5 @@
// "class org.jetbrains.jet.plugin.intentions.ConvertToExpressionBodyAction" "false"
fun foo(p: Boolean): String {
<caret>while(true) { }
}