mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Properly retarget unary operators
#KTIJ-30032 Fixed GitOrigin-RevId: 154fa9b03ed09f9e6fdbada465217a9764934be3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
346ef0d213
commit
dd875ac5ac
+5
@@ -692,6 +692,11 @@ public abstract class MoveTestGenerated extends AbstractMoveTest {
|
||||
public void testKotlin_unaffectedQualifiedReferences_UnaffectedQualifiedReferences() throws Exception {
|
||||
runTest("testData/refactoring/moveTopLevel/kotlin/unaffectedQualifiedReferences/unaffectedQualifiedReferences.test");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlin/unaryOperatorReference/unaryOperatorReference.test")
|
||||
public void testKotlin_unaryOperatorReference_UnaryOperatorReference() throws Exception {
|
||||
runTest("testData/refactoring/moveTopLevel/kotlin/unaryOperatorReference/unaryOperatorReference.test");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// FILE: test/UnaryOperator.kt
|
||||
// BIND_TO test.bar.not
|
||||
package test
|
||||
|
||||
import test.foo.not
|
||||
|
||||
fun foo(x: String): Boolean {
|
||||
return <caret>!x
|
||||
}
|
||||
|
||||
// FILE: test/foo/Test.kt
|
||||
package test.foo
|
||||
|
||||
operator fun String.not() = false
|
||||
|
||||
// FILE: test/bar/Test.kt
|
||||
package test.bar
|
||||
|
||||
operator fun String.not() = false
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// FILE: test/UnaryOperator.kt
|
||||
// BIND_TO test.bar.not
|
||||
package test
|
||||
|
||||
import test.bar.not
|
||||
import test.foo.not
|
||||
|
||||
fun foo(x: String): Boolean {
|
||||
return <caret>!x
|
||||
}
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package foo
|
||||
|
||||
fun doFoo(): Boolean { return false }
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package otherBar
|
||||
|
||||
import foo.doFoo
|
||||
|
||||
fun fooBar() {
|
||||
if (!doFoo()) return
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package bar
|
||||
|
||||
import foo.doFoo
|
||||
|
||||
fun foo<caret>Bar() {
|
||||
if (!doFoo()) return
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package foo
|
||||
|
||||
fun doFoo(): Boolean { return false }
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"mainFile": "bar/UseSite.kt",
|
||||
"type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS",
|
||||
"targetPackage": "otherBar",
|
||||
"enabledInK1": "true",
|
||||
"enabledInK2": "true"
|
||||
}
|
||||
+9
-1
@@ -228,7 +228,15 @@ internal class K2ReferenceMutateService : KtReferenceMutateServiceBase() {
|
||||
val isInfix = analyze(targetElement) { (targetElement.getFunctionLikeSymbol() as? KaNamedFunctionSymbol)?.isInfix == true }
|
||||
val isOperator = analyze(targetElement) { (targetElement.getFunctionLikeSymbol() as? KaNamedFunctionSymbol)?.isOperator == true }
|
||||
val replacedExpr = if (isOperator) {
|
||||
replaced(psiFactory.createOperationName(OperatorNameConventions.TOKENS_BY_OPERATOR_NAME[Name.identifier(shortName)] ?: shortName))
|
||||
val identifier = Name.identifier(shortName)
|
||||
val isUnary = OperatorNameConventions.UNARY_OPERATION_NAMES.contains(identifier)
|
||||
val operator = OperatorNameConventions.TOKENS_BY_OPERATOR_NAME[identifier] ?: shortName
|
||||
val newOperator = if (isUnary) {
|
||||
(psiFactory.createExpression("${operator}0") as KtUnaryExpression).operationReference
|
||||
} else {
|
||||
psiFactory.createOperationName(operator)
|
||||
}
|
||||
replaced(newOperator)
|
||||
} else if (isInfix) {
|
||||
replaced(psiFactory.createOperationName(shortName))
|
||||
} else {
|
||||
|
||||
+5
@@ -449,4 +449,9 @@ public class K2MoveTopLevelTestGenerated extends AbstractK2MoveTopLevelTest {
|
||||
public void testKotlin_unaffectedQualifiedReferences_UnaffectedQualifiedReferences() throws Exception {
|
||||
runTest("../../idea/tests/testData/refactoring/moveTopLevel/kotlin/unaffectedQualifiedReferences/unaffectedQualifiedReferences.test");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlin/unaryOperatorReference/unaryOperatorReference.test")
|
||||
public void testKotlin_unaryOperatorReference_UnaryOperatorReference() throws Exception {
|
||||
runTest("../../idea/tests/testData/refactoring/moveTopLevel/kotlin/unaryOperatorReference/unaryOperatorReference.test");
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -816,6 +816,11 @@ public abstract class K2BindToElementTestGenerated extends AbstractK2BindToEleme
|
||||
runTest("../../idea/tests/testData/refactoring/bindToElement/operationReference/UnQualified.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("UnaryOperator.kt")
|
||||
public void testUnaryOperator() throws Exception {
|
||||
runTest("../../idea/tests/testData/refactoring/bindToElement/operationReference/UnaryOperator.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("WithRegularCall.kt")
|
||||
public void testWithRegularCall() throws Exception {
|
||||
runTest("../../idea/tests/testData/refactoring/bindToElement/operationReference/WithRegularCall.kt");
|
||||
|
||||
Reference in New Issue
Block a user