Minor: refactoring AddValVarToConstructorParameterAction
This commit is contained in:
+7
-6
@@ -30,11 +30,12 @@ import org.jetbrains.kotlin.idea.refactoring.ValVarExpression
|
|||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
|
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
|
|
||||||
interface AddValVarToConstructorParameterAction {
|
interface AddValVarToConstructorParameterAction {
|
||||||
companion object {
|
companion object {
|
||||||
val actionFamily = "Add val/var to primary constructor parameter"
|
const val actionFamily = "Add val/var to primary constructor parameter"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getActionText(element: KtParameter) = "Add val/var to parameter '${element.name ?: ""}'"
|
fun getActionText(element: KtParameter) = "Add val/var to parameter '${element.name ?: ""}'"
|
||||||
@@ -65,11 +66,11 @@ interface AddValVarToConstructorParameterAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Intention :
|
class Intention :
|
||||||
SelfTargetingRangeIntention<KtParameter>(KtParameter::class.java, actionFamily),
|
SelfTargetingRangeIntention<KtParameter>(KtParameter::class.java, actionFamily),
|
||||||
AddValVarToConstructorParameterAction {
|
AddValVarToConstructorParameterAction {
|
||||||
override fun applicabilityRange(element: KtParameter): TextRange? {
|
override fun applicabilityRange(element: KtParameter): TextRange? {
|
||||||
if (!canInvoke(element)) return null
|
if (!canInvoke(element)) return null
|
||||||
if (element.getStrictParentOfType<KtClass>()?.isData() ?: false) return null
|
if (element.getStrictParentOfType<KtClass>()?.isData() == true) return null
|
||||||
text = getActionText(element)
|
text = getActionText(element)
|
||||||
return element.nameIdentifier?.textRange
|
return element.nameIdentifier?.textRange
|
||||||
}
|
}
|
||||||
@@ -78,8 +79,8 @@ interface AddValVarToConstructorParameterAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class QuickFix(parameter: KtParameter) :
|
class QuickFix(parameter: KtParameter) :
|
||||||
KotlinQuickFixAction<KtParameter>(parameter),
|
KotlinQuickFixAction<KtParameter>(parameter),
|
||||||
AddValVarToConstructorParameterAction {
|
AddValVarToConstructorParameterAction {
|
||||||
override fun getText() = element?.let { getActionText(it) } ?: ""
|
override fun getText() = element?.let { getActionText(it) } ?: ""
|
||||||
|
|
||||||
override fun getFamilyName() = actionFamily
|
override fun getFamilyName() = actionFamily
|
||||||
|
|||||||
Reference in New Issue
Block a user