Reformat: ChangeVariableMutabilityFix
This commit is contained in:
committed by
Mikhail Glukhikh
parent
e141f4f407
commit
e26ab28d45
@@ -28,7 +28,10 @@ import org.jetbrains.kotlin.psi.*
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||||
|
|
||||||
class ChangeVariableMutabilityFix(element: KtValVarKeywordOwner, private val makeVar: Boolean) : KotlinQuickFixAction<KtValVarKeywordOwner>(element) {
|
class ChangeVariableMutabilityFix(
|
||||||
|
element: KtValVarKeywordOwner,
|
||||||
|
private val makeVar: Boolean
|
||||||
|
) : KotlinQuickFixAction<KtValVarKeywordOwner>(element) {
|
||||||
|
|
||||||
override fun getText() = if (makeVar) "Make variable mutable" else "Make variable immutable"
|
override fun getText() = if (makeVar) "Make variable mutable" else "Make variable immutable"
|
||||||
|
|
||||||
@@ -48,7 +51,7 @@ class ChangeVariableMutabilityFix(element: KtValVarKeywordOwner, private val mak
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val VAL_WITH_SETTER_FACTORY: KotlinSingleIntentionActionFactory = object: KotlinSingleIntentionActionFactory() {
|
val VAL_WITH_SETTER_FACTORY: KotlinSingleIntentionActionFactory = object : KotlinSingleIntentionActionFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
val accessor = diagnostic.psiElement as KtPropertyAccessor
|
val accessor = diagnostic.psiElement as KtPropertyAccessor
|
||||||
return ChangeVariableMutabilityFix(accessor.property, true)
|
return ChangeVariableMutabilityFix(accessor.property, true)
|
||||||
@@ -58,7 +61,8 @@ class ChangeVariableMutabilityFix(element: KtValVarKeywordOwner, private val mak
|
|||||||
class ReassignmentActionFactory(val factory: DiagnosticFactory1<*, DeclarationDescriptor>) : KotlinSingleIntentionActionFactory() {
|
class ReassignmentActionFactory(val factory: DiagnosticFactory1<*, DeclarationDescriptor>) : KotlinSingleIntentionActionFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
val propertyDescriptor = factory.cast(diagnostic).a
|
val propertyDescriptor = factory.cast(diagnostic).a
|
||||||
val declaration = DescriptorToSourceUtils.descriptorToDeclaration(propertyDescriptor) as? KtValVarKeywordOwner ?: return null
|
val declaration =
|
||||||
|
DescriptorToSourceUtils.descriptorToDeclaration(propertyDescriptor) as? KtValVarKeywordOwner ?: return null
|
||||||
return ChangeVariableMutabilityFix(declaration, true)
|
return ChangeVariableMutabilityFix(declaration, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,7 +73,7 @@ class ChangeVariableMutabilityFix(element: KtValVarKeywordOwner, private val mak
|
|||||||
|
|
||||||
val CAPTURED_MEMBER_VAL_INITIALIZATION_FACTORY = ReassignmentActionFactory(Errors.CAPTURED_MEMBER_VAL_INITIALIZATION)
|
val CAPTURED_MEMBER_VAL_INITIALIZATION_FACTORY = ReassignmentActionFactory(Errors.CAPTURED_MEMBER_VAL_INITIALIZATION)
|
||||||
|
|
||||||
val VAR_OVERRIDDEN_BY_VAL_FACTORY: KotlinSingleIntentionActionFactory = object: KotlinSingleIntentionActionFactory() {
|
val VAR_OVERRIDDEN_BY_VAL_FACTORY: KotlinSingleIntentionActionFactory = object : KotlinSingleIntentionActionFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
val element = diagnostic.psiElement
|
val element = diagnostic.psiElement
|
||||||
return when (element) {
|
return when (element) {
|
||||||
@@ -79,14 +83,14 @@ class ChangeVariableMutabilityFix(element: KtValVarKeywordOwner, private val mak
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val VAR_ANNOTATION_PARAMETER_FACTORY: KotlinSingleIntentionActionFactory = object: KotlinSingleIntentionActionFactory() {
|
val VAR_ANNOTATION_PARAMETER_FACTORY: KotlinSingleIntentionActionFactory = object : KotlinSingleIntentionActionFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
val element = diagnostic.psiElement as KtParameter
|
val element = diagnostic.psiElement as KtParameter
|
||||||
return ChangeVariableMutabilityFix(element, false)
|
return ChangeVariableMutabilityFix(element, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val LATEINIT_VAL_FACTORY = object: KotlinSingleIntentionActionFactory() {
|
val LATEINIT_VAL_FACTORY = object : KotlinSingleIntentionActionFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
val lateinitElement = Errors.INAPPLICABLE_LATEINIT_MODIFIER.cast(diagnostic).psiElement
|
val lateinitElement = Errors.INAPPLICABLE_LATEINIT_MODIFIER.cast(diagnostic).psiElement
|
||||||
val property = lateinitElement.getStrictParentOfType<KtProperty>() ?: return null
|
val property = lateinitElement.getStrictParentOfType<KtProperty>() ?: return null
|
||||||
|
|||||||
Reference in New Issue
Block a user