mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 09:03:31 +07:00
KTIJ-39340 [kotlin] Select inserted TODO placeholder
(cherry picked from commit 9e27c69b74b677c04b23a4ae33980f9312841d98) IJ-CR-210501 GitOrigin-RevId: 8f735776b36c96a1c0caa1ea972d89c5214a4249
This commit is contained in:
committed by
intellij-monorepo-bot
parent
525614ade1
commit
ca3197d1c3
+10
-2
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtUserType
|
||||
import org.jetbrains.kotlin.psi.KtValueArgument
|
||||
|
||||
internal class AddContextParameterToExistingContextFix(
|
||||
surroundingCall: KtCallExpression,
|
||||
@@ -41,9 +42,16 @@ internal class AddContextParameterToExistingContextFix(
|
||||
} else {
|
||||
val typeReference = psiFactory.createType(parameterTypeFqNameText)
|
||||
val userType = shortenReferences(typeReference) as? KtUserType
|
||||
psiFactory.createExpression("TODO(\"Provide $parameterTypeText\")${userType?.let { " as ${it.text}" } ?: ""}")
|
||||
psiFactory.createArgument(
|
||||
psiFactory.createExpression("TODO(\"Provide $parameterTypeText\")${userType?.let { " as ${it.text}" } ?: ""}")
|
||||
)
|
||||
}
|
||||
argList.addBefore(newElement, rightParen)
|
||||
val insertedElement = argList.addBefore(newElement, rightParen) as? KtValueArgument ?: return
|
||||
if (candidateName == null) {
|
||||
val insertedExpression = insertedElement.getArgumentExpression() ?: return
|
||||
updater.moveCaretTo(insertedExpression)
|
||||
updater.templateBuilder().field(insertedExpression, insertedExpression.text)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getActionPresentation(context: ActionContext, element: KtCallExpression): Presentation =
|
||||
|
||||
+9
-1
@@ -7,6 +7,7 @@ import com.intellij.modcommand.Presentation
|
||||
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferences
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.intentions.KotlinPsiUpdateModCommandAction
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
|
||||
@@ -37,7 +38,14 @@ internal class SurroundCallWithContextFix(
|
||||
}
|
||||
val newExpression = psiFactory.createExpression(expressionText)
|
||||
shortenReferences(newExpression)
|
||||
element.replace(newExpression)
|
||||
val replace = element.replace(newExpression) as? KtCallExpression
|
||||
|
||||
if (candidateName == null && replace != null) {
|
||||
val valueArgument = replace.valueArguments.firstOrNull()
|
||||
val insertedExpression = valueArgument?.getArgumentExpression() ?: return
|
||||
updater.moveCaretTo(insertedExpression)
|
||||
updater.templateBuilder().field(insertedExpression, insertedExpression.text)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getActionPresentation(context: ActionContext, element: KtExpression): Presentation =
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@
|
||||
context(s: String, l: Long) fun bar() {}
|
||||
|
||||
fun foo(i: Int) {
|
||||
context("a", TODO("Provide Long") as Long) {
|
||||
<caret>bar()
|
||||
context("a", TODO("Provide Long") as Long<caret>) {
|
||||
bar()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
context(s: String) fun bar() {}
|
||||
|
||||
fun foo(i: Int) {
|
||||
<caret>context(TODO("Provide String") as String) { bar() }
|
||||
context(TODO("Provide String") as String<caret>) { bar() }
|
||||
}
|
||||
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundCallWithContextFix
|
||||
Reference in New Issue
Block a user