Reformat: Convert to primary constructor
This commit is contained in:
+5
-4
@@ -100,7 +100,8 @@ class ConvertSecondaryConstructorToPrimaryIntention : SelfTargetingRangeIntentio
|
|||||||
val constructorDescriptor = context[BindingContext.CONSTRUCTOR, this] ?: return null
|
val constructorDescriptor = context[BindingContext.CONSTRUCTOR, this] ?: return null
|
||||||
val initializer = factory.createAnonymousInitializer() as? KtClassInitializer
|
val initializer = factory.createAnonymousInitializer() as? KtClassInitializer
|
||||||
for (statement in bodyExpression?.statements ?: emptyList()) {
|
for (statement in bodyExpression?.statements ?: emptyList()) {
|
||||||
val (rightDescriptor, leftDescriptor) = statement.tryConvertToPropertyByParameterInitialization(constructorDescriptor, context)
|
val (rightDescriptor, leftDescriptor) =
|
||||||
|
statement.tryConvertToPropertyByParameterInitialization(constructorDescriptor, context)
|
||||||
?: with(initializer) {
|
?: with(initializer) {
|
||||||
(initializer?.body as? KtBlockExpression)?.let {
|
(initializer?.body as? KtBlockExpression)?.let {
|
||||||
it.addBefore(statement.copy(), it.rBrace)
|
it.addBefore(statement.copy(), it.rBrace)
|
||||||
@@ -131,7 +132,8 @@ class ConvertSecondaryConstructorToPrimaryIntention : SelfTargetingRangeIntentio
|
|||||||
if (property != null) {
|
if (property != null) {
|
||||||
if (propertyDescriptor.name == parameterDescriptor.name &&
|
if (propertyDescriptor.name == parameterDescriptor.name &&
|
||||||
propertyDescriptor.type == parameterDescriptor.type &&
|
propertyDescriptor.type == parameterDescriptor.type &&
|
||||||
propertyDescriptor.accessors.all { it.isDefault }) {
|
propertyDescriptor.accessors.all { it.isDefault }
|
||||||
|
) {
|
||||||
propertyCommentSaver = CommentSaver(property)
|
propertyCommentSaver = CommentSaver(property)
|
||||||
val valOrVar = if (property.isVar) factory.createVarKeyword() else factory.createValKeyword()
|
val valOrVar = if (property.isVar) factory.createVarKeyword() else factory.createValKeyword()
|
||||||
newParameter.addBefore(valOrVar, newParameter.nameIdentifier)
|
newParameter.addBefore(valOrVar, newParameter.nameIdentifier)
|
||||||
@@ -141,8 +143,7 @@ class ConvertSecondaryConstructorToPrimaryIntention : SelfTargetingRangeIntentio
|
|||||||
newParameter.addBefore(newModifiers, newParameter.valOrVarKeyword)
|
newParameter.addBefore(newModifiers, newParameter.valOrVarKeyword)
|
||||||
}
|
}
|
||||||
property.delete()
|
property.delete()
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
property.initializer = factory.createSimpleName(parameterDescriptor.name.asString())
|
property.initializer = factory.createSimpleName(parameterDescriptor.name.asString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user