use of org.eclipse.xtext.util.TextRegionWithLineInformation in project xtext-core by eclipse.
the class TraceRegionTest method testLeafIterator_OneChild_LeftGap.
@Test
public void testLeafIterator_OneChild_LeftGap() {
final TraceRegion parent = new TraceRegion(0, 2, 0, 2, true, 2, 3, 0, 0, null, newURI());
AbstractTraceRegion first = new AbstractStatefulTraceRegion(new TextRegionWithLineInformation(0, 1, 0, 1), true, new LocationData(2, 3, 0, 0, null), parent) {
};
TraceRegion second = new TraceRegion(1, 1, 1, 2, true, 3, 4, 0, 0, parent, null);
Iterator<AbstractTraceRegion> iter = parent.leafIterator();
assertEquals(Arrays.asList(first, second).iterator(), iter);
}
use of org.eclipse.xtext.util.TextRegionWithLineInformation in project xtext-core by eclipse.
the class TraceRegionTest method testLeafIterator_OneGrandChild_LeftGap.
@Test
public void testLeafIterator_OneGrandChild_LeftGap() {
final TraceRegion root = new TraceRegion(0, 2, 0, 2, true, 2, 3, 0, 0, null, newURI());
AbstractTraceRegion first = new AbstractStatefulTraceRegion(new TextRegionWithLineInformation(0, 1, 0, 1), true, new LocationData(2, 3, 0, 0, null), root) {
};
TraceRegion parent = new TraceRegion(1, 1, 1, 2, true, 3, 4, 0, 0, root, null);
TraceRegion second = new TraceRegion(1, 1, 1, 2, true, 3, 4, 0, 0, parent, null);
Iterator<AbstractTraceRegion> iter = root.leafIterator();
assertEquals(Arrays.asList(first, second).iterator(), iter);
}
use of org.eclipse.xtext.util.TextRegionWithLineInformation in project xtext-core by eclipse.
the class TraceRegionTest method testLeafIterator_OneChild_RightGap.
@Test
public void testLeafIterator_OneChild_RightGap() {
final TraceRegion parent = new TraceRegion(0, 2, 0, 2, true, 2, 3, 0, 0, null, newURI());
AbstractTraceRegion first = new TraceRegion(0, 1, 0, 1, true, 3, 4, 0, 0, parent, null);
AbstractTraceRegion second = new AbstractStatefulTraceRegion(new TextRegionWithLineInformation(1, 1, 1, 2), true, new LocationData(2, 3, 0, 0, null), parent) {
};
Iterator<AbstractTraceRegion> iter = parent.leafIterator();
assertEquals(Arrays.asList(first, second).iterator(), iter);
}
use of org.eclipse.xtext.util.TextRegionWithLineInformation in project xtext-core by eclipse.
the class AbstractNode method getTextRegionWithLineInformation.
/**
* @since 2.5
*/
protected ITextRegionWithLineInformation getTextRegionWithLineInformation(int offset, int length) {
INode rootNode = getRootNode();
if (rootNode != null) {
int startLine = basicGetLineOfOffset(rootNode, offset);
int endLine = basicGetLineOfOffset(rootNode, offset + length);
return new TextRegionWithLineInformation(offset, length, startLine, endLine);
}
return new TextRegionWithLineInformation(offset, length, 1, 1);
}
use of org.eclipse.xtext.util.TextRegionWithLineInformation in project xtext-core by eclipse.
the class AbstractTraceRegion method getMergedAssociatedLocation.
/**
* Returns the merged location of all associated locations if they belong to the same resource. Otherwise
* <code>null</code> is returned.
*/
public ILocationData getMergedAssociatedLocation() {
List<ILocationData> allData = getAssociatedLocations();
if (allData.isEmpty()) {
return null;
}
if (allData.size() == 1) {
return allData.get(0);
}
boolean allNull = true;
SourceRelativeURI path = null;
ITextRegionWithLineInformation region = ITextRegionWithLineInformation.EMPTY_REGION;
for (ILocationData data : allData) {
if (path != null) {
if (!path.equals(data.getSrcRelativePath())) {
return null;
}
} else {
if (data.getSrcRelativePath() == null) {
if (!allNull)
throw new IllegalStateException("Iff multiple associated locations are present, the path has to be set");
} else {
allNull = false;
path = data.getSrcRelativePath();
}
}
region = region.merge(new TextRegionWithLineInformation(data.getOffset(), data.getLength(), data.getLineNumber(), data.getEndLineNumber()));
}
return new LocationData(region.getOffset(), region.getLength(), region.getLineNumber(), region.getEndLineNumber(), path);
}
Aggregations