i18n: add dynamic text getters for SelfTargetingIntention
#KT-37483
This commit is contained in:
+44
-16
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -12,7 +12,6 @@ import com.intellij.openapi.application.ApplicationManager
|
|||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.PsiDocumentManager
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
@@ -27,19 +26,31 @@ import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
|||||||
@Suppress("EqualsOrHashCode")
|
@Suppress("EqualsOrHashCode")
|
||||||
abstract class SelfTargetingIntention<TElement : PsiElement>(
|
abstract class SelfTargetingIntention<TElement : PsiElement>(
|
||||||
val elementType: Class<TElement>,
|
val elementType: Class<TElement>,
|
||||||
@Nls private var text: String,
|
@Nls private var textGetter: () -> String,
|
||||||
@Nls private val familyName: String = text
|
@Nls private val familyNameGetter: () -> String = textGetter,
|
||||||
) : IntentionAction {
|
) : IntentionAction {
|
||||||
|
|
||||||
@Nls
|
@Deprecated("Replace with primary constructor", ReplaceWith("SelfTargetingIntention(elementType, { text }, { familyName })"))
|
||||||
protected val defaultText: String = text
|
constructor(
|
||||||
|
elementType: Class<TElement>,
|
||||||
|
@Nls text: String,
|
||||||
|
@Nls familyName: String = text,
|
||||||
|
) : this(elementType, { text }, { familyName })
|
||||||
|
|
||||||
|
protected val defaultText: String get() = defaultTextGetter()
|
||||||
|
private val defaultTextGetter: () -> String = textGetter
|
||||||
|
|
||||||
|
@Deprecated("Replace with `setTextGetter`", ReplaceWith("setTextGetter { text }"))
|
||||||
protected fun setText(@Nls text: String) {
|
protected fun setText(@Nls text: String) {
|
||||||
this.text = text
|
this.textGetter = { text }
|
||||||
}
|
}
|
||||||
|
|
||||||
final override fun getText() = text
|
protected fun setTextGetter(@Nls textGetter: () -> String) {
|
||||||
final override fun getFamilyName() = familyName
|
this.textGetter = textGetter
|
||||||
|
}
|
||||||
|
|
||||||
|
final override fun getText() = textGetter()
|
||||||
|
final override fun getFamilyName() = familyNameGetter()
|
||||||
|
|
||||||
abstract fun isApplicableTo(element: TElement, caretOffset: Int): Boolean
|
abstract fun isApplicableTo(element: TElement, caretOffset: Int): Boolean
|
||||||
|
|
||||||
@@ -101,7 +112,7 @@ abstract class SelfTargetingIntention<TElement : PsiElement>(
|
|||||||
|
|
||||||
override fun startInWriteAction() = true
|
override fun startInWriteAction() = true
|
||||||
|
|
||||||
override fun toString(): String = getText()
|
override fun toString(): String = text
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
// Nasty code because IntentionWrapper itself does not override equals
|
// Nasty code because IntentionWrapper itself does not override equals
|
||||||
@@ -115,9 +126,16 @@ abstract class SelfTargetingIntention<TElement : PsiElement>(
|
|||||||
|
|
||||||
abstract class SelfTargetingRangeIntention<TElement : PsiElement>(
|
abstract class SelfTargetingRangeIntention<TElement : PsiElement>(
|
||||||
elementType: Class<TElement>,
|
elementType: Class<TElement>,
|
||||||
@Nls text: String,
|
@Nls textGetter: () -> String,
|
||||||
@Nls familyName: String = text
|
@Nls familyNameGetter: () -> String = textGetter,
|
||||||
) : SelfTargetingIntention<TElement>(elementType, text, familyName) {
|
) : SelfTargetingIntention<TElement>(elementType, textGetter, familyNameGetter) {
|
||||||
|
|
||||||
|
@Deprecated("Replace with primary constructor", ReplaceWith("SelfTargetingRangeIntention(elementType, { text }, { familyName })"))
|
||||||
|
constructor(
|
||||||
|
elementType: Class<TElement>,
|
||||||
|
@Nls text: String,
|
||||||
|
@Nls familyName: String = text,
|
||||||
|
) : this(elementType, { text }, { familyName })
|
||||||
|
|
||||||
abstract fun applicabilityRange(element: TElement): TextRange?
|
abstract fun applicabilityRange(element: TElement): TextRange?
|
||||||
|
|
||||||
@@ -129,9 +147,19 @@ abstract class SelfTargetingRangeIntention<TElement : PsiElement>(
|
|||||||
|
|
||||||
abstract class SelfTargetingOffsetIndependentIntention<TElement : KtElement>(
|
abstract class SelfTargetingOffsetIndependentIntention<TElement : KtElement>(
|
||||||
elementType: Class<TElement>,
|
elementType: Class<TElement>,
|
||||||
@Nls text: String,
|
@Nls textGetter: () -> String,
|
||||||
@Nls familyName: String = text
|
@Nls familyNameGetter: () -> String = textGetter,
|
||||||
) : SelfTargetingRangeIntention<TElement>(elementType, text, familyName) {
|
) : SelfTargetingRangeIntention<TElement>(elementType, textGetter, familyNameGetter) {
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"Replace with primary constructor",
|
||||||
|
ReplaceWith("SelfTargetingOffsetIndependentIntention(elementType, { text }, { familyName })")
|
||||||
|
)
|
||||||
|
constructor(
|
||||||
|
elementType: Class<TElement>,
|
||||||
|
@Nls text: String,
|
||||||
|
@Nls familyName: String = text,
|
||||||
|
) : this(elementType, { text }, { familyName })
|
||||||
|
|
||||||
abstract fun isApplicableTo(element: TElement): Boolean
|
abstract fun isApplicableTo(element: TElement): Boolean
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user