mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
[regionAccess] don't make merge() API for now
Signed-off-by: Moritz Eysholdt <moritz.eysholdt@itemis.de>
This commit is contained in:
parent
097a8a1dd3
commit
84bfecf6d0
5 changed files with 28 additions and 27 deletions
|
@ -13,6 +13,7 @@ import org.eclipse.xtext.formatting2.regionaccess.ILineRegion;
|
|||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextReplacement;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextSegment;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.internal.TextRegions;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.base.Throwables;
|
||||
|
@ -64,9 +65,9 @@ public class TextRegionsInTextToString {
|
|||
return this.frame;
|
||||
ITextRegionAccess access = getTextRegionAccess();
|
||||
if (access != null) {
|
||||
ITextSegment impactRegion = access.merge(this.items);
|
||||
ITextSegment impactRegion = TextRegions.merge(this.items);
|
||||
List<ILineRegion> expandToLines = access.expandToLines(impactRegion, getLeadingLines(), getTrailingLines());
|
||||
return access.merge(expandToLines);
|
||||
return TextRegions.merge(expandToLines);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess;
|
|||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionRewriter;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextReplacement;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextSegment;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.internal.TextRegions;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
|
@ -80,9 +81,9 @@ public class TextRegionsWithTitleToString {
|
|||
List<ITextSegment> segments = Lists.newArrayList();
|
||||
for (Item item : items)
|
||||
segments.add(item.getRegion());
|
||||
ITextSegment impactRegion = access.merge(segments);
|
||||
ITextSegment impactRegion = TextRegions.merge(segments);
|
||||
List<ILineRegion> expandToLines = access.expandToLines(impactRegion, getLeadingLines(), getTrailingLines());
|
||||
return access.merge(expandToLines);
|
||||
return TextRegions.merge(expandToLines);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -191,7 +191,5 @@ public interface ITextRegionAccess {
|
|||
|
||||
String textForOffset(int offset, int length);
|
||||
|
||||
ITextSegment merge(Iterable<? extends ITextSegment> segments);
|
||||
|
||||
List<ILineRegion> expandToLines(ITextSegment segment, int leadingLinesToAdd, int trailingLinesToAdd);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import java.util.Arrays;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -269,26 +268,6 @@ public abstract class AbstractRegionAccess implements ITextRegionAccess {
|
|||
return new LineRegion(this, start, end - start);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextSegment merge(Iterable<? extends ITextSegment> segments) {
|
||||
Iterator<? extends ITextSegment> it = segments.iterator();
|
||||
if (!it.hasNext())
|
||||
throw new IllegalStateException();
|
||||
ITextSegment first = it.next();
|
||||
int minOffset = first.getOffset();
|
||||
int maxEndOffset = first.getEndOffset();
|
||||
while (it.hasNext()) {
|
||||
ITextSegment next = it.next();
|
||||
int offset = next.getOffset();
|
||||
int endOffset = next.getEndOffset();
|
||||
if (offset < minOffset)
|
||||
minOffset = offset;
|
||||
if (endOffset > maxEndOffset)
|
||||
maxEndOffset = endOffset;
|
||||
}
|
||||
return new TextSegment(this, minOffset, maxEndOffset - minOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILineRegion> expandToLines(ITextSegment segment, int leadingLinesToAdd, int trailingLinesToAdd) {
|
||||
List<ILineRegion> lines = Lists.newArrayList(segment.getLineRegions());
|
||||
|
|
|
@ -10,8 +10,10 @@ package org.eclipse.xtext.formatting2.regionaccess.internal;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextSegment;
|
||||
import org.eclipse.xtext.util.ITextRegion;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -65,4 +67,24 @@ public class TextRegions {
|
|||
}
|
||||
return ImmutableList.copyOf(missing);
|
||||
}
|
||||
|
||||
public static ITextSegment merge(Iterable<? extends ITextSegment> segments) {
|
||||
Iterator<? extends ITextSegment> it = segments.iterator();
|
||||
if (!it.hasNext())
|
||||
throw new IllegalStateException();
|
||||
ITextSegment first = it.next();
|
||||
int minOffset = first.getOffset();
|
||||
int maxEndOffset = first.getEndOffset();
|
||||
while (it.hasNext()) {
|
||||
ITextSegment next = it.next();
|
||||
int offset = next.getOffset();
|
||||
int endOffset = next.getEndOffset();
|
||||
if (offset < minOffset)
|
||||
minOffset = offset;
|
||||
if (endOffset > maxEndOffset)
|
||||
maxEndOffset = endOffset;
|
||||
}
|
||||
return new TextSegment(first.getTextRegionAccess(), minOffset, maxEndOffset - minOffset);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue