From 65c8a3834e15fb01167476fe6729d86745de2d97 Mon Sep 17 00:00:00 2001 From: Yaroslav Lepenkin Date: Wed, 6 Jul 2016 15:20:47 +0300 Subject: [PATCH] [formatter-core: context formatting] removed unnecessary abstraction --- .../formatting/AdjustFormatRangesState.kt | 18 +++++++----------- .../psi/formatter/common/AbstractBlock.java | 6 ++---- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/formatting/AdjustFormatRangesState.kt b/platform/lang-impl/src/com/intellij/formatting/AdjustFormatRangesState.kt index a700c34f5bec..1b79993ce555 100644 --- a/platform/lang-impl/src/com/intellij/formatting/AdjustFormatRangesState.kt +++ b/platform/lang-impl/src/com/intellij/formatting/AdjustFormatRangesState.kt @@ -69,25 +69,19 @@ class VcsAwareFormatRangesInfo(val formattingRanges: List, class AdditionalRangesExtractor(private val formatRanges: FormatTextRanges) : BlockProcessor { - val extraRanges = mutableListOf() + val extraRanges = mutableListOf() override fun processLeafBlock(block: Block) = Unit override fun processCompositeBlock(block: Block) { if (block is AbstractBlock) { - block.getExtraRangesToFormat(formatRanges)?.let { extraRanges.add(it) } + block.getExtraRangesToFormat(formatRanges)?.let { + extraRanges.addAll(it) + } } } } -class ExtraReformatRanges(val ranges: List = emptyList()) { - constructor(range: TextRange): this(listOf(range)) -} - -fun FormatTextRanges.mergeWith(extraRanges: ExtraReformatRanges) { - extraRanges.ranges.forEach { add(it, false) } -} - class AdjustFormatRangesState(var currentRoot: Block, val formatRanges: FormatTextRanges) : State() { @@ -97,7 +91,9 @@ class AdjustFormatRangesState(var currentRoot: Block, init { setOnDone({ - extractor.extraRanges.forEach { formatRanges.mergeWith(it) } + extractor.extraRanges.forEach { + formatRanges.add(it, false) + } }) } diff --git a/platform/lang-impl/src/com/intellij/psi/formatter/common/AbstractBlock.java b/platform/lang-impl/src/com/intellij/psi/formatter/common/AbstractBlock.java index 2ca0874b6afd..b793a2e384e8 100644 --- a/platform/lang-impl/src/com/intellij/psi/formatter/common/AbstractBlock.java +++ b/platform/lang-impl/src/com/intellij/psi/formatter/common/AbstractBlock.java @@ -187,12 +187,10 @@ public abstract class AbstractBlock implements ASTBlock { * @return additional range to reformat, when this block if formatted */ @Nullable - public ExtraReformatRanges getExtraRangesToFormat(FormatTextRanges ranges) { + public List getExtraRangesToFormat(FormatTextRanges ranges) { if (ranges.isInsertedBlock(this) && myNode.textContains('\n')) { - List extra = calculateExtraRanges(myNode); - return new ExtraReformatRanges(extra); + return calculateExtraRanges(myNode); } - return null; }