FIR IDE: Enable RemoveUselessIsCheckFix and
RemoveUselessIsCheckFixForWhen.
This commit is contained in:
committed by
teamcityserver
parent
639b7537da
commit
af35892007
@@ -107,6 +107,7 @@ class MainKtQuickFixRegistrar : KtQuickFixRegistrar() {
|
||||
registerPsiQuickFixes(KtFirDiagnostic.UselessElvis::class, RemoveUselessElvisFix)
|
||||
registerPsiQuickFixes(KtFirDiagnostic.UselessElvisRightIsNull::class, RemoveUselessElvisFix)
|
||||
registerPsiQuickFixes(KtFirDiagnostic.UselessCast::class, RemoveUselessCastFix)
|
||||
registerPsiQuickFixes(KtFirDiagnostic.UselessIsCheck::class, RemoveUselessIsCheckFix, RemoveUselessIsCheckFixForWhen)
|
||||
registerApplicator(ReplaceCallFixFactories.unsafeCallFactory)
|
||||
registerApplicator(AddExclExclCallFixFactories.unsafeCallFactory)
|
||||
registerApplicator(AddExclExclCallFixFactories.unsafeInfixCallFactory)
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.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.KtIsExpression
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
|
||||
class RemoveUselessIsCheckFix(element: KtIsExpression) : KotlinPsiOnlyQuickFixAction<KtIsExpression>(element) {
|
||||
override fun getFamilyName() = KotlinBundle.message("remove.useless.is.check")
|
||||
|
||||
override fun getText(): String = familyName
|
||||
|
||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||
element?.run {
|
||||
val expressionsText = this.isNegated.not().toString()
|
||||
val newExpression = KtPsiFactory(project).createExpression(expressionsText)
|
||||
replace(newExpression)
|
||||
}
|
||||
}
|
||||
|
||||
companion object : QuickFixesPsiBasedFactory<PsiElement>(PsiElement::class, PsiElementSuitabilityCheckers.ALWAYS_SUITABLE) {
|
||||
override fun doCreateQuickFix(psiElement: PsiElement): List<IntentionAction> {
|
||||
val expression = psiElement.getNonStrictParentOfType<KtIsExpression>() ?: return emptyList()
|
||||
return listOf(RemoveUselessIsCheckFix(expression))
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-19
@@ -1,29 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* 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.
|
||||
* 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.intention.IntentionAction
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
|
||||
class RemoveUselessIsCheckFixForWhen(element: KtWhenConditionIsPattern) : KotlinQuickFixAction<KtWhenConditionIsPattern>(element) {
|
||||
class RemoveUselessIsCheckFixForWhen(element: KtWhenConditionIsPattern) : KotlinPsiOnlyQuickFixAction<KtWhenConditionIsPattern>(element) {
|
||||
override fun getFamilyName() = KotlinBundle.message("remove.useless.is.check")
|
||||
|
||||
override fun getText(): String = familyName
|
||||
@@ -43,10 +33,10 @@ class RemoveUselessIsCheckFixForWhen(element: KtWhenConditionIsPattern) : Kotlin
|
||||
}
|
||||
}
|
||||
|
||||
companion object : KotlinSingleIntentionActionFactory() {
|
||||
override fun createAction(diagnostic: Diagnostic): KotlinQuickFixAction<KtWhenConditionIsPattern>? {
|
||||
val expression = diagnostic.psiElement.getNonStrictParentOfType<KtWhenConditionIsPattern>() ?: return null
|
||||
return RemoveUselessIsCheckFixForWhen(expression)
|
||||
companion object : QuickFixesPsiBasedFactory<PsiElement>(PsiElement::class, PsiElementSuitabilityCheckers.ALWAYS_SUITABLE) {
|
||||
override fun doCreateQuickFix(psiElement: PsiElement): List<IntentionAction> {
|
||||
val expression = psiElement.getNonStrictParentOfType<KtWhenConditionIsPattern>() ?: return emptyList()
|
||||
return listOf(RemoveUselessIsCheckFixForWhen(expression))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* 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
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtIsExpression
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
|
||||
class RemoveUselessIsCheckFix(element: KtIsExpression) : KotlinQuickFixAction<KtIsExpression>(element) {
|
||||
override fun getFamilyName() = KotlinBundle.message("remove.useless.is.check")
|
||||
|
||||
override fun getText(): String = familyName
|
||||
|
||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||
element?.run {
|
||||
val expressionsText = this.isNegated.not().toString()
|
||||
val newExpression = KtPsiFactory(project).createExpression(expressionsText)
|
||||
replace(newExpression)
|
||||
}
|
||||
}
|
||||
|
||||
companion object : KotlinSingleIntentionActionFactory() {
|
||||
override fun createAction(diagnostic: Diagnostic): KotlinQuickFixAction<KtIsExpression>? {
|
||||
val expression = diagnostic.psiElement.getNonStrictParentOfType<KtIsExpression>() ?: return null
|
||||
return RemoveUselessIsCheckFix(expression)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,4 @@ fun foo(a: String) {
|
||||
if (<caret>1 is Int) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
@@ -3,6 +3,4 @@ fun foo(a: String) {
|
||||
if (<caret>true) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
@@ -8,6 +8,4 @@ fun foo(bar: Base):Int {
|
||||
<caret>is Base -> 42
|
||||
else -> 1
|
||||
}
|
||||
}
|
||||
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
@@ -7,6 +7,4 @@ fun foo(bar: Base):Int {
|
||||
is Derived -> 0
|
||||
else -> 42
|
||||
}
|
||||
}
|
||||
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
+1
-2
@@ -9,5 +9,4 @@ fun foo(bar: Base):Int {
|
||||
bar <caret>is Base -> 42
|
||||
else -> 1
|
||||
}
|
||||
}
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
+1
-2
@@ -9,5 +9,4 @@ fun foo(bar: Base):Int {
|
||||
true -> 42
|
||||
else -> 1
|
||||
}
|
||||
}
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
+1
-2
@@ -9,5 +9,4 @@ fun foo(bar: Base):Int {
|
||||
bar <caret>!is Base -> 42
|
||||
else -> 1
|
||||
}
|
||||
}
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
+1
-2
@@ -9,5 +9,4 @@ fun foo(bar: Base):Int {
|
||||
false -> 42
|
||||
else -> 1
|
||||
}
|
||||
}
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
@@ -8,6 +8,4 @@ fun foo(bar: Base):Int {
|
||||
<caret>!is Base -> 42
|
||||
else -> 1
|
||||
}
|
||||
}
|
||||
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
+1
-3
@@ -7,6 +7,4 @@ fun foo(bar: Base):Int {
|
||||
is Derived -> 0
|
||||
else -> 1
|
||||
}
|
||||
}
|
||||
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
@@ -3,6 +3,4 @@ fun foo(a: String) {
|
||||
if (<caret>1 !is Int) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
@@ -3,6 +3,4 @@ fun foo(a: String) {
|
||||
if (<caret>false) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
Reference in New Issue
Block a user