Use property access syntax: don't report when setter argument is lambda
#KT-30627 Fixed
This commit is contained in:
committed by
Dmitry Gridin
parent
a3f8987255
commit
1c32941949
@@ -182,6 +182,13 @@ class UsePropertyAccessSyntaxIntention :
|
|||||||
|
|
||||||
val isSetUsage = callExpression.valueArguments.size == 1
|
val isSetUsage = callExpression.valueArguments.size == 1
|
||||||
|
|
||||||
|
val valueArgumentExpression = callExpression.valueArguments.firstOrNull()?.getArgumentExpression()?.takeUnless {
|
||||||
|
it is KtLambdaExpression || it is KtNamedFunction || it is KtCallableReferenceExpression
|
||||||
|
}
|
||||||
|
if (isSetUsage && valueArgumentExpression == null) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
if (isSetUsage && qualifiedExpression.isUsedAsExpression(bindingContext)) {
|
if (isSetUsage && qualifiedExpression.isUsedAsExpression(bindingContext)) {
|
||||||
// call to the setter used as expression can be converted in the only case when it's used as body expression for some declaration and its type is Unit
|
// call to the setter used as expression can be converted in the only case when it's used as body expression for some declaration and its type is Unit
|
||||||
val parent = qualifiedExpression.parent
|
val parent = qualifiedExpression.parent
|
||||||
|
|||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
public class J {
|
||||||
|
public Runnable getR() { return null; }
|
||||||
|
public void setR(Runnable r) {}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
// WITH_RUNTIME
|
||||||
|
fun test() {
|
||||||
|
J().<caret>setR(fun() {
|
||||||
|
println("Hello, world!")
|
||||||
|
})
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
public class J {
|
||||||
|
public Runnable getR() { return null; }
|
||||||
|
public void setR(Runnable r) {}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
// WITH_RUNTIME
|
||||||
|
fun test() {
|
||||||
|
J().<caret>setR(::test)
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
public class J {
|
||||||
|
public Runnable getR() { return null; }
|
||||||
|
public void setR(Runnable r) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
// WITH_RUNTIME
|
||||||
|
fun test() {
|
||||||
|
J().<caret>setR { println("Hello, world!") }
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
public class J {
|
||||||
|
public Runnable getR() { return null; }
|
||||||
|
public void setR(Runnable r) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
// WITH_RUNTIME
|
||||||
|
fun test() {
|
||||||
|
J().<caret>setR({ println("Hello, world!") })
|
||||||
|
}
|
||||||
@@ -16575,6 +16575,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
runTest("idea/testData/intentions/usePropertyAccessSyntax/set.kt");
|
runTest("idea/testData/intentions/usePropertyAccessSyntax/set.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("setAnonymouseFunctionArgument.kt")
|
||||||
|
public void testSetAnonymouseFunctionArgument() throws Exception {
|
||||||
|
runTest("idea/testData/intentions/usePropertyAccessSyntax/setAnonymouseFunctionArgument.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("setAsExpressionBody.kt")
|
@TestMetadata("setAsExpressionBody.kt")
|
||||||
public void testSetAsExpressionBody() throws Exception {
|
public void testSetAsExpressionBody() throws Exception {
|
||||||
runTest("idea/testData/intentions/usePropertyAccessSyntax/setAsExpressionBody.kt");
|
runTest("idea/testData/intentions/usePropertyAccessSyntax/setAsExpressionBody.kt");
|
||||||
@@ -16590,11 +16595,26 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
runTest("idea/testData/intentions/usePropertyAccessSyntax/setAsExpressionBodyUnqualified.kt");
|
runTest("idea/testData/intentions/usePropertyAccessSyntax/setAsExpressionBodyUnqualified.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("setFunctionReferenceArgument.kt")
|
||||||
|
public void testSetFunctionReferenceArgument() throws Exception {
|
||||||
|
runTest("idea/testData/intentions/usePropertyAccessSyntax/setFunctionReferenceArgument.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("setImplicitReceiver.kt")
|
@TestMetadata("setImplicitReceiver.kt")
|
||||||
public void testSetImplicitReceiver() throws Exception {
|
public void testSetImplicitReceiver() throws Exception {
|
||||||
runTest("idea/testData/intentions/usePropertyAccessSyntax/setImplicitReceiver.kt");
|
runTest("idea/testData/intentions/usePropertyAccessSyntax/setImplicitReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("setLambdaArgument.kt")
|
||||||
|
public void testSetLambdaArgument() throws Exception {
|
||||||
|
runTest("idea/testData/intentions/usePropertyAccessSyntax/setLambdaArgument.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("setLambdaArgument2.kt")
|
||||||
|
public void testSetLambdaArgument2() throws Exception {
|
||||||
|
runTest("idea/testData/intentions/usePropertyAccessSyntax/setLambdaArgument2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("setReservedWord1.kt")
|
@TestMetadata("setReservedWord1.kt")
|
||||||
public void testSetReservedWord1() throws Exception {
|
public void testSetReservedWord1() throws Exception {
|
||||||
runTest("idea/testData/intentions/usePropertyAccessSyntax/setReservedWord1.kt");
|
runTest("idea/testData/intentions/usePropertyAccessSyntax/setReservedWord1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user