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:
Mikhail Glukhikh
2017-06-29 16:50:45 +03:00
committed by Mikhail Glukhikh
parent fe9d3f16d3
commit d08b18f5f8
164 changed files with 703 additions and 548 deletions
-1
View File
@@ -1,5 +1,4 @@
// "Add 'inline' to function 'foo'" "false"
// ACTION: Convert to expression body
// ERROR: Modifier 'crossinline' is allowed only for function parameters of an inline function
fun bar() {
@@ -1,5 +1,4 @@
// "class org.jetbrains.kotlin.idea.quickfix.ChangeToStarProjectionFix" "false"
// ACTION: Convert to expression body
class Constructor<out T>(val x: T)
@@ -1,5 +1,4 @@
// "class org.jetbrains.kotlin.idea.quickfix.ChangeToStarProjectionFix" "false"
// ACTION: Convert to expression body
fun <T> get(column: String, map: Map<String, Any>): T {
return map[column] as <caret>T
}
@@ -2,7 +2,6 @@
// "Import" "false"
// ERROR: Too many arguments for public final fun foo(): Unit defined in main.X
// ACTION: Add parameter to function 'foo'
// ACTION: Convert to expression body
// ACTION: Create extension function 'X.foo'
// ACTION: Create member function 'X.foo'
@@ -2,7 +2,6 @@
// "Import" "false"
// ERROR: Too many arguments for public final fun foo(): Unit defined in main.X
// ACTION: Add parameter to function 'foo'
// ACTION: Convert to expression body
// ACTION: Create extension function 'X.foo'
// ACTION: Create member function 'X.foo'
@@ -3,7 +3,6 @@
// ERROR: Type mismatch: inferred type is Int but String was expected
// ACTION: Add 'toString()' call
// ACTION: Change parameter 'p' type of function 'main.X.foo' to 'Int'
// ACTION: Convert to expression body
// ACTION: Create function 'foo'
package main
@@ -2,7 +2,6 @@
// "Import" "false"
// ERROR: Too many arguments for public final fun foo(): Unit defined in main.X
// ACTION: Add parameter to function 'foo'
// ACTION: Convert to expression body
// ACTION: Create extension function 'X.foo'
// ACTION: Create member function 'X.foo'
@@ -1,6 +1,5 @@
// "Import" "false"
// ERROR: Unresolved reference: Some
// ACTION: Convert to expression body
// ACTION: Create function 'Some'
// ACTION: Rename reference
@@ -1,6 +1,5 @@
// "Import" "false"
// ERROR: Unresolved reference: Some
// ACTION: Convert to expression body
// ACTION: Create function 'Some'
// ACTION: Rename reference
@@ -1,6 +1,5 @@
// "Create annotation 'foo'" "false"
// ERROR: Unresolved reference: foo
// ACTION: Convert to expression body
// ACTION: Make private
// ACTION: Make internal
@@ -1,5 +1,4 @@
// "Create abstract function 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create function 'foo'
// ACTION: Rename reference
// ERROR: Unresolved reference: foo
@@ -1,5 +1,4 @@
// "Create abstract function 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create extension function 'B.foo'
// ACTION: Create member function 'B.foo'
// ACTION: Rename reference
@@ -4,7 +4,6 @@
// ACTION: Make private
// ACTION: Rename reference
// ACTION: Put arguments on separate lines
// ACTION: Convert to expression body
// ERROR: Unresolved reference: foo
// ERROR: Unresolved reference: bar
@@ -1,5 +1,4 @@
// "Create extension function 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create function 'foo'
// ACTION: Rename reference
// ERROR: Unresolved reference: foo
@@ -1,5 +1,4 @@
// "Create member function 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create extension function 'A.foo'
// ACTION: Rename reference
// ERROR: Unresolved reference: foo
@@ -1,5 +1,4 @@
// "Create member function 'foo'" "false"
// ACTION: Convert to expression body
// ERROR: Unresolved reference: x
class A<T>(val n: T) {
@@ -1,5 +1,4 @@
// "Create function 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Rename reference
// ERROR: Unresolved reference: foo
fun bar(n: Int) = "$n"
@@ -1,5 +1,4 @@
// "Create parameter 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create property 'foo'
// ACTION: Rename reference
@@ -1,5 +1,4 @@
// "Create parameter 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create property 'foo'
// ACTION: Rename reference
@@ -1,5 +1,4 @@
// "Create parameter 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create abstract property 'foo'
// ACTION: Rename reference
@@ -1,5 +1,4 @@
// "Create parameter 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create property 'foo'
// ACTION: Rename reference
@@ -1,5 +1,4 @@
// "Create parameter 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create property 'foo'
// ACTION: Create extension property 'T.foo'
@@ -1,5 +1,4 @@
// "Create parameter 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create property 'foo'
// ACTION: Create extension property 'T.foo'
@@ -1,5 +1,4 @@
// "Create property 'foo' as constructor parameter" "false"
// ACTION: Convert to expression body
// ACTION: Create parameter 'foo'
// ACTION: Create local variable 'foo'
// ACTION: Rename reference
@@ -1,5 +1,4 @@
// "Create property 'foo' as constructor parameter" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create parameter 'foo'
// ACTION: Create property 'foo'
@@ -1,6 +1,5 @@
// "Create property 'foo' as constructor parameter" "false"
// ACTION: Create property 'foo'
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create parameter 'foo'
// ACTION: Rename reference
@@ -1,6 +1,5 @@
// "Create property 'foo' as constructor parameter" "false"
// ACTION: Create member property 'A.foo'
// ACTION: Convert to expression body
// ACTION: Create extension property 'A.foo'
// ACTION: Rename reference
// ERROR: Unresolved reference: foo
@@ -1,5 +1,4 @@
// "Create abstract property 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create parameter 'foo'
// ACTION: Create property 'foo'
@@ -1,5 +1,4 @@
// "Create abstract property 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create extension property 'B.foo'
// ACTION: Create member property 'B.foo'
// ACTION: Create property 'foo' as constructor parameter
@@ -1,5 +1,4 @@
// "Create property 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create parameter 'foo'
// ACTION: Create local variable 'foo'
// ACTION: Rename reference
@@ -1,7 +1,6 @@
// "Create member property 'bar'" "false"
// ACTION: Create extension property 'T.bar'
// ACTION: Rename reference
// ACTION: Convert to expression body
// ERROR: Unresolved reference: bar
fun consume(n: Int) {}
@@ -1,5 +1,4 @@
// "Create property 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create extension property 'A.foo'
// ACTION: Rename reference
// ERROR: Unresolved reference: foo
@@ -1,5 +1,4 @@
// "Create property 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create extension property 'A.foo'
// ACTION: Rename reference
// ERROR: Unresolved reference: foo
-1
View File
@@ -1,5 +1,4 @@
// "Create label foo@" "false"
// ACTION: Convert to expression body
// ERROR: The label '@foo' does not denote a loop
// ERROR: Unresolved reference: @foo
-1
View File
@@ -1,5 +1,4 @@
// "Create label foo@" "false"
// ACTION: Convert to expression body
// ERROR: The label '@foo' does not denote a loop
// ERROR: Unresolved reference: @foo
-1
View File
@@ -1,5 +1,4 @@
// "Create label foo@" "false"
// ACTION: Convert to expression body
// ERROR: Unresolved reference: @foo
fun test(): Int {
@@ -3,7 +3,6 @@
// ACTION: Make 'Nested' internal
// ACTION: Make 'Nested' public
// ACTION: Remove parameter 'arg'
// ACTION: Convert to expression body
// ERROR: 'internal' function exposes its 'private' parameter type argument Nested
// ERROR: Cannot access 'Nested': it is private in 'Outer'
@@ -1,6 +1,5 @@
// "Move annotation to receiver type" "false"
// ERROR: '@receiver:' annotations can only be applied to the receiver type of extension function or extension property declarations
// ACTION: Convert to expression body
// ACTION: Make internal
// ACTION: Make private
@@ -1,5 +1,4 @@
// "Make A.foo open" "false"
// ACTION: Convert to expression body
// ERROR: This type is final, so it cannot be inherited from
class A() {
open fun foo() {}
@@ -1,6 +1,5 @@
// "Replace with safe (?.) call" "false"
// ACTION: Add non-null asserted (!!) call
// ACTION: Convert to expression body
// ACTION: Replace with safe (this?.) call
// ERROR: Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type A?
@@ -2,7 +2,6 @@
// ACTION: Add 'toString()' call
// ACTION: Add non-null asserted (!!) call
// ACTION: Change parameter 's' type of function 'bar' to 'String?'
// ACTION: Convert to expression body
// ACTION: Create function 'bar'
// ACTION: Surround with null check
// ACTION: Wrap with '?.let { ... }' call
@@ -1,6 +1,5 @@
// "Cast expression 'Foo<Number>()' to 'Foo<Int>'" "false"
// ACTION: Change return type of enclosing function 'foo' to 'Foo<Number>'
// ACTION: Convert to expression body
// ERROR: Type mismatch: inferred type is Foo<Number> but Foo<Int> was expected
class Foo<T>
@@ -1,6 +1,5 @@
// "Let 'B' implement interface 'A<Int>'" "false"
// ACTION: Change parameter 'a' type of function 'let.implement.foo' to 'B'
// ACTION: Convert to expression body
// ACTION: Create function 'foo'
// ERROR: Type mismatch: inferred type is B but A<Int> was expected
package let.implement
@@ -1,6 +1,5 @@
// "Let 'B' implement interface 'A<*>'" "false"
// ACTION: Change parameter 'a' type of function 'let.implement.foo' to 'B'
// ACTION: Convert to expression body
// ACTION: Create function 'foo'
// ERROR: Type mismatch: inferred type is B but A<*> was expected
@@ -1,6 +1,5 @@
// "Let 'B' implement interface 'A<Int>'" "false"
// ACTION: Change parameter 'a' type of function 'let.implement.foo' to 'B'
// ACTION: Convert to expression body
// ACTION: Create function 'foo'
// ERROR: Type mismatch: inferred type is B but A<Int> was expected
package let.implement
@@ -1,6 +1,5 @@
// "Let 'String' implement interface 'A'" "false"
// ACTION: Change parameter 'a' type of function 'let.implement.foo' to 'String'
// ACTION: Convert to expression body
// ACTION: To raw string literal
// ACTION: Create function 'foo'
// ERROR: Type mismatch: inferred type is String but A was expected
@@ -1,6 +1,5 @@
// "Change return type of called function 'AA.f' to 'Boolean'" "false"
// ACTION: Change return type of enclosing function 'AAA.g' to 'Int'
// ACTION: Convert to expression body
// ERROR: Type mismatch: inferred type is Int but Boolean was expected
interface A {
fun f(): Int
@@ -1,6 +1,5 @@
// "Change return type of called function 'AA.contains' to 'Int'" "false"
// ACTION: Change return type of enclosing function 'AAA.g' to 'Boolean'
// ACTION: Convert to expression body
// ACTION: Replace overloaded operator with function call
// ERROR: Type mismatch: inferred type is Boolean but Int was expected
interface A {
@@ -1,5 +1,4 @@
// "Suppress for declarations annotated by 'kotlin.Deprecated'" "false"
// ACTION: Create test
// ACTION: Convert to expression body
@Deprecated("")
fun foo<caret>(){}
@@ -1,7 +1,6 @@
// "Suppress for declarations annotated by 'org.jetbrains.annotations.NonNls'" "false"
// ACTION: Safe delete 'foo'
// ACTION: Create test
// ACTION: Convert to expression body
import org.jetbrains.annotations.NonNls
@NonNls