ProtectedInFinalInspection: reformat
This commit is contained in:
committed by
Mikhail Glukhikh
parent
9c18e24de5
commit
b935f52a63
@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.psi.declarationVisitor
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.visibilityModifier
|
||||
|
||||
class ProtectedInFinalInspection : AbstractKotlinInspection() {
|
||||
class ProtectedInFinalInspection : AbstractKotlinInspection() {
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||
return declarationVisitor(fun(declaration) {
|
||||
val visibilityModifier = declaration.visibilityModifier() ?: return
|
||||
@@ -27,12 +27,14 @@ class ProtectedInFinalInspection : AbstractKotlinInspection() {
|
||||
if (modifierType == KtTokens.PROTECTED_KEYWORD) {
|
||||
val parentClass = declaration.getParentOfType<KtClass>(true) ?: return
|
||||
if (!parentClass.isInheritable() && !parentClass.isEnum() &&
|
||||
declaration.implicitVisibility() != KtTokens.PROTECTED_KEYWORD) {
|
||||
holder.registerProblem(visibilityModifier,
|
||||
"'protected' visibility is effectively 'private' in a final class",
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
MakePrivateFix(),
|
||||
MakeOpenFix()
|
||||
declaration.implicitVisibility() != KtTokens.PROTECTED_KEYWORD
|
||||
) {
|
||||
holder.registerProblem(
|
||||
visibilityModifier,
|
||||
"'protected' visibility is effectively 'private' in a final class",
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
MakePrivateFix(),
|
||||
MakeOpenFix()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -47,7 +49,7 @@ class ProtectedInFinalInspection : AbstractKotlinInspection() {
|
||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return
|
||||
val modifierListOwner = descriptor.psiElement.getParentOfType<KtModifierListOwner>(true)
|
||||
?: throw IllegalStateException("Can't find modifier list owner for modifier")
|
||||
?: throw IllegalStateException("Can't find modifier list owner for modifier")
|
||||
addModifier(modifierListOwner, KtTokens.PRIVATE_KEYWORD)
|
||||
}
|
||||
}
|
||||
@@ -60,7 +62,7 @@ class ProtectedInFinalInspection : AbstractKotlinInspection() {
|
||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return
|
||||
val modifierListOwner = descriptor.psiElement.getParentOfType<KtModifierListOwner>(true)
|
||||
?: throw IllegalStateException("Can't find modifier list owner for modifier")
|
||||
?: throw IllegalStateException("Can't find modifier list owner for modifier")
|
||||
val parentClass = modifierListOwner.getParentOfType<KtClass>(true) ?: return
|
||||
addModifier(parentClass, KtTokens.OPEN_KEYWORD)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user