use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class AbstractTraceRegionToString method shouldInclude.
protected boolean shouldInclude(AbstractTraceRegion region, ILocationData location) {
SourceRelativeURI srcRelativePath = location.getSrcRelativePath();
ITextRegion frame = getRemoteFrame(srcRelativePath == null ? region.getAssociatedSrcRelativePath() : srcRelativePath);
return frame == null ? true : frame.contains(location);
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-eclipse by eclipse.
the class HyperlinkHelper method createHyperlinksTo.
/**
* Produces hyperlinks for the given {@code node} which is associated with a cross reference
* that points to the referenced {@code target}.
*
* @see #createHyperlinksTo(XtextResource, Region, EObject, IHyperlinkAcceptor)
*
* @since 2.4
*/
protected void createHyperlinksTo(XtextResource resource, INode node, EObject target, IHyperlinkAcceptor acceptor) {
ITextRegion textRegion = node.getTextRegion();
Region region = new Region(textRegion.getOffset(), textRegion.getLength());
createHyperlinksTo(resource, region, target, acceptor);
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-eclipse by eclipse.
the class ContentFormatter method initRequest.
protected void initRequest(IXtextDocument document, IRegion region, XtextResource resource, FormatterRequest request) {
ITextRegion textRegion = new TextRegion(region.getOffset(), region.getLength());
request.setAllowIdentityEdits(false);
request.setFormatUndefinedHiddenRegionsOnly(false);
request.setRegions(singletonList(textRegion));
ITextRegionAccess tokenAccess = regionBuilder.forNodeModel(resource).create();
IPreferenceValues preferenceValues = preferencesProvider.getPreferenceValues(resource);
request.setPreferences(TypedPreferenceValues.castOrWrap(preferenceValues));
request.setTextRegionAccess(tokenAccess);
if (tokenAccess.hasSyntaxError())
request.setExceptionHandler(ExceptionAcceptor.IGNORING);
else
request.setExceptionHandler(ExceptionAcceptor.LOGGING);
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-eclipse by eclipse.
the class ExpressionUtilTest method assertExpressionSelected.
protected void assertExpressionSelected(String modelWithSelectionMarkup, String expectedSelection) throws Exception {
String cleanedModel = modelWithSelectionMarkup.replaceAll("\\$", "");
XExpression expression = parse(cleanedModel);
int selectionOffset = modelWithSelectionMarkup.indexOf("$");
int selectionLength = modelWithSelectionMarkup.lastIndexOf("$") - selectionOffset - 1;
XExpression selectedExpression = util.findSelectedExpression((XtextResource) expression.eResource(), new TextSelection(selectionOffset, selectionLength));
ITextRegion selectedRegion = locationInFileProvider.getFullTextRegion(selectedExpression);
assertEquals(expectedSelection, cleanedModel.substring(selectedRegion.getOffset(), selectedRegion.getOffset() + selectedRegion.getLength()));
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-eclipse by eclipse.
the class ExpressionUtilTest method assertSiblingExpressionsSelected.
protected void assertSiblingExpressionsSelected(String modelWithSelectionMarkup, String expectedSelection) throws Exception {
String cleanedModel = modelWithSelectionMarkup.replaceAll("\\$", "");
XExpression expression = parse(cleanedModel);
int selectionOffset = modelWithSelectionMarkup.indexOf("$");
int selectionLength = modelWithSelectionMarkup.lastIndexOf("$") - selectionOffset - 1;
List<XExpression> selectedExpressions = util.findSelectedSiblingExpressions((XtextResource) expression.eResource(), new TextSelection(selectionOffset, selectionLength));
List<ITextRegion> regions = ListExtensions.map(selectedExpressions, it -> locationInFileProvider.getFullTextRegion(it));
ITextRegion selectedRegion = IterableExtensions.reduce(regions, (a, b) -> a.merge(b));
assertEquals(expectedSelection, cleanedModel.substring(selectedRegion.getOffset(), selectedRegion.getOffset() + selectedRegion.getLength()));
}
Aggregations