X-Git-Url: https://git.jetbrains.org/?p=idea%2Fcommunity.git;a=blobdiff_plain;f=platform%2Flang-impl%2Fsrc%2Fcom%2Fintellij%2Fformatting%2FFormatProcessor.java;h=8d157038435fb2d8ef56a9e86f390a7b5329dcc0;hp=698a1677f5abaf217961f3bc67e2fe5bff934558;hb=03a72e58c33bc50c82441568dd094a3bfba488c5;hpb=6c3ee1c84b970771bffc203b981918dc58116f3f diff --git a/platform/lang-impl/src/com/intellij/formatting/FormatProcessor.java b/platform/lang-impl/src/com/intellij/formatting/FormatProcessor.java index 698a1677f5ab..8d157038435f 100644 --- a/platform/lang-impl/src/com/intellij/formatting/FormatProcessor.java +++ b/platform/lang-impl/src/com/intellij/formatting/FormatProcessor.java @@ -159,7 +159,8 @@ public class FormatProcessor { @NotNull private State myCurrentState; - private MultiMap myExpandableIndents; + private MultiMap myExpandableIndents; + private Map myExpandableIndentsMinOffsetBlocksToWrappers; public FormatProcessor(final FormattingDocumentModel docModel, Block rootBlock, @@ -1365,7 +1366,9 @@ public class FormatProcessor { root, model, affectedRanges, mySettings, myDefaultIndentOption, interestingOffset, myProgressCallback ); myWrapper.setCollectAlignmentsInsideFormattingRange(myReformatContext); - myExpandableIndents = myWrapper.getBlocksWithSmartIndents(); + + myExpandableIndents = myWrapper.getExpandableIndentsBlocks(); + myExpandableIndentsMinOffsetBlocksToWrappers = myWrapper.getMarkerBlocks(); } @Override @@ -1590,9 +1593,8 @@ public class FormatProcessor { } } - private class ExpandChildrenIndent extends State { - private Iterator myIterator; + private Iterator myIterator; public ExpandChildrenIndent() { super(FormattingStateId.EXPANDING_CHILDREN_INDENTS); @@ -1608,11 +1610,10 @@ public class FormatProcessor { return; } - Collection blocksToExpandIndent = myExpandableIndents.get(myIterator.next()); - - if (shouldExpand(blocksToExpandIndent)) { + final ExpandableIndent indent = myIterator.next(); + Collection blocksToExpandIndent = myExpandableIndents.get(indent); + if (shouldExpand(indent, blocksToExpandIndent)) { for (AbstractBlockWrapper block : blocksToExpandIndent) { - ExpandableIndent indent = (ExpandableIndent)block.getIndent(); indent.setEnforceIndent(true); reindentNewLineChildren(block); indent.setEnforceIndent(false); @@ -1620,28 +1621,20 @@ public class FormatProcessor { } } - private boolean shouldExpand(Collection blocksToExpandIndent) { - int minGroupOffset = Integer.MAX_VALUE; + private boolean shouldExpand(ExpandableIndent indent, Collection blocksToExpandIndent) { for (AbstractBlockWrapper block : blocksToExpandIndent) { if (!block.getWhiteSpace().containsLineFeeds()) continue; - - ExpandableIndent indent = (ExpandableIndent)block.getIndent(); - if (indent.isMinGroupOffsetMarker()) { - minGroupOffset = block.getNumberOfSymbolsBeforeBlock().getTotalSpaces(); - } - else { - return true; - } + return true; } - if (minGroupOffset == Integer.MAX_VALUE) return false; + int strictMinOffset = getStrictMinOffset(indent); + if (strictMinOffset == Integer.MAX_VALUE) { + return false; + } for (AbstractBlockWrapper block : blocksToExpandIndent) { - ExpandableIndent indent = (ExpandableIndent)block.getIndent(); - if (indent.isMinGroupOffsetMarker()) continue; - int minNewLineChildrenOffset = findMinNewLineIndent(block); - if (minNewLineChildrenOffset <= minGroupOffset) { + if (minNewLineChildrenOffset <= strictMinOffset) { return true; } } @@ -1649,6 +1642,18 @@ public class FormatProcessor { return false; } + private int getStrictMinOffset(ExpandableIndent indent) { + final Block minOffsetBlock = indent.getStrictMinOffsetBlock(); + if (minOffsetBlock == null) return Integer.MAX_VALUE; + + AbstractBlockWrapper wrapper = myExpandableIndentsMinOffsetBlocksToWrappers.get(minOffsetBlock); + if (wrapper.getWhiteSpace().containsLineFeeds()) { + return wrapper.getNumberOfSymbolsBeforeBlock().getTotalSpaces(); + } + + return Integer.MAX_VALUE; + } + private int findMinNewLineIndent(@NotNull AbstractBlockWrapper block) { if (block instanceof LeafBlockWrapper && block.getWhiteSpace().containsLineFeeds()) { return block.getNumberOfSymbolsBeforeBlock().getTotalSpaces();