use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class TracingSugar method location.
/**
* @param obj the EObject containing the feature
* @param feature the EStructuralFeature to trace
* @param idx the index of the value to trace, in case the feature contains a list, should be <code>-1</code> otherwise.
*
* @return ILocationData covering the <code>fullTextRegion</code> of the given feature in the given EObject.
*/
public ILocationData location(final EObject obj, final EStructuralFeature feature, final int idx) {
final ITextRegion region = this.locationProvider.getFullTextRegion(obj, feature, idx);
final SourceRelativeURI uri = this.traceURIConverter.getURIForTrace(obj.eResource());
return new LocationData(((ITextRegionWithLineInformation) region), uri);
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class AbstractFormatter2 method isInRequestedRange.
protected boolean isInRequestedRange(EObject obj) {
Collection<ITextRegion> regions = request.getRegions();
if (regions.isEmpty())
return true;
ITextRegionAccess access = request.getTextRegionAccess();
IEObjectRegion objRegion = access.regionForEObject(obj);
if (objRegion == null)
return false;
IHiddenRegion previousHidden = objRegion.getPreviousHiddenRegion();
IHiddenRegion nextHidden = objRegion.getNextHiddenRegion();
int objOffset = previousHidden != null ? previousHidden.getOffset() : 0;
int objEnd = nextHidden != null ? nextHidden.getEndOffset() : access.regionForRootEObject().getEndOffset();
for (ITextRegion region : regions) {
int regionOffset = region.getOffset();
int regionEnd = regionOffset + region.getLength();
if (regionOffset <= objEnd && regionEnd >= objOffset)
return true;
}
return false;
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class FormattableDocumentTest method shouldFormat.
@Test
public void shouldFormat() {
final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
Collection<ITextRegion> _regions = it.getRequest().getRegions();
TextRegion _textRegion = new TextRegion(0, 6);
_regions.add(_textRegion);
StringConcatenation _builder = new StringConcatenation();
_builder.append("idlist");
it.setToBeFormatted(_builder);
it.setFormatter(new GenericFormatter() {
@Override
protected void format(final EObject model, final ITextRegionExtensions regionAccess, final IFormattableDocument document) {
throw new IllegalStateException("this method should never be called");
}
@Override
public boolean shouldFormat(final Object obj, final IFormattableDocument document) {
return false;
}
});
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("idlist");
it.setExpectation(_builder_1);
};
this._genericFormatterTester.assertFormatted(_function);
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class TokenRegionProviderTest method testBug486454.
@Test
public void testBug486454() throws Exception {
String model = "t";
ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(1, 0));
assertEquals(0, tokenRegion.getOffset());
assertEquals(1, tokenRegion.getLength());
}
Aggregations