Fix MoveProperty intention: better property placement

Property is placed now before first property, or at the beginning of class body if no properties found.

#KT-18044 Fixed
This commit is contained in:
Vyacheslav Gerasimov
2017-05-29 14:15:39 +03:00
parent ca124d1e36
commit 24476fc581
6 changed files with 48 additions and 1 deletions
@@ -39,7 +39,8 @@ class MovePropertyToClassBodyIntention : SelfTargetingIntention<KtParameter>(KtP
val propertyDeclaration = KtPsiFactory(element)
.createProperty("${element.valOrVarKeyword?.text} ${element.name} = ${element.name}")
parentClass.addDeclaration(propertyDeclaration).apply {
val firstProperty = parentClass.getProperties().firstOrNull()
parentClass.addDeclarationBefore(propertyDeclaration, firstProperty).apply {
val propertyModifierList = element.modifierList?.copy() as? KtModifierList
propertyModifierList?.let { modifierList?.replace(it) ?: addBefore(it, firstChild) }
modifierList?.annotationEntries?.forEach {