New J2K: properly remove redundant modifiers in post-processing as #KT-30804 is fixed

This commit is contained in:
Ilya Kirillov
2019-06-10 16:44:32 +03:00
parent 2aa20d003d
commit 8375a12733
2 changed files with 2 additions and 11 deletions
@@ -352,7 +352,7 @@ class RemoveRedundantModalityModifierProcessing : ApplicabilityBasedInspectionLi
}
override fun apply(element: KtDeclaration) {
element.removeModifierSmart(element.modalityModifierType()!!)
element.removeModifier(element.modalityModifierType()!!)
}
}
@@ -371,7 +371,7 @@ class RemoveRedundantVisibilityModifierProcessing : ApplicabilityBasedInspection
}
override fun apply(element: KtDeclaration) {
element.removeModifierSmart(element.visibilityModifierType()!!)
element.removeModifier(element.visibilityModifierType()!!)
}
}
@@ -75,14 +75,5 @@ fun KtElement.hasUsagesOutsideOf(inElement: KtElement, outsideElements: List<KtE
outsideElements.none { it.isAncestor(reference.element) }
}
//hack until KT-30804 is fixed
fun KtModifierListOwner.removeModifierSmart(modifierToken: KtModifierKeywordToken) {
val newElement = copy() as KtModifierListOwner
newElement.removeModifier(modifierToken)
replace(newElement)
containingFile.commitAndUnblockDocument()
}
inline fun <reified T : PsiElement> List<PsiElement>.descendantsOfType(): List<T> =
flatMap { it.collectDescendantsOfType() }