From 0c397548e8795722acad6238f4fa0439370fe78b Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Sat, 23 May 2015 11:09:40 +0300 Subject: [PATCH] createByPattern fix (after we changed way how JetPsiFactory.createArgument works --- .../src/org/jetbrains/kotlin/psi/createByPattern.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt index 97b335bbe9f..e7f68b71450 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt @@ -24,6 +24,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager import com.intellij.psi.impl.source.codeStyle.CodeEditUtil import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.parents +import org.jetbrains.kotlin.psi.psiUtil.replaced import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import java.util.ArrayList @@ -105,7 +106,14 @@ public fun createByPattern(pattern: String, vararg args: if (element is JetFunctionLiteral) { element = element.getParent() as JetFunctionLiteralExpression } - element.replace(args[n] as PsiElement) + val argument = args[n] as PsiElement + // if argument element has generated flag then it has not been formatted yet and we should do this manually + // (because we cleared this flag for the whole tree above and PostprocessReformattingAspect won't format anything) + val reformat = CodeEditUtil.isNodeGenerated(argument.getNode()) + element = element.replaced(argument) + if (reformat) { + codeStyleManager.reformat(element, true) + } } codeStyleManager.adjustLineIndent(resultElement.getContainingFile(), resultElement.getTextRange())