From ed595aab27b6198757726bf77e66f9167f126d23 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Sun, 10 May 2015 11:07:29 +0300 Subject: [PATCH] Fixed formatting problem + other way of creating returns --- .../frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt | 7 ++++--- .../idea/intentions/declarations/DeclarationUtils.java | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt index a4ee3dc28c1..50cc0eab4e0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt @@ -63,7 +63,8 @@ public class JetPsiFactory(private val project: Project) { } public fun createExpression(text: String): JetExpression { - return createProperty("val x = $text").getInitializer() ?: error("Failed to create expression from text: '$text'") + //TODO: '\n' below if important - some strange code indenting problems appear without it + return createProperty("val x =\n$text").getInitializer() ?: error("Failed to create expression from text: '$text'") } public fun createClassLiteral(className: String): JetClassLiteralExpression = @@ -345,8 +346,8 @@ public class JetPsiFactory(private val project: Project) { return createExpression("return $text") as JetReturnExpression } - public fun createReturn(expression: JetExpression?): JetReturnExpression { - return createReturn(JetPsiUtil.getText(expression)) + public fun createReturn(expression: JetExpression): JetReturnExpression { + return createExpressionByPattern("return $0", expression) as JetReturnExpression } public fun createIf(condition: JetExpression, thenExpr: JetExpression, elseExpr: JetExpression?): JetIfExpression { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/declarations/DeclarationUtils.java b/idea/src/org/jetbrains/kotlin/idea/intentions/declarations/DeclarationUtils.java index 91843d4bd37..e9b30070b0a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/declarations/DeclarationUtils.java +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/declarations/DeclarationUtils.java @@ -20,7 +20,6 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; -import com.intellij.psi.codeStyle.CodeStyleManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage; @@ -74,7 +73,6 @@ public class DeclarationUtils { Project project = newInitializer.getProject(); PsiFile file = parent.getContainingFile(); PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(PsiDocumentManager.getInstance(project).getDocument(file)); - CodeStyleManager.getInstance(project).adjustLineIndent(file, newInitializer.getTextRange()); //noinspection ConstantConditions JetType inferredType = getPropertyTypeIfNeeded(property);