Code Insight: Format generated declarations

#KT-11176 Fixed
(cherry picked from commit 3641ad6)
This commit is contained in:
Alexey Sedunov
2016-06-30 15:02:14 +03:00
parent a33f946c14
commit 3ba776fffa
51 changed files with 57 additions and 69 deletions
@@ -23,9 +23,9 @@ import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.SmartPointerManager
import com.intellij.psi.codeStyle.CodeStyleManager
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.SmartList
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
@@ -174,7 +174,7 @@ fun <T : KtDeclaration> insertMembersAfter(
if (otherMembers.isNotEmpty()) {
val body = classOrObject.getOrCreateBody()
var afterAnchor = anchor ?: findInsertAfterAnchor(editor, body) ?: return@runWriteAction emptyList()
var afterAnchor = anchor ?: findInsertAfterAnchor(editor, body) ?: return@runWriteAction emptyList<T>()
otherMembers.mapNotNullTo(insertedMembers) {
if (classOrObject is KtClass && classOrObject.isEnum()) {
val enumEntries = classOrObject.declarations.filterIsInstance<KtEnumEntry>()
@@ -204,6 +204,9 @@ fun <T : KtDeclaration> insertMembersAfter(
}
insertedMembers
}.apply {
val codeStyleManager = CodeStyleManager.getInstance(classOrObject.project)
forEach { codeStyleManager.reformat(it) }
}
}