Repository: JetBrains/kotlin
File: idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/AddModifierFix.kt (Kotlin)

Code before:
                    if (modifierListOwner is KtObjectDeclaration) return null
                    if (modifierListOwner is KtClass) {
                        if (modifierListOwner.isInterface() ||
                            modifierListOwner.isSealed() ||
                            modifierListOwner.isEnum() ||
                            modifierListOwner.isData() ||
                            modifierListOwner.isAnnotation()
                        ) return null
                    }
                }
            }
            return AddModifierFix(modifierListOwner, modifier)
        }

        fun createModifierFix(
            element: KtModifierListOwner,
            modifier: KtModifierKeywordToken
        ): T
    }

    companion object : Factory<AddModifierFix> {
        val addAbstractModifier: QuickFixesPsiBasedFactory<PsiElement> = AddModifierFix.createFactory(KtTokens.ABSTRACT_KEYWORD)
        val addAbstractToContainingClass: QuickFixesPsiBasedFactory<PsiElement> =
            AddModifierFix.createFactory(KtTokens.ABSTRACT_KEYWORD, KtClassOrObject::class.java)
        val addOpenToContainingClass: QuickFixesPsiBasedFactory<PsiElement> =
            AddModifierFix.createFactory(KtTokens.OPEN_KEYWORD, KtClassOrObject::class.java)
        val addFinalToProperty: QuickFixesPsiBasedFactory<PsiElement> =
            AddModifierFix.createFactory(KtTokens.FINAL_KEYWORD, KtProperty::class.java)
        val addInnerModifier = createFactory(KtTokens.INNER_KEYWORD)
        private val modalityModifiers: Set<KtModifierKeywordToken> =
            setOf(KtTokens.ABSTRACT_KEYWORD, KtTokens.OPEN_KEYWORD, KtTokens.FINAL_KEYWORD)

        override fun createModifierFix(element: KtModifierListOwner, modifier: KtModifierKeywordToken): AddModifierFix =
            AddModifierFix(element, modifier)

    }
}


Review comment (refactor):
Nit: we should probably unify on one style here. Either put in types on the other lines or simplify the other lines as well (I prefer the latter)?

Code after:
                    if (modifierListOwner is KtObjectDeclaration) return null
                    if (modifierListOwner is KtClass) {
                        if (modifierListOwner.isInterface() ||
                            modifierListOwner.isSealed() ||
                            modifierListOwner.isEnum() ||
                            modifierListOwner.isData() ||
                            modifierListOwner.isAnnotation()
                        ) return null
                    }
                }
            }
            return AddModifierFix(modifierListOwner, modifier)
        }

        fun createModifierFix(
            element: KtModifierListOwner,
            modifier: KtModifierKeywordToken
        ): T
    }

    companion object : Factory<AddModifierFix> {
        val addAbstractModifier = AddModifierFix.createFactory(KtTokens.ABSTRACT_KEYWORD)
        val addAbstractToContainingClass = AddModifierFix.createFactory(KtTokens.ABSTRACT_KEYWORD, KtClassOrObject::class.java)
        val addOpenToContainingClass = AddModifierFix.createFactory(KtTokens.OPEN_KEYWORD, KtClassOrObject::class.java)
        val addFinalToProperty = AddModifierFix.createFactory(KtTokens.FINAL_KEYWORD, KtProperty::class.java)
        val addInnerModifier = createFactory(KtTokens.INNER_KEYWORD)

        private val modalityModifiers: Set<KtModifierKeywordToken> =
            setOf(KtTokens.ABSTRACT_KEYWORD, KtTokens.OPEN_KEYWORD, KtTokens.FINAL_KEYWORD)

        override fun createModifierFix(element: KtModifierListOwner, modifier: KtModifierKeywordToken): AddModifierFix =
            AddModifierFix(element, modifier)

    }
}