use of org.eclipse.xtext.util.ITextRegionWithLineInformation in project xtext-core by eclipse.
the class LocationInFileProviderTest method testBug353969_02.
@Test
public void testBug353969_02() throws Exception {
Processor p = (Processor) model.getComponents().get(0);
EList<Mode> modes = p.getMode();
assertEquals(2, modes.size());
Mode m2 = modes.get(1);
ITextRegionWithLineInformation m2FullRegion = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(m2);
assertEquals(modelAsString.indexOf("mode m2;"), m2FullRegion.getOffset());
assertEquals("mode m2;".length(), m2FullRegion.getLength());
assertEquals(4, m2FullRegion.getLineNumber());
assertEquals(4, m2FullRegion.getEndLineNumber());
ITextRegionWithLineInformation m2SignificantRegion = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(m2);
assertEquals(modelAsString.indexOf("m2;"), m2SignificantRegion.getOffset());
assertEquals("m2".length(), m2SignificantRegion.getLength());
assertEquals(4, m2SignificantRegion.getLineNumber());
assertEquals(4, m2SignificantRegion.getEndLineNumber());
}
use of org.eclipse.xtext.util.ITextRegionWithLineInformation 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.ITextRegionWithLineInformation 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);
}
use of org.eclipse.xtext.util.ITextRegionWithLineInformation in project xtext-core by eclipse.
the class CharSequenceTraceWrapper method wrapWithTraceData.
public CharSequence wrapWithTraceData(CharSequence sequence, EObject origin) {
ITextRegionWithLineInformation location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(origin);
AbsoluteURI absoluteURI = new AbsoluteURI(origin.eResource().getURI());
IProjectConfig projectConfig = projectConfigProvider.getProjectConfig(EcoreUtil2.getResourceSet(origin));
SourceRelativeURI sourceRelativeURI = absoluteURI.deresolve(projectConfig);
return wrapWithTraceData(sequence, sourceRelativeURI, location.getOffset(), location.getLength(), location.getLineNumber(), location.getEndLineNumber());
}
use of org.eclipse.xtext.util.ITextRegionWithLineInformation in project xtext-core by eclipse.
the class TracingSugar method location.
/**
* @return ILocationData covering the <code>fullTextRegion</code> of the given EObject.
*/
public ILocationData location(final EObject obj) {
final ITextRegion region = this.locationProvider.getFullTextRegion(obj);
final SourceRelativeURI uri = this.traceURIConverter.getURIForTrace(obj.eResource());
return new LocationData(((ITextRegionWithLineInformation) region), uri);
}
Aggregations