diff --git a/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/FormatterBasedLineIndentInfoBuilder.java b/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/FormatterBasedLineIndentInfoBuilder.java index 164956c51e4a..e18a834445e7 100644 --- a/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/FormatterBasedLineIndentInfoBuilder.java +++ b/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/FormatterBasedLineIndentInfoBuilder.java @@ -20,6 +20,7 @@ import com.intellij.lang.LanguageFormatting; import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiComment; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; @@ -59,9 +60,7 @@ public class FormatterBasedLineIndentInfoBuilder { List normallyIndentedBlocks = ContainerUtil.filter(getBlocksStartingNewLine(), new Condition() { @Override public boolean value(Block block) { - Indent indent = block.getIndent(); - Indent.Type type = indent != null ? indent.getType() : null; - return type == Indent.Type.NONE || type == Indent.Type.NORMAL; + return hasTotallyNormalOrNoneIndent(block); } }); @@ -74,6 +73,29 @@ public class FormatterBasedLineIndentInfoBuilder { } }); } + + private static boolean hasTotallyNormalOrNoneIndent(Block block) { + final TextRange range = block.getTextRange(); + final int startOffset = range.getStartOffset(); + + boolean startOffsetAlreadyHasNormalIndent = false; + + while (block != null && range.getStartOffset() == startOffset) { + Indent.Type type = block.getIndent() != null ? block.getIndent().getType() : null; + + if (type == Indent.Type.NONE || type == Indent.Type.NORMAL && !startOffsetAlreadyHasNormalIndent) { + startOffsetAlreadyHasNormalIndent = true; + } + else { + return false; + } + + List subBlocks = block.getSubBlocks(); + block = subBlocks.isEmpty() ? null : subBlocks.get(0); + } + + return true; + } @NotNull private List getBlocksStartingNewLine() {