Get rid of obsolete syntax in quickfixes changing lambda's signature
- Do not wrap parameters with '()' - Do not set return type for them - Fix existing testData
This commit is contained in:
@@ -228,6 +228,12 @@ public open class JetChangeInfo(
|
||||
}
|
||||
|
||||
public fun getNewParametersSignature(inheritedCallable: JetCallableDefinitionUsage<PsiElement>): String {
|
||||
return "(" + getNewParametersSignatureWithoutParentheses(inheritedCallable) + ")"
|
||||
}
|
||||
|
||||
public fun getNewParametersSignatureWithoutParentheses(
|
||||
inheritedCallable: JetCallableDefinitionUsage<PsiElement>
|
||||
): String {
|
||||
val signatureParameters = getNonReceiverParameters()
|
||||
|
||||
val isLambda = inheritedCallable.getDeclaration() is JetFunctionLiteral
|
||||
@@ -237,7 +243,7 @@ public open class JetChangeInfo(
|
||||
|
||||
return signatureParameters.indices
|
||||
.map { i -> signatureParameters[i].getDeclarationSignature(i, inheritedCallable) }
|
||||
.joinToString(prefix = "(", separator = ", ", postfix = ")")
|
||||
.joinToString(separator = ", ")
|
||||
}
|
||||
|
||||
public fun renderReceiverType(inheritedCallable: JetCallableDefinitionUsage<PsiElement>): String? {
|
||||
|
||||
+4
-5
@@ -227,9 +227,8 @@ public class JetCallableDefinitionUsage<T extends PsiElement> extends JetUsageIn
|
||||
|
||||
boolean returnTypeIsNeeded;
|
||||
if (element instanceof JetFunction) {
|
||||
returnTypeIsNeeded = (changeInfo.isRefactoringTarget(originalCallableDescriptor) ||
|
||||
!(callable instanceof JetFunctionLiteral) ||
|
||||
callable.getTypeReference() != null);
|
||||
returnTypeIsNeeded = !(callable instanceof JetFunctionLiteral)
|
||||
&& (changeInfo.isRefactoringTarget(originalCallableDescriptor) || callable.getTypeReference() != null);
|
||||
}
|
||||
else {
|
||||
returnTypeIsNeeded = element instanceof JetProperty || element instanceof JetParameter;
|
||||
@@ -261,7 +260,7 @@ public class JetCallableDefinitionUsage<T extends PsiElement> extends JetUsageIn
|
||||
|
||||
JetParameterList newParameterList = null;
|
||||
if (isLambda) {
|
||||
if (parametersCount == 0 && ((JetFunctionLiteral) element).getTypeReference() == null) {
|
||||
if (parametersCount == 0) {
|
||||
if (parameterList != null) {
|
||||
parameterList.delete();
|
||||
PsiElement arrow = ((JetFunctionLiteral)element).getArrow();
|
||||
@@ -272,7 +271,7 @@ public class JetCallableDefinitionUsage<T extends PsiElement> extends JetUsageIn
|
||||
}
|
||||
}
|
||||
else {
|
||||
newParameterList = psiFactory.createFunctionLiteralParameterList(changeInfo.getNewParametersSignature(
|
||||
newParameterList = psiFactory.createFunctionLiteralParameterList(changeInfo.getNewParametersSignatureWithoutParentheses(
|
||||
(JetCallableDefinitionUsage<PsiElement>) this)
|
||||
);
|
||||
canReplaceEntireList = true;
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
// DISABLE-ERRORS
|
||||
|
||||
fun f(x: Int, y: Int, z : () -> Int) {
|
||||
f(1, 2, {(x: Int, y: Int<caret>) -> x});
|
||||
f(1, 2, {x: Int, y: Int<caret> -> x});
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
// DISABLE-ERRORS
|
||||
|
||||
fun f(x: Int, y: Int, z : (Int, Int?, Any) -> Int) {
|
||||
f(1, 2, {(<caret>x: Int) -> x});
|
||||
f(1, 2, {<caret>x: Int -> x});
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,5 +2,5 @@
|
||||
// DISABLE-ERRORS
|
||||
|
||||
fun f(x: Int, y: Int, z : (Int, Int?, Any) -> Int) {
|
||||
f(1, 2, {(i: Int, i1: Int?, any: Any) -> x});
|
||||
f(1, 2, { i: Int, i1: Int?, any: Any -> x});
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ fun foo(f: Int.(Int, Int) -> Int) {
|
||||
}
|
||||
|
||||
fun test() {
|
||||
foo { <caret>(a: Int) -> 0 }
|
||||
foo { <caret>a: Int -> 0 }
|
||||
}
|
||||
+1
-1
@@ -5,5 +5,5 @@ fun foo(f: Int.(Int, Int) -> Int) {
|
||||
}
|
||||
|
||||
fun test() {
|
||||
foo {(i: Int, i1: Int) -> 0 }
|
||||
foo { i: Int, i1: Int -> 0 }
|
||||
}
|
||||
+1
-1
@@ -2,5 +2,5 @@
|
||||
// DISABLE-ERRORS
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
Test<String>().perform("") {(s: String?, s1: String?) -> }
|
||||
Test<String>().perform("") { s: String?, s1: String? -> }
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// "Change type from 'String' to '(Int) -> String'" "true"
|
||||
fun foo(f: ((Int) -> String) -> String) {
|
||||
foo {
|
||||
(f: String<caret>) -> f(42)
|
||||
f: String<caret> -> f(42)
|
||||
}
|
||||
}
|
||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
// "Change type from 'String' to '(Int) -> String'" "true"
|
||||
fun foo(f: ((Int) -> String) -> String) {
|
||||
foo {
|
||||
(f: (Int) -> String<caret>) -> f(42)
|
||||
f: (Int) -> String<caret> -> f(42)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,6 +2,6 @@
|
||||
|
||||
fun foo(f: ((java.util.LinkedHashSet<Int>) -> java.util.HashSet<Int>) -> String) {
|
||||
foo {
|
||||
(f: String<caret>) -> "42"
|
||||
f: String<caret> -> "42"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,6 +5,6 @@ import java.util.LinkedHashSet
|
||||
|
||||
fun foo(f: ((java.util.LinkedHashSet<Int>) -> java.util.HashSet<Int>) -> String) {
|
||||
foo {
|
||||
(f: (LinkedHashSet<Int>) -> HashSet<Int>) -> "42"
|
||||
f: (LinkedHashSet<Int>) -> HashSet<Int> -> "42"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// "Change type from 'String' to 'Int'" "true"
|
||||
fun foo(f: (Int) -> String) {
|
||||
foo {
|
||||
(x: String<caret>) -> ""
|
||||
x: String<caret> -> ""
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// "Change type from 'String' to 'Int'" "true"
|
||||
fun foo(f: (Int) -> String) {
|
||||
foo {
|
||||
(x: Int) -> ""
|
||||
x: Int -> ""
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,6 +2,6 @@
|
||||
|
||||
fun foo(f: (java.util.HashSet<Int>) -> String) {
|
||||
foo {
|
||||
(x: String<caret>) -> ""
|
||||
x: String<caret> -> ""
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,6 +4,6 @@ import java.util.HashSet
|
||||
|
||||
fun foo(f: (java.util.HashSet<Int>) -> String) {
|
||||
foo {
|
||||
(x: HashSet<Int>) -> ""
|
||||
x: HashSet<Int> -> ""
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Change 'f' type to '(Long) -> Unit'" "true"
|
||||
fun foo() {
|
||||
var f: Int = if (true) { (x: Long) -> }<caret> else { (x: Long) -> }
|
||||
var f: Int = if (true) { x: Long -> }<caret> else { x: Long -> }
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Change 'f' type to '(Long) -> Unit'" "true"
|
||||
fun foo() {
|
||||
var f: (Long) -> Unit = if (true) { (x: Long) -> }<caret> else { (x: Long) -> }
|
||||
var f: (Long) -> Unit = if (true) { x: Long -> }<caret> else { x: Long -> }
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// "Change 'f' type to '(Delegates) -> Unit'" "true"
|
||||
|
||||
fun foo() {
|
||||
var f: Int = { (x: kotlin.properties.Delegates) -> }<caret>
|
||||
var f: Int = { x: kotlin.properties.Delegates -> }<caret>
|
||||
}
|
||||
+1
-1
@@ -3,5 +3,5 @@ import kotlin.properties.Delegates
|
||||
// "Change 'f' type to '(Delegates) -> Unit'" "true"
|
||||
|
||||
fun foo() {
|
||||
var f: (Delegates) -> Unit = { (x: kotlin.properties.Delegates) -> }
|
||||
var f: (Delegates) -> Unit = { x: kotlin.properties.Delegates -> }
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Change 'foo' function return type to '(Long) -> Int'" "true"
|
||||
fun foo(x: Any): Int {
|
||||
return {(x: Long) -> 42}<caret>
|
||||
return {x: Long -> 42}<caret>
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Change 'foo' function return type to '(Long) -> Int'" "true"
|
||||
fun foo(x: Any): (Long) -> Int {
|
||||
return {(x: Long) -> 42}<caret>
|
||||
return {x: Long -> 42}<caret>
|
||||
}
|
||||
+1
-1
@@ -8,5 +8,5 @@
|
||||
// ERROR: Unresolved reference: NoSuchType
|
||||
|
||||
fun foo(): Int {
|
||||
return { (x: NoSuchType<caret>) -> 42 }
|
||||
return { x: NoSuchType<caret> -> 42 }
|
||||
}
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// "Change 'f' type to '(Int, Int) -> (String) -> Int'" "true"
|
||||
fun foo() {
|
||||
val f: () -> Long = {
|
||||
(a: Int, b: Int): Long ->
|
||||
val x = {(s: String) -> 42}
|
||||
a: Int, b: Int ->
|
||||
val x = {s: String -> 42}
|
||||
if (true) x
|
||||
else if (true) x else {
|
||||
var y = 42
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// "Change 'f' type to '(Int, Int) -> (String) -> Int'" "true"
|
||||
fun foo() {
|
||||
val f: (Int, Int) -> (String) -> Int = {
|
||||
(a: Int, b: Int): (String) -> Int ->
|
||||
val x = {(s: String) -> 42}
|
||||
a: Int, b: Int ->
|
||||
val x = {s: String -> 42}
|
||||
if (true) x
|
||||
else if (true) x else {
|
||||
var y = 42
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
fun foo() {
|
||||
val v1 = {(z: Int, y1: String, x: Any): Int -> println(z); println(y1) }
|
||||
val v1 = { z: Int, y1: String, x: Any -> println(z); println(y1) }
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
fun foo() {
|
||||
val v1 = {(<caret>z: Int, y: String) -> println(z); println(y) }
|
||||
val v1 = {<caret>z: Int, y: String -> println(z); println(y) }
|
||||
}
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
fun test() {
|
||||
SamTest.test(Foo<String, Int> { (s, n) -> "" })
|
||||
SamTest.test(Foo { (s: MutableList<X<Int>>, n: X<MutableSet<String>>) -> "" })
|
||||
SamTest.test(Foo { (s: MutableList<X<Int>>, n: X<MutableSet<String>>): X<MutableList<String>>? -> "" })
|
||||
SamTest.test(Foo<String, Int> { s, n -> "" })
|
||||
SamTest.test(Foo { s: MutableList<X<Int>>, n: X<MutableSet<String>> -> "" })
|
||||
SamTest.test(Foo { s: MutableList<X<Int>>, n: X<MutableSet<String>> -> "" })
|
||||
}
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
fun test() {
|
||||
SamTest.test(Foo<String, Int> { (s, n) -> "" })
|
||||
SamTest.test(Foo { (s: String, n: Int) -> "" })
|
||||
SamTest.test(Foo { (s: String, n: Int): String -> "" })
|
||||
SamTest.test(Foo<String, Int> { s, n -> "" })
|
||||
SamTest.test(Foo { s: String, n: Int -> "" })
|
||||
SamTest.test(Foo { s: String, n: Int -> "" })
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun test() {
|
||||
JTest.samTest(SAM { " " })
|
||||
JTest.samTest(SAM { () -> " " })
|
||||
JTest.samTest(SAM { -> " " })
|
||||
JTest.samTest(SAM { -> " " })
|
||||
}
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
fun test() {
|
||||
JTest.samTest(SAM {(s, n, o) -> s + " " + n })
|
||||
JTest.samTest(SAM { s, n, o -> s + " " + n })
|
||||
}
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
fun test() {
|
||||
JTest.samTest(SAM { (s, n) -> s + " " + n })
|
||||
JTest.samTest(SAM { s, n -> s + " " + n })
|
||||
}
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
fun test() {
|
||||
JTest.samTest(SAM {(n, s) -> s + " " })
|
||||
JTest.samTest(SAM {(n, s) -> s + " " })
|
||||
JTest.samTest(SAM {(n, it) -> it + " " })
|
||||
JTest.samTest(SAM { n, s -> s + " " })
|
||||
JTest.samTest(SAM { n, s -> s + " " })
|
||||
JTest.samTest(SAM { n, it -> it + " " })
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun test() {
|
||||
JTest.samTest(SAM { s -> s + " " })
|
||||
JTest.samTest(SAM { (s) -> s + " " })
|
||||
JTest.samTest(SAM { s -> s + " " })
|
||||
JTest.samTest(SAM { it + " " })
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
fun test() {
|
||||
JTest.samTest(SAM { (s, n) -> s + " " })
|
||||
JTest.samTest(SAM { (s, n): Any? -> s + " " })
|
||||
JTest.samTest(SAM { s, n -> s + " " })
|
||||
JTest.samTest(SAM { s, n -> s + " " })
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
fun test() {
|
||||
JTest.samTest(SAM { (s, n) -> s + " " })
|
||||
JTest.samTest(SAM { (s, n): String -> s + " " })
|
||||
JTest.samTest(SAM { s, n -> s + " " })
|
||||
JTest.samTest(SAM { s, n -> s + " " })
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
fun test() {
|
||||
JTest.samTest(SAM { (s, n) -> s + " " })
|
||||
JTest.samTest(SAM { (s: Any, n: Int) -> x + " " })
|
||||
JTest.samTest(SAM { s, n -> s + " " })
|
||||
JTest.samTest(SAM { s: Any, n: Int -> x + " " })
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
fun test() {
|
||||
JTest.samTest(SAM { (s, n) -> s + " " })
|
||||
JTest.samTest(SAM { (s: String, n: Int) -> x + " " })
|
||||
JTest.samTest(SAM { s, n -> s + " " })
|
||||
JTest.samTest(SAM { s: String, n: Int -> x + " " })
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
fun test() {
|
||||
JTest.samTest(SAM { (s, n) -> s + " " })
|
||||
JTest.samTest(SAM { (x, y) -> x + " " })
|
||||
JTest.samTest(SAM { s, n -> s + " " })
|
||||
JTest.samTest(SAM { x, y -> x + " " })
|
||||
}
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
fun test() {
|
||||
JTest.samTest(SAM { s + " " })
|
||||
JTest.samTest(SAM { s + " " })
|
||||
JTest.samTest(SAM { it + " " })
|
||||
}
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
fun test() {
|
||||
JTest.samTest(SAM { s -> s + " " })
|
||||
JTest.samTest(SAM { (s) -> s + " " })
|
||||
JTest.samTest(SAM { it + " " })
|
||||
}
|
||||
Reference in New Issue
Block a user