JetSelfTargetingInspection - deprecated i18n usage
This commit is contained in:
+19
-17
@@ -24,12 +24,21 @@ import org.jetbrains.kotlin.idea.JetBundle
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypesAndPredicate
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypesAndPredicate
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
|
|
||||||
public abstract class JetSelfTargetingIntention<T: JetElement>(protected val key: String, val elementType: Class<T>) : IntentionAction {
|
public abstract class JetSelfTargetingIntention<T: JetElement>(
|
||||||
private var myText:String = JetBundle.message(key);
|
public val elementType: Class<T>,
|
||||||
protected fun setText(text: String) {
|
private var text: String,
|
||||||
myText = text
|
private val familyName: String)
|
||||||
|
: IntentionAction {
|
||||||
|
deprecated("Use primary constructor, no need to use i18n")
|
||||||
|
public constructor(key: String, elementType: Class<T>) : 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 abstract fun isApplicableTo(element: T): Boolean
|
||||||
public open fun isApplicableTo(element: T, editor: Editor): Boolean = isApplicableTo(element)
|
public open fun isApplicableTo(element: T, editor: Editor): Boolean = isApplicableTo(element)
|
||||||
@@ -40,19 +49,12 @@ public abstract class JetSelfTargetingIntention<T: JetElement>(protected val key
|
|||||||
return file.findElementAt(offset)?.getParentOfTypesAndPredicate(false, elementType) { element -> isApplicableTo(element, editor) }
|
return file.findElementAt(offset)?.getParentOfTypesAndPredicate(false, elementType) { element -> isApplicableTo(element, editor) }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun getFamilyName(): String {
|
override fun isAvailable(project: Project, editor: Editor, file: PsiFile)
|
||||||
return JetBundle.message(key + ".family")
|
= getTarget(editor, file) != null
|
||||||
}
|
|
||||||
|
|
||||||
public override fun isAvailable(project: Project, editor: Editor, file: PsiFile): Boolean {
|
override fun invoke(project: Project, editor: Editor, file: PsiFile): Unit {
|
||||||
return getTarget(editor, file) != null
|
val target = getTarget(editor, file) ?: error("Intention is not applicable")
|
||||||
}
|
applyTo(target, editor)
|
||||||
|
|
||||||
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 startInWriteAction(): Boolean = true
|
override fun startInWriteAction(): Boolean = true
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ public class SimplifyNegatedBinaryExpressionIntention : JetSelfTargetingIntentio
|
|||||||
val operation = (JetPsiUtil.getOperationToken(expression) as? JetSingleValueToken) ?: return false
|
val operation = (JetPsiUtil.getOperationToken(expression) as? JetSingleValueToken) ?: return false
|
||||||
val negOperation = operation.negate() ?: 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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -97,7 +97,7 @@ public fun JetQualifiedExpression.toCallDescription(): CallDescription? {
|
|||||||
return CallDescription(this, callExpression, resolvedCall)
|
return CallDescription(this, callExpression, resolvedCall)
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class AttributeCallReplacementIntention(name: String) : JetSelfTargetingIntention<JetDotQualifiedExpression>(name, javaClass()) {
|
public abstract class AttributeCallReplacementIntention(private val name: String) : JetSelfTargetingIntention<JetDotQualifiedExpression>(name, javaClass()) {
|
||||||
|
|
||||||
protected abstract fun isApplicableToCall(call: CallDescription): Boolean
|
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 {
|
final override fun isApplicableTo(element: JetDotQualifiedExpression): Boolean {
|
||||||
val callDescription = element.toCallDescription()
|
val callDescription = element.toCallDescription()
|
||||||
if (callDescription != null && isApplicableToCall(callDescription)) {
|
if (callDescription != null && isApplicableToCall(callDescription)) {
|
||||||
setText(JetBundle.message(key, *formatArgumentsFor(callDescription)))
|
setText(JetBundle.message(name, *formatArgumentsFor(callDescription)))
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user