Copy/Move: Fix processing of calls used as callees
#KT-18241 Fixed
This commit is contained in:
+2
-1
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.idea.codeInsight.shorten.addToShorteningWaitSet
|
||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||
import org.jetbrains.kotlin.idea.core.copied
|
||||
import org.jetbrains.kotlin.idea.core.quoteIfNeeded
|
||||
import org.jetbrains.kotlin.idea.core.replaced
|
||||
import org.jetbrains.kotlin.idea.intentions.OperatorToFunctionIntention
|
||||
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
|
||||
import org.jetbrains.kotlin.lexer.KtToken
|
||||
@@ -206,7 +207,7 @@ class KtSimpleNameReference(expression: KtSimpleNameExpression) : KtSimpleRefere
|
||||
val typeText = "$text${elementToReplace.typeArgumentList?.text ?: ""}"
|
||||
elementToReplace.replace(psiFactory.createType(typeText).typeElement!!)
|
||||
}
|
||||
else -> elementToReplace.replace(psiFactory.createExpression(text))
|
||||
else -> KtPsiUtil.safeDeparenthesize(elementToReplace.replaced(psiFactory.createExpression(text)))
|
||||
} as KtElement
|
||||
|
||||
val selector = (newElement as? KtCallableReferenceExpression)?.callableReference
|
||||
|
||||
@@ -562,7 +562,11 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT
|
||||
}
|
||||
|
||||
override fun shortenElement(element: KtDotQualifiedExpression): KtElement {
|
||||
return element.replace(element.selectorExpression!!) as KtElement
|
||||
val parens = element.parent as? KtParenthesizedExpression
|
||||
val requiredParens = parens != null && !KtPsiUtil.areParenthesesUseless(parens)
|
||||
val shortenedElement = element.replace(element.selectorExpression!!) as KtElement
|
||||
if (requiredParens) return shortenedElement.parent.replaced(shortenedElement)
|
||||
return shortenedElement
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package bar
|
||||
|
||||
import foo.parenB
|
||||
import foo.parenBP
|
||||
import foo.parenP
|
||||
import foo.parenPB
|
||||
import foo.parenPP
|
||||
|
||||
fun some2(p1: () -> Unit, p2: (() -> Unit) -> Unit) {
|
||||
parenB { p1() }
|
||||
parenP()
|
||||
parenBP { p1 }()
|
||||
parenPP()()
|
||||
parenPB(p2) {}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
fun parenB(p: () -> Unit) = p()
|
||||
fun parenP() {}
|
||||
fun parenBP(p: () -> () -> Unit): () -> Unit = p()
|
||||
fun parenPP(): () -> Unit = {}
|
||||
fun parenPB(p: (() -> Unit) -> Unit): (() -> Unit) -> Unit = p
|
||||
|
||||
fun some(p1: () -> Unit, p2: (() -> Unit) -> Unit) {
|
||||
parenB { p1() }
|
||||
parenP()
|
||||
parenBP { p1 }()
|
||||
parenPP()()
|
||||
(parenPB(p2)) {}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
fun parenB(p: () -> Unit) = p()
|
||||
fun parenP() {}
|
||||
fun parenBP(p: () -> () -> Unit): () -> Unit = p()
|
||||
fun parenPP(): () -> Unit = {}
|
||||
fun parenPB(p: (() -> Unit) -> Unit): (() -> Unit) -> Unit = p
|
||||
|
||||
fun <caret>some(p1: () -> Unit, p2: (() -> Unit) -> Unit) {
|
||||
parenB { p1() }
|
||||
parenP()
|
||||
parenBP { p1 }()
|
||||
parenPP()()
|
||||
(parenPB(p2)) {}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"mainFile": "foo/test.kt",
|
||||
"targetPackage": "bar",
|
||||
"newName": "some2"
|
||||
}
|
||||
@@ -72,6 +72,12 @@ public class CopyTestGenerated extends AbstractCopyTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("copyFunCallQualificationWithParentheses/copyFunCallQualificationWithParentheses.test")
|
||||
public void testCopyFunCallQualificationWithParentheses_CopyFunCallQualificationWithParentheses() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/copy/copyFunCallQualificationWithParentheses/copyFunCallQualificationWithParentheses.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("copyLocalClass/copyLocalClass.test")
|
||||
public void testCopyLocalClass_CopyLocalClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/copy/copyLocalClass/copyLocalClass.test");
|
||||
|
||||
Reference in New Issue
Block a user