use of org.eclipse.xtext.util.ITextRegionWithLineInformation in project xtext-core by eclipse.
the class AbstractTrace method mergeRegions.
protected ILocationInResource mergeRegions(AbstractTraceRegion left, AbstractTraceRegion right) {
if (left == null) {
if (right != null) {
return getMergedLocationInResource(right);
}
return null;
}
if (right == null || left.equals(right)) {
return getMergedLocationInResource(left);
} else {
SourceRelativeURI leftToPath = left.getAssociatedSrcRelativePath();
SourceRelativeURI rightToPath = right.getAssociatedSrcRelativePath();
if (ObjectExtensions.operator_equals(leftToPath, rightToPath)) {
ITextRegionWithLineInformation leftRegion = left.getMyRegion();
ITextRegionWithLineInformation rightRegion = right.getMyRegion();
if (leftRegion.contains(rightRegion)) {
return getMergedLocationInResource(left);
} else if (rightRegion.contains(leftRegion)) {
return getMergedLocationInResource(right);
} else {
AbstractTraceRegion parent = left.getParent();
AbstractTraceRegion leftChild = left;
while (parent != null) {
if (parent.getMyRegion().contains(rightRegion)) {
break;
}
leftChild = parent;
parent = parent.getParent();
}
if (parent != null) {
AbstractTraceRegion rightChild = right;
while (!parent.equals(rightChild.getParent())) {
rightChild = rightChild.getParent();
if (rightChild == null) {
return getMergedLocationInResource(leftChild);
}
}
SourceRelativeURI path = leftToPath;
if (path == null) {
path = leftChild.getAssociatedSrcRelativePath();
}
ITextRegionWithLineInformation merged = parent.getMergedAssociatedLocation();
if (merged != null) {
return createLocationInResource(merged, path);
}
}
}
}
}
// TODO the remaining cases have yet to be implemented
return null;
}
use of org.eclipse.xtext.util.ITextRegionWithLineInformation in project xtext-core by eclipse.
the class LocationInFileProviderTest method testEObjectSignificantLocation.
@Test
public void testEObjectSignificantLocation() throws Exception {
assertEquals(2, elements.size());
ITextRegionWithLineInformation location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(elements.get(0));
assertEquals(modelAsString.indexOf("x"), location.getOffset());
assertEquals(1, location.getLength());
assertEquals(0, location.getLineNumber());
assertEquals(0, location.getEndLineNumber());
location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(elements.get(1));
assertEquals(modelAsString.lastIndexOf("y"), location.getOffset());
assertEquals(1, location.getLength());
assertEquals(0, location.getLineNumber());
assertEquals(0, location.getEndLineNumber());
}
use of org.eclipse.xtext.util.ITextRegionWithLineInformation in project xtext-core by eclipse.
the class LocationInFileProviderTest method testContainmentRefSignificantLocation.
@Test
public void testContainmentRefSignificantLocation() throws Exception {
assertEquals(2, elements.size());
ITextRegionWithLineInformation location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(model, LocationprovidertestPackage.Literals.MODEL__ELEMENTS, 0);
assertEquals(modelAsString.indexOf("x"), location.getOffset());
assertEquals(1, location.getLength());
assertEquals(0, location.getLineNumber());
assertEquals(0, location.getEndLineNumber());
location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(model, LocationprovidertestPackage.Literals.MODEL__ELEMENTS, 1);
assertEquals(modelAsString.lastIndexOf("y"), location.getOffset());
assertEquals(1, location.getLength());
assertEquals(0, location.getLineNumber());
assertEquals(0, location.getEndLineNumber());
// multi feature index out of bounds -> return owner's significant region
location = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(model, LocationprovidertestPackage.Literals.MODEL__ELEMENTS, 2);
assertEquals(0, location.getOffset());
assertEquals(modelAsString.length(), location.getLength());
assertEquals(0, location.getLineNumber());
assertEquals(10, location.getEndLineNumber());
}
use of org.eclipse.xtext.util.ITextRegionWithLineInformation in project xtext-core by eclipse.
the class LocationInFileProviderTest method testAttributeFullLocation.
@Test
public void testAttributeFullLocation() {
assertEquals(2, elements.size());
ITextRegionWithLineInformation location = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(elements.get(0), LocationprovidertestPackage.Literals.ELEMENT__NAME, 0);
assertEquals(modelAsString.indexOf("x"), location.getOffset());
assertEquals(1, location.getLength());
assertEquals(0, location.getLineNumber());
assertEquals(0, location.getEndLineNumber());
// single feature index out of bounds -> ignore index
location = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(elements.get(1), LocationprovidertestPackage.Literals.ELEMENT__NAME, 1);
assertEquals(modelAsString.lastIndexOf("y"), location.getOffset());
assertEquals("y".length(), location.getLength());
assertEquals(0, location.getLineNumber());
assertEquals(0, location.getEndLineNumber());
}
use of org.eclipse.xtext.util.ITextRegionWithLineInformation in project xtext-core by eclipse.
the class LocationInFileProviderTest method testCrossRefFullLocation.
@Test
public void testCrossRefFullLocation() throws Exception {
assertEquals(2, elements.size());
int indexOfFirstY = modelAsString.indexOf("y");
int indexOfSecondY = modelAsString.indexOf("y", indexOfFirstY + 1);
ITextRegionWithLineInformation location = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(elements.get(0), LocationprovidertestPackage.Literals.ELEMENT__SINGLEREF, 0);
assertEquals(indexOfFirstY, location.getOffset());
assertEquals(1, location.getLength());
assertEquals(0, location.getLineNumber());
assertEquals(0, location.getEndLineNumber());
// single feature index out of bounds -> ignore index
location = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(elements.get(0), LocationprovidertestPackage.Literals.ELEMENT__SINGLEREF, 1);
assertEquals(indexOfFirstY, location.getOffset());
assertEquals(1, location.getLength());
assertEquals(0, location.getLineNumber());
assertEquals(0, location.getEndLineNumber());
location = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(elements.get(0), LocationprovidertestPackage.Literals.ELEMENT__MULTIREFS, 0);
assertEquals(indexOfSecondY, location.getOffset());
assertEquals(1, location.getLength());
assertEquals(0, location.getLineNumber());
assertEquals(0, location.getEndLineNumber());
// multi feature index out of bounds -> return owner's full region
location = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(elements.get(0), LocationprovidertestPackage.Literals.ELEMENT__MULTIREFS, 1);
assertEquals(0, location.getOffset());
assertEquals(modelAsString.indexOf(" element y"), location.getLength());
assertEquals(0, location.getLineNumber());
assertEquals(0, location.getEndLineNumber());
}
Aggregations