diff --git a/java/java-tests/testSrc/com/intellij/java/psi/formatter/java/JavaEnterActionTest.java b/java/java-tests/testSrc/com/intellij/java/psi/formatter/java/JavaEnterActionTest.java index ea2edf213c37..d7393b8e024b 100644 --- a/java/java-tests/testSrc/com/intellij/java/psi/formatter/java/JavaEnterActionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/psi/formatter/java/JavaEnterActionTest.java @@ -613,4 +613,21 @@ public class JavaEnterActionTest extends AbstractEnterActionTestCase { "}" ); } + + public void testIdea192807() { + doTextTest( + "java", + + "class MyTest\n" + + "{\n" + + " private void foo() { String a = \"a\"; String b = \"b\";}\n" + + "}", + + "class MyTest\n" + + "{\n" + + " private void foo() { String a = \"a\";\n" + + " String b = \"b\";}\n" + + "}" + ); + } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/lineIndent/JavaLikeLangLineIndentProvider.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/lineIndent/JavaLikeLangLineIndentProvider.java index fc1acbd97fe3..b337ba190461 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/lineIndent/JavaLikeLangLineIndentProvider.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/lineIndent/JavaLikeLangLineIndentProvider.java @@ -136,7 +136,7 @@ public abstract class JavaLikeLangLineIndentProvider implements LineIndentProvid } int statementStart = getStatementStartOffset(beforeSemicolon, dropIndentAfterReturnLike(beforeSemicolon)); SemanticEditorPosition atStatementStart = getPosition(editor, statementStart); - if (atStatementStart.isAt(BlockOpeningBrace)) { + if (isAtBlockOpeningOnSameLine(atStatementStart)) { return myFactory.createIndentCalculator(getIndentInBlock(project, language, atStatementStart), this::getDeepBlockStatementStartOffset); } if (!isInsideForLikeConstruction(atStatementStart)) { @@ -203,6 +203,17 @@ public abstract class JavaLikeLangLineIndentProvider implements LineIndentProvid return null; } + private static boolean isAtBlockOpeningOnSameLine(@NotNull SemanticEditorPosition position) { + SemanticEditorPosition pos = position.copy(); + while (!pos.isAt(BlockOpeningBrace)) { + pos.moveBefore(); + if (pos.isAtEnd() || pos.isAtMultiline()) { + return false; + } + } + return true; + } + private SemanticEditorPosition afterOptionalWhitespaceOnSameLine(@NotNull Editor editor, int offset) { SemanticEditorPosition position = getPosition(editor, offset); if (position.isAt(Whitespace)) {