PSI: Add parentheses around non-trivial callee expressions
#KT-8232 Fixed
This commit is contained in:
@@ -535,6 +535,16 @@ public class JetPsiUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parentExpression instanceof JetCallExpression && currentInner == ((JetCallExpression) parentExpression).getCalleeExpression()) {
|
||||||
|
if (innerExpression instanceof JetSimpleNameExpression) return false;
|
||||||
|
if (PsiUtilPackage.getQualifiedExpressionForSelector(parentExpression) != null) return true;
|
||||||
|
return !(innerExpression instanceof JetThisExpression
|
||||||
|
|| innerExpression instanceof JetArrayAccessExpression
|
||||||
|
|| innerExpression instanceof JetConstantExpression
|
||||||
|
|| innerExpression instanceof JetStringTemplateExpression
|
||||||
|
|| innerExpression instanceof JetCallExpression);
|
||||||
|
}
|
||||||
|
|
||||||
IElementType innerOperation = getOperation(innerExpression);
|
IElementType innerOperation = getOperation(innerExpression);
|
||||||
IElementType parentOperation = getOperation(parentExpression);
|
IElementType parentOperation = getOperation(parentExpression);
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.TextRange
|
|||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention
|
||||||
import org.jetbrains.kotlin.idea.intentions.callExpression
|
import org.jetbrains.kotlin.idea.intentions.callExpression
|
||||||
import org.jetbrains.kotlin.idea.intentions.calleeName
|
import org.jetbrains.kotlin.idea.intentions.calleeName
|
||||||
|
import org.jetbrains.kotlin.psi.JetCallExpression
|
||||||
import org.jetbrains.kotlin.psi.JetDotQualifiedExpression
|
import org.jetbrains.kotlin.psi.JetDotQualifiedExpression
|
||||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ public class ReplaceInvokeIntention : JetSelfTargetingRangeIntention<JetDotQuali
|
|||||||
|
|
||||||
override fun applyTo(element: JetDotQualifiedExpression, editor: Editor) {
|
override fun applyTo(element: JetDotQualifiedExpression, editor: Editor) {
|
||||||
val receiver = element.getReceiverExpression()
|
val receiver = element.getReceiverExpression()
|
||||||
val callExpression = element.callExpression!!
|
val callExpression = element.callExpression!!.copy() as JetCallExpression
|
||||||
callExpression.getCalleeExpression()!!.replace(receiver)
|
callExpression.getCalleeExpression()!!.replace(receiver)
|
||||||
element.replace(callExpression)
|
element.replace(callExpression)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun foo(x : String, y : () -> String.() -> Unit) {
|
||||||
|
val <caret>f = y()
|
||||||
|
x.f()
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(x : String, y : () -> String.() -> Unit) {
|
||||||
|
x.(y())()
|
||||||
|
}
|
||||||
@@ -151,6 +151,12 @@ public class InlineTestGenerated extends AbstractInlineTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("Callee.kt")
|
||||||
|
public void testCallee() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/inline/addParenthesis/Callee.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("Colon.kt")
|
@TestMetadata("Colon.kt")
|
||||||
public void testColon() throws Exception {
|
public void testColon() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/inline/addParenthesis/Colon.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/inline/addParenthesis/Colon.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user