summaryrefslogtreecommitdiff
path: root/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithTryFinallySurrounder.java
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2014-09-18 11:43:07 -0700
committerTor Norbye <tnorbye@google.com>2014-09-18 11:43:28 -0700
commite782c57d74000722f9db4c9426317410520670c6 (patch)
tree6e5d3e8934107ffabb7661f8bfc0e1a08eb37faf /java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithTryFinallySurrounder.java
parentc3d3a90f6b4ead083d63e28e6b9fcea93d675678 (diff)
downloadidea-e782c57d74000722f9db4c9426317410520670c6.tar.gz
Snapshot idea/138.2210 from git://git.jetbrains.org/idea/community.git
Change-Id: I8f0204d7887ee78cf1fd8c09f936c5afff0edd2f
Diffstat (limited to 'java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithTryFinallySurrounder.java')
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithTryFinallySurrounder.java16
1 files changed, 6 insertions, 10 deletions
diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithTryFinallySurrounder.java b/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithTryFinallySurrounder.java
index e757ddeacc17..28732a65390b 100644
--- a/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithTryFinallySurrounder.java
+++ b/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithTryFinallySurrounder.java
@@ -19,10 +19,8 @@ import com.intellij.codeInsight.CodeInsightBundle;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.EditorModificationUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
-import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.util.IncorrectOperationException;
@@ -65,16 +63,14 @@ class JavaWithTryFinallySurrounder extends JavaStatementsSurrounder{
if (finallyBlock == null) {
return null;
}
- int offset = finallyBlock.getTextRange().getStartOffset() + 2;
- editor.getCaretModel().moveToOffset(offset);
- final Document document = editor.getDocument();
+ Document document = editor.getDocument();
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
+ TextRange finallyBlockRange = finallyBlock.getTextRange();
+ int newLineOffset = finallyBlockRange.getStartOffset() + 2;
+ editor.getCaretModel().moveToOffset(newLineOffset);
editor.getSelectionModel().removeSelection();
- final PsiStatement[] tryBlockStatements = tryBlock.getStatements();
- LOG.assertTrue(tryBlockStatements.length > 0, tryBlock.getText());
- final PsiStatement firstTryStmt = tryBlockStatements[0];
- final int indent = firstTryStmt.getTextOffset() - document.getLineStartOffset(document.getLineNumber(firstTryStmt.getTextOffset()));
- EditorModificationUtil.insertStringAtCaret(editor, StringUtil.repeat(" ", indent), false, true);
+ CodeStyleManager.getInstance(project).adjustLineIndent(document, newLineOffset);
+ PsiDocumentManager.getInstance(project).commitDocument(document);
return new TextRange(editor.getCaretModel().getOffset(), editor.getCaretModel().getOffset());
}
} \ No newline at end of file