Get rid of local version of RemoveModifierFix
This commit is contained in:
+3
-1
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.core.implicitModality
|
||||
import org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtVisitorVoid
|
||||
@@ -47,7 +48,8 @@ class RedundantModalityModifierInspection : AbstractKotlinInspection(), CleanupL
|
||||
holder.registerProblem(modalityModifier,
|
||||
"Redundant modality modifier",
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
||||
RemoveModifierFix("Remove redundant modality modifier"))
|
||||
IntentionWrapper(RemoveModifierFix(declaration, implicitModality, isRedundant = true),
|
||||
declaration.containingFile))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.inspections
|
||||
import com.intellij.codeInspection.*
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
import org.jetbrains.kotlin.idea.core.implicitVisibility
|
||||
import org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtVisitorVoid
|
||||
import org.jetbrains.kotlin.psi.psiUtil.visibilityModifier
|
||||
@@ -28,11 +29,13 @@ class RedundantVisibilityModifierInspection : AbstractKotlinInspection(), Cleanu
|
||||
return object : KtVisitorVoid() {
|
||||
override fun visitDeclaration(declaration: KtDeclaration) {
|
||||
val visibilityModifier = declaration.visibilityModifier() ?: return
|
||||
if (visibilityModifier.node.elementType == declaration.implicitVisibility()) {
|
||||
val implicitVisibility = declaration.implicitVisibility()
|
||||
if (visibilityModifier.node.elementType == implicitVisibility) {
|
||||
holder.registerProblem(visibilityModifier,
|
||||
"Redundant visibility modifier",
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
||||
RemoveModifierFix("Remove redundant visibility modifier"))
|
||||
IntentionWrapper(RemoveModifierFix(declaration, implicitVisibility, isRedundant = true),
|
||||
declaration.containingFile))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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.inspections
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService
|
||||
import com.intellij.codeInspection.LocalQuickFix
|
||||
import com.intellij.codeInspection.ProblemDescriptor
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.psi.KtModifierListOwner
|
||||
import org.jetbrains.kotlin.psi.addRemoveModifier.removeModifier
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
|
||||
class RemoveModifierFix(val text: String) : LocalQuickFix {
|
||||
override fun getName(): String = text
|
||||
|
||||
override fun getFamilyName(): String = text
|
||||
|
||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||
val modifierKeyword = descriptor.psiElement.node.elementType as KtModifierKeywordToken
|
||||
val modifierListOwner = descriptor.psiElement.getParentOfType<KtModifierListOwner>(true)
|
||||
?: throw IllegalStateException("Can't find modifier list owner for modifier")
|
||||
if (!FileModificationService.getInstance().preparePsiElementForWrite(modifierListOwner)) return
|
||||
removeModifier(modifierListOwner, modifierKeyword)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Remove redundant modality modifier" "true"
|
||||
// "Remove redundant 'abstract' modifier" "true"
|
||||
interface A {
|
||||
<caret>abstract fun foo()
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Remove redundant modality modifier" "true"
|
||||
// "Remove redundant 'abstract' modifier" "true"
|
||||
interface A {
|
||||
<caret>fun foo()
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Remove redundant modality modifier" "true"
|
||||
// "Remove redundant 'final' modifier" "true"
|
||||
open class C {
|
||||
<caret>final fun foo(){}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Remove redundant modality modifier" "true"
|
||||
// "Remove redundant 'final' modifier" "true"
|
||||
open class C {
|
||||
fun foo(){}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
// "Remove redundant visibility modifier" "true"
|
||||
// "Remove redundant 'public' modifier" "true"
|
||||
<caret>public class C {
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
// "Remove redundant visibility modifier" "true"
|
||||
// "Remove redundant 'public' modifier" "true"
|
||||
class C {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user