From 894bf000e1ce89ec501b91ce62a8bc5b60508c53 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Tue, 14 Apr 2015 12:31:55 +0300 Subject: [PATCH] JetSelfTargetingInspection - deprecated i18n usage --- .../intentions/JetSelfTargetingIntention.kt | 36 ++++++++++--------- ...implifyNegatedBinaryExpressionIntention.kt | 2 +- .../AttributeCallReplacementIntention.kt | 4 +-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/JetSelfTargetingIntention.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/JetSelfTargetingIntention.kt index 1c655cbe055..3a56325e5cb 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/JetSelfTargetingIntention.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/JetSelfTargetingIntention.kt @@ -24,12 +24,21 @@ import org.jetbrains.kotlin.idea.JetBundle import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypesAndPredicate import com.intellij.codeInsight.intention.IntentionAction -public abstract class JetSelfTargetingIntention(protected val key: String, val elementType: Class) : IntentionAction { - private var myText:String = JetBundle.message(key); - protected fun setText(text: String) { - myText = text +public abstract class JetSelfTargetingIntention( + public val elementType: Class, + private var text: String, + private val familyName: String) +: IntentionAction { + deprecated("Use primary constructor, no need to use i18n") + public constructor(key: String, elementType: Class) : this(elementType, JetBundle.message(key), JetBundle.message(key + ".family")) { } - override fun getText(): String = myText + + protected fun setText(text: String) { + this.text = text + } + + override fun getText() = text + override fun getFamilyName() = familyName public abstract fun isApplicableTo(element: T): Boolean public open fun isApplicableTo(element: T, editor: Editor): Boolean = isApplicableTo(element) @@ -40,19 +49,12 @@ public abstract class JetSelfTargetingIntention(protected val key return file.findElementAt(offset)?.getParentOfTypesAndPredicate(false, elementType) { element -> isApplicableTo(element, editor) } } - public override fun getFamilyName(): String { - return JetBundle.message(key + ".family") - } + override fun isAvailable(project: Project, editor: Editor, file: PsiFile) + = getTarget(editor, file) != null - public override fun isAvailable(project: Project, editor: Editor, file: PsiFile): Boolean { - return getTarget(editor, file) != null - } - - public override fun invoke(project: Project, editor: Editor, file: PsiFile): Unit { - val target = getTarget(editor, file) - assert(target != null, "Intention is not applicable") - - applyTo(target!!, editor) + override fun invoke(project: Project, editor: Editor, file: PsiFile): Unit { + val target = getTarget(editor, file) ?: error("Intention is not applicable") + applyTo(target, editor) } override fun startInWriteAction(): Boolean = true diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SimplifyNegatedBinaryExpressionIntention.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SimplifyNegatedBinaryExpressionIntention.kt index cef3f3b119a..2a0365ca414 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SimplifyNegatedBinaryExpressionIntention.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SimplifyNegatedBinaryExpressionIntention.kt @@ -64,7 +64,7 @@ public class SimplifyNegatedBinaryExpressionIntention : JetSelfTargetingIntentio val operation = (JetPsiUtil.getOperationToken(expression) as? JetSingleValueToken) ?: return false val negOperation = operation.negate() ?: return false - setText(JetBundle.message(key, operation.getValue(), negOperation.getValue())) + setText(JetBundle.message("simplify.negated.binary.expression", operation.getValue(), negOperation.getValue())) return true } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt index 726e2e5c78b..e0d0f82613e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt @@ -97,7 +97,7 @@ public fun JetQualifiedExpression.toCallDescription(): CallDescription? { return CallDescription(this, callExpression, resolvedCall) } -public abstract class AttributeCallReplacementIntention(name: String) : JetSelfTargetingIntention(name, javaClass()) { +public abstract class AttributeCallReplacementIntention(private val name: String) : JetSelfTargetingIntention(name, javaClass()) { protected abstract fun isApplicableToCall(call: CallDescription): Boolean @@ -107,7 +107,7 @@ public abstract class AttributeCallReplacementIntention(name: String) : JetSelfT final override fun isApplicableTo(element: JetDotQualifiedExpression): Boolean { val callDescription = element.toCallDescription() if (callDescription != null && isApplicableToCall(callDescription)) { - setText(JetBundle.message(key, *formatArgumentsFor(callDescription))) + setText(JetBundle.message(name, *formatArgumentsFor(callDescription))) return true } else { return false