KotlinSuppressIntentionAction: cleanup code

This commit is contained in:
Dmitry Gridin
2019-10-10 21:36:47 +07:00
parent 3832924bd7
commit e3d9f05d28
@@ -34,13 +34,17 @@ class KotlinSuppressIntentionAction private constructor(
private val suppressKey: String, private val suppressKey: String,
private val kind: AnnotationHostKind private val kind: AnnotationHostKind
) : SuppressIntentionAction() { ) : SuppressIntentionAction() {
constructor(suppressAt: KtExpression, constructor(
suppressAt: KtExpression,
suppressKey: String, suppressKey: String,
kind: AnnotationHostKind) : this(suppressAt as PsiElement, suppressKey, kind) kind: AnnotationHostKind
) : this(suppressAt as PsiElement, suppressKey, kind)
constructor(suppressAt: KtFile, constructor(
suppressAt: KtFile,
suppressKey: String, suppressKey: String,
kind: AnnotationHostKind) : this(suppressAt as PsiElement, suppressKey, kind) kind: AnnotationHostKind
) : this(suppressAt as PsiElement, suppressKey, kind)
override fun getFamilyName() = KotlinBundle.message("suppress.warnings.family") override fun getFamilyName() = KotlinBundle.message("suppress.warnings.family")
override fun getText() = KotlinBundle.message("suppress.warning.for", suppressKey, kind.kind, kind.name) override fun getText() = KotlinBundle.message("suppress.warning.for", suppressKey, kind.kind, kind.name)
@@ -53,13 +57,15 @@ class KotlinSuppressIntentionAction private constructor(
val id = "\"$suppressKey\"" val id = "\"$suppressKey\""
when (suppressAt) { when (suppressAt) {
is KtModifierListOwner -> is KtModifierListOwner -> suppressAt.addAnnotation(
suppressAt.addAnnotation(KotlinBuiltIns.FQ_NAMES.suppress, KotlinBuiltIns.FQ_NAMES.suppress,
id, id,
whiteSpaceText = if (kind.newLineNeeded) "\n" else " ", whiteSpaceText = if (kind.newLineNeeded) "\n" else " ",
addToExistingAnnotation = { entry -> addToExistingAnnotation = { entry ->
addArgumentToSuppressAnnotation(entry, id) addArgumentToSuppressAnnotation(
true entry,
id
); true
}) })
is KtAnnotatedExpression -> is KtAnnotatedExpression ->
@@ -102,8 +108,7 @@ class KotlinSuppressIntentionAction private constructor(
if (entry != null) { if (entry != null) {
// already annotated with @suppress // already annotated with @suppress
addArgumentToSuppressAnnotation(entry, id) addArgumentToSuppressAnnotation(entry, id)
} } else {
else {
suppressAtExpression(suppressAt, id) suppressAtExpression(suppressAt, id)
} }
} }
@@ -139,7 +144,8 @@ class KotlinSuppressIntentionAction private constructor(
} }
} }
private fun suppressAnnotationText(id: String, withAt: Boolean = true) = "${if (withAt) "@" else ""}${KotlinBuiltIns.FQ_NAMES.suppress.shortName()}($id)" private fun suppressAnnotationText(id: String, withAt: Boolean = true) =
"${if (withAt) "@" else ""}${KotlinBuiltIns.FQ_NAMES.suppress.shortName()}($id)"
private fun findSuppressAnnotation(annotated: KtAnnotated): KtAnnotationEntry? { private fun findSuppressAnnotation(annotated: KtAnnotated): KtAnnotationEntry? {
val context = annotated.analyze() val context = annotated.analyze()