New J2K: do not show inline dialog during J2K
#KT-35169 fixed
This commit is contained in:
+6
-5
@@ -25,8 +25,9 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
|||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import javax.swing.JComponent
|
import javax.swing.JComponent
|
||||||
|
|
||||||
class IfThenToElvisInspection(
|
class IfThenToElvisInspection @JvmOverloads constructor(
|
||||||
@JvmField var highlightStatement: Boolean = false
|
@JvmField var highlightStatement: Boolean = false,
|
||||||
|
private val inlineWithPrompt: Boolean = true
|
||||||
) : AbstractApplicabilityBasedInspection<KtIfExpression>(KtIfExpression::class.java) {
|
) : AbstractApplicabilityBasedInspection<KtIfExpression>(KtIfExpression::class.java) {
|
||||||
override fun inspectionText(element: KtIfExpression): String = KotlinBundle.message("if.then.foldable.to")
|
override fun inspectionText(element: KtIfExpression): String = KotlinBundle.message("if.then.foldable.to")
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ class IfThenToElvisInspection(
|
|||||||
ProblemHighlightType.INFORMATION
|
ProblemHighlightType.INFORMATION
|
||||||
|
|
||||||
override fun applyTo(element: KtIfExpression, project: Project, editor: Editor?) {
|
override fun applyTo(element: KtIfExpression, project: Project, editor: Editor?) {
|
||||||
convert(element, editor)
|
convert(element, editor, inlineWithPrompt)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun inspectionHighlightRangeInElement(element: KtIfExpression) = element.fromIfKeywordToRightParenthesisTextRangeInThis()
|
override fun inspectionHighlightRangeInElement(element: KtIfExpression) = element.fromIfKeywordToRightParenthesisTextRangeInThis()
|
||||||
@@ -53,7 +54,7 @@ class IfThenToElvisInspection(
|
|||||||
companion object {
|
companion object {
|
||||||
val INTENTION_TEXT get() = KotlinBundle.message("replace.if.expression.with.elvis.expression")
|
val INTENTION_TEXT get() = KotlinBundle.message("replace.if.expression.with.elvis.expression")
|
||||||
|
|
||||||
fun convert(element: KtIfExpression, editor: Editor?) {
|
fun convert(element: KtIfExpression, editor: Editor?, inlineWithPrompt: Boolean) {
|
||||||
val ifThenToSelectData = element.buildSelectTransformationData() ?: return
|
val ifThenToSelectData = element.buildSelectTransformationData() ?: return
|
||||||
|
|
||||||
val factory = KtPsiFactory(element)
|
val factory = KtPsiFactory(element)
|
||||||
@@ -79,7 +80,7 @@ class IfThenToElvisInspection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (editor != null) {
|
if (editor != null) {
|
||||||
elvis.inlineLeftSideIfApplicableWithPrompt(editor)
|
elvis.inlineLeftSideIfApplicable(editor, inlineWithPrompt)
|
||||||
with(IfThenToSafeAccessInspection) {
|
with(IfThenToSafeAccessInspection) {
|
||||||
(elvis.left as? KtSafeQualifiedExpression)?.renameLetParameter(editor)
|
(elvis.left as? KtSafeQualifiedExpression)?.renameLetParameter(editor)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -24,7 +24,8 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
|||||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
|
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
||||||
|
|
||||||
class IfThenToSafeAccessInspection : AbstractApplicabilityBasedInspection<KtIfExpression>(KtIfExpression::class.java) {
|
class IfThenToSafeAccessInspection @JvmOverloads constructor(private val inlineWithPrompt: Boolean = true) :
|
||||||
|
AbstractApplicabilityBasedInspection<KtIfExpression>(KtIfExpression::class.java) {
|
||||||
|
|
||||||
override fun isApplicable(element: KtIfExpression): Boolean = isApplicableTo(element, expressionShouldBeStable = true)
|
override fun isApplicable(element: KtIfExpression): Boolean = isApplicableTo(element, expressionShouldBeStable = true)
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ class IfThenToSafeAccessInspection : AbstractApplicabilityBasedInspection<KtIfEx
|
|||||||
override val startFixInWriteAction = false
|
override val startFixInWriteAction = false
|
||||||
|
|
||||||
override fun applyTo(element: KtIfExpression, project: Project, editor: Editor?) {
|
override fun applyTo(element: KtIfExpression, project: Project, editor: Editor?) {
|
||||||
convert(element, editor)
|
convert(element, editor, inlineWithPrompt)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -59,7 +60,7 @@ class IfThenToSafeAccessInspection : AbstractApplicabilityBasedInspection<KtIfEx
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun convert(ifExpression: KtIfExpression, editor: Editor?) {
|
fun convert(ifExpression: KtIfExpression, editor: Editor?, inlineWithPrompt: Boolean) {
|
||||||
val ifThenToSelectData = ifExpression.buildSelectTransformationData() ?: return
|
val ifThenToSelectData = ifExpression.buildSelectTransformationData() ?: return
|
||||||
|
|
||||||
val factory = KtPsiFactory(ifExpression)
|
val factory = KtPsiFactory(ifExpression)
|
||||||
@@ -70,7 +71,7 @@ class IfThenToSafeAccessInspection : AbstractApplicabilityBasedInspection<KtIfEx
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (editor != null && resultExpr is KtSafeQualifiedExpression) {
|
if (editor != null && resultExpr is KtSafeQualifiedExpression) {
|
||||||
resultExpr.inlineReceiverIfApplicableWithPrompt(editor)
|
resultExpr.inlineReceiverIfApplicable(editor, inlineWithPrompt)
|
||||||
resultExpr.renameLetParameter(editor)
|
resultExpr.renameLetParameter(editor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-11
@@ -7,10 +7,8 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations
|
|||||||
|
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.application.TransactionGuard
|
import com.intellij.openapi.application.TransactionGuard
|
||||||
import com.intellij.openapi.command.CommandProcessor
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||||
import com.intellij.openapi.project.Project
|
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.search.LocalSearchScope
|
import com.intellij.psi.search.LocalSearchScope
|
||||||
import com.intellij.psi.search.searches.ReferencesSearch
|
import com.intellij.psi.search.searches.ReferencesSearch
|
||||||
@@ -142,7 +140,7 @@ fun KtIfExpression.introduceValueForCondition(occurrenceInThenClause: KtExpressi
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KtNameReferenceExpression.inlineIfDeclaredLocallyAndOnlyUsedOnceWithPrompt(editor: Editor?) {
|
fun KtNameReferenceExpression.inlineIfDeclaredLocallyAndOnlyUsedOnce(editor: Editor?, withPrompt: Boolean) {
|
||||||
val declaration = this.mainReference.resolve() as? KtProperty ?: return
|
val declaration = this.mainReference.resolve() as? KtProperty ?: return
|
||||||
|
|
||||||
val enclosingElement = KtPsiUtil.getEnclosingElementForLocalDeclaration(declaration)
|
val enclosingElement = KtPsiUtil.getEnclosingElementForLocalDeclaration(declaration)
|
||||||
@@ -155,7 +153,7 @@ fun KtNameReferenceExpression.inlineIfDeclaredLocallyAndOnlyUsedOnceWithPrompt(e
|
|||||||
if (references.size == 1) {
|
if (references.size == 1) {
|
||||||
if (!ApplicationManager.getApplication().isUnitTestMode) {
|
if (!ApplicationManager.getApplication().isUnitTestMode) {
|
||||||
ApplicationManager.getApplication().invokeLater {
|
ApplicationManager.getApplication().invokeLater {
|
||||||
val handler = KotlinInlineValHandler()
|
val handler = KotlinInlineValHandler(withPrompt)
|
||||||
if (declaration.isValid && handler.canInlineElement(declaration)) {
|
if (declaration.isValid && handler.canInlineElement(declaration)) {
|
||||||
TransactionGuard.getInstance().submitTransactionAndWait {
|
TransactionGuard.getInstance().submitTransactionAndWait {
|
||||||
handler.inlineElement(this.project, editor, declaration)
|
handler.inlineElement(this.project, editor, declaration)
|
||||||
@@ -163,21 +161,21 @@ fun KtNameReferenceExpression.inlineIfDeclaredLocallyAndOnlyUsedOnceWithPrompt(e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
KotlinInlineValHandler().inlineElement(this.project, editor, declaration)
|
KotlinInlineValHandler(withPrompt).inlineElement(this.project, editor, declaration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KtSafeQualifiedExpression.inlineReceiverIfApplicableWithPrompt(editor: Editor?) {
|
fun KtSafeQualifiedExpression.inlineReceiverIfApplicable(editor: Editor?, withPrompt: Boolean) {
|
||||||
(this.receiverExpression as? KtNameReferenceExpression)?.inlineIfDeclaredLocallyAndOnlyUsedOnceWithPrompt(editor)
|
(this.receiverExpression as? KtNameReferenceExpression)?.inlineIfDeclaredLocallyAndOnlyUsedOnce(editor, withPrompt)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KtBinaryExpression.inlineLeftSideIfApplicableWithPrompt(editor: Editor?) {
|
fun KtBinaryExpression.inlineLeftSideIfApplicable(editor: Editor?, withPrompt: Boolean) {
|
||||||
(this.left as? KtNameReferenceExpression)?.inlineIfDeclaredLocallyAndOnlyUsedOnceWithPrompt(editor)
|
(this.left as? KtNameReferenceExpression)?.inlineIfDeclaredLocallyAndOnlyUsedOnce(editor, withPrompt)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KtPostfixExpression.inlineBaseExpressionIfApplicableWithPrompt(editor: Editor?) {
|
fun KtPostfixExpression.inlineBaseExpressionIfApplicable(editor: Editor?, withPrompt: Boolean) {
|
||||||
(this.baseExpression as? KtNameReferenceExpression)?.inlineIfDeclaredLocallyAndOnlyUsedOnceWithPrompt(editor)
|
(this.baseExpression as? KtNameReferenceExpression)?.inlineIfDeclaredLocallyAndOnlyUsedOnce(editor, withPrompt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// I.e. stable val/var/receiver
|
// I.e. stable val/var/receiver
|
||||||
|
|||||||
@@ -28,13 +28,13 @@ object SmartCastImpossibleInIfThenFactory : KotlinIntentionActionsFactory() {
|
|||||||
ifExpression,
|
ifExpression,
|
||||||
{ IfThenToSafeAccessInspection.fixTextFor(it) },
|
{ IfThenToSafeAccessInspection.fixTextFor(it) },
|
||||||
{ IfThenToSafeAccessInspection.isApplicableTo(it, expressionShouldBeStable = false) },
|
{ IfThenToSafeAccessInspection.isApplicableTo(it, expressionShouldBeStable = false) },
|
||||||
{ ifExpr, _, editor -> IfThenToSafeAccessInspection.convert(ifExpr, editor) }
|
{ ifExpr, _, editor -> IfThenToSafeAccessInspection.convert(ifExpr, editor, inlineWithPrompt = true) }
|
||||||
),
|
),
|
||||||
createQuickFix(
|
createQuickFix(
|
||||||
ifExpression,
|
ifExpression,
|
||||||
{ IfThenToElvisInspection.INTENTION_TEXT },
|
{ IfThenToElvisInspection.INTENTION_TEXT },
|
||||||
{ IfThenToElvisInspection.isApplicableTo(it, expressionShouldBeStable = false) },
|
{ IfThenToElvisInspection.isApplicableTo(it, expressionShouldBeStable = false) },
|
||||||
{ ifExpr, _, editor -> IfThenToElvisInspection.convert(ifExpr, editor) }
|
{ ifExpr, _, editor -> IfThenToElvisInspection.convert(ifExpr, editor, inlineWithPrompt = true) }
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,8 +223,8 @@ private val inspectionLikePostProcessingGroup =
|
|||||||
it
|
it
|
||||||
) as KtReturnExpression).returnedExpression.isTrivialStatementBody()
|
) as KtReturnExpression).returnedExpression.isTrivialStatementBody()
|
||||||
},
|
},
|
||||||
inspectionBasedProcessing(IfThenToSafeAccessInspection(), writeActionNeeded = false),
|
inspectionBasedProcessing(IfThenToSafeAccessInspection(inlineWithPrompt = false), writeActionNeeded = false),
|
||||||
inspectionBasedProcessing(IfThenToElvisInspection(highlightStatement = true), writeActionNeeded = false),
|
inspectionBasedProcessing(IfThenToElvisInspection(highlightStatement = true, inlineWithPrompt = false), writeActionNeeded = false),
|
||||||
inspectionBasedProcessing(SimplifyNegatedBinaryExpressionInspection()),
|
inspectionBasedProcessing(SimplifyNegatedBinaryExpressionInspection()),
|
||||||
inspectionBasedProcessing(ReplaceGetOrSetInspection()),
|
inspectionBasedProcessing(ReplaceGetOrSetInspection()),
|
||||||
intentionBasedProcessing(ObjectLiteralToLambdaIntention(), writeActionNeeded = true),
|
intentionBasedProcessing(ObjectLiteralToLambdaIntention(), writeActionNeeded = true),
|
||||||
|
|||||||
Reference in New Issue
Block a user