Search in sources :

Example 36 with ITextRegion

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);
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion)

Example 37 with ITextRegion

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);
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) Region(org.eclipse.jface.text.Region) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion)

Example 38 with ITextRegion

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);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) IPreferenceValues(org.eclipse.xtext.preferences.IPreferenceValues) ITextRegion(org.eclipse.xtext.util.ITextRegion)

Example 39 with ITextRegion

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()));
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) ITextRegion(org.eclipse.xtext.util.ITextRegion) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 40 with ITextRegion

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()));
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) ITextRegion(org.eclipse.xtext.util.ITextRegion) XExpression(org.eclipse.xtext.xbase.XExpression)

Aggregations

ITextRegion (org.eclipse.xtext.util.ITextRegion)122 TextRegion (org.eclipse.xtext.util.TextRegion)44 EObject (org.eclipse.emf.ecore.EObject)33 Test (org.junit.Test)20 INode (org.eclipse.xtext.nodemodel.INode)19 XtextResource (org.eclipse.xtext.resource.XtextResource)17 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)15 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)15 BadLocationException (org.eclipse.jface.text.BadLocationException)11 Region (org.eclipse.jface.text.Region)9 XExpression (org.eclipse.xtext.xbase.XExpression)9 IOException (java.io.IOException)8 CoreException (org.eclipse.core.runtime.CoreException)8 IParseResult (org.eclipse.xtext.parser.IParseResult)7 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)7 IRegion (org.eclipse.jface.text.IRegion)6 ITextSelection (org.eclipse.jface.text.ITextSelection)6 Collection (java.util.Collection)5 ArrayList (java.util.ArrayList)4 TextSelection (org.eclipse.jface.text.TextSelection)4