FIR IDE: Move RemoveExclExclCallFix to idea-frontend-independent.
This commit is contained in:
committed by
Ilya Kirillov
parent
4fffed4165
commit
34609b264d
+52
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.quickfix
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
|
import com.intellij.codeInsight.intention.HighPriorityAction
|
||||||
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||||
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
import org.jetbrains.kotlin.psi.KtPostfixExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
|
|
||||||
|
abstract class ExclExclCallFix(psiElement: PsiElement) : KotlinPsiOnlyQuickFixAction<PsiElement>(psiElement) {
|
||||||
|
override fun getFamilyName(): String = text
|
||||||
|
|
||||||
|
override fun startInWriteAction(): Boolean = true
|
||||||
|
}
|
||||||
|
|
||||||
|
class RemoveExclExclCallFix(psiElement: PsiElement) : ExclExclCallFix(psiElement), CleanupFix, HighPriorityAction {
|
||||||
|
override fun getText(): String = KotlinBundle.message("fix.remove.non.null.assertion")
|
||||||
|
|
||||||
|
override fun isAvailable(project: Project, editor: Editor?, file: KtFile): Boolean =
|
||||||
|
getExclExclPostfixExpression() != null
|
||||||
|
|
||||||
|
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||||
|
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return
|
||||||
|
|
||||||
|
val postfixExpression = getExclExclPostfixExpression() ?: return
|
||||||
|
val expression = KtPsiFactory(project).createExpression(postfixExpression.baseExpression!!.text)
|
||||||
|
postfixExpression.replace(expression)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getExclExclPostfixExpression(): KtPostfixExpression? {
|
||||||
|
val operationParent = element?.parent
|
||||||
|
if (operationParent is KtPostfixExpression && operationParent.baseExpression != null) {
|
||||||
|
return operationParent
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object : QuickFixesPsiBasedFactory<PsiElement>(PsiElement::class, PsiElementSuitabilityCheckers.ALWAYS_SUITABLE) {
|
||||||
|
override fun doCreateQuickFix(psiElement: PsiElement): List<IntentionAction> {
|
||||||
|
return listOfNotNull(RemoveExclExclCallFix(psiElement))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-50
@@ -1,23 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix
|
package org.jetbrains.kotlin.idea.quickfix
|
||||||
|
|
||||||
import com.intellij.codeInsight.FileModificationService
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInsight.intention.HighPriorityAction
|
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import com.intellij.codeInsight.intention.LowPriorityAction
|
import com.intellij.codeInsight.intention.LowPriorityAction
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
@@ -50,42 +38,8 @@ import org.jetbrains.kotlin.util.OperatorNameConventions
|
|||||||
import org.jetbrains.kotlin.util.isValidOperator
|
import org.jetbrains.kotlin.util.isValidOperator
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
|
class AddExclExclCallFix(psiElement: PsiElement, val checkImplicitReceivers: Boolean = true) : ExclExclCallFix(psiElement),
|
||||||
abstract class ExclExclCallFix(psiElement: PsiElement) : KotlinQuickFixAction<PsiElement>(psiElement) {
|
LowPriorityAction {
|
||||||
override fun getFamilyName(): String = text
|
|
||||||
|
|
||||||
override fun startInWriteAction(): Boolean = true
|
|
||||||
}
|
|
||||||
|
|
||||||
class RemoveExclExclCallFix(psiElement: PsiElement) : ExclExclCallFix(psiElement), CleanupFix, HighPriorityAction {
|
|
||||||
override fun getText(): String = KotlinBundle.message("fix.remove.non.null.assertion")
|
|
||||||
|
|
||||||
override fun isAvailable(project: Project, editor: Editor?, file: KtFile): Boolean =
|
|
||||||
getExclExclPostfixExpression() != null
|
|
||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
|
||||||
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return
|
|
||||||
|
|
||||||
val postfixExpression = getExclExclPostfixExpression() ?: return
|
|
||||||
val expression = KtPsiFactory(project).createExpression(postfixExpression.baseExpression!!.text)
|
|
||||||
postfixExpression.replace(expression)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getExclExclPostfixExpression(): KtPostfixExpression? {
|
|
||||||
val operationParent = element?.parent
|
|
||||||
if (operationParent is KtPostfixExpression && operationParent.baseExpression != null) {
|
|
||||||
return operationParent
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object : KotlinSingleIntentionActionFactory() {
|
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction = RemoveExclExclCallFix(diagnostic.psiElement)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class AddExclExclCallFix(psiElement: PsiElement, val checkImplicitReceivers: Boolean) : ExclExclCallFix(psiElement), LowPriorityAction {
|
|
||||||
constructor(psiElement: PsiElement) : this(psiElement, true)
|
|
||||||
|
|
||||||
override fun getText() = KotlinBundle.message("fix.introduce.non.null.assertion")
|
override fun getText() = KotlinBundle.message("fix.introduce.non.null.assertion")
|
||||||
|
|
||||||
Reference in New Issue
Block a user