mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[formatter-core: context formatting] removed unnecessary abstraction
This commit is contained in:
@@ -69,25 +69,19 @@ class VcsAwareFormatRangesInfo(val formattingRanges: List<TextRange>,
|
||||
|
||||
|
||||
class AdditionalRangesExtractor(private val formatRanges: FormatTextRanges) : BlockProcessor {
|
||||
val extraRanges = mutableListOf<ExtraReformatRanges>()
|
||||
val extraRanges = mutableListOf<TextRange>()
|
||||
|
||||
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<TextRange> = 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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<TextRange> getExtraRangesToFormat(FormatTextRanges ranges) {
|
||||
if (ranges.isInsertedBlock(this) && myNode.textContains('\n')) {
|
||||
List<TextRange> extra = calculateExtraRanges(myNode);
|
||||
return new ExtraReformatRanges(extra);
|
||||
return calculateExtraRanges(myNode);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user