Search in sources :

Example 81 with ITextRegion

use of org.eclipse.xtext.util.ITextRegion 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(EObject obj) {
    ITextRegion region = locationProvider.getFullTextRegion(obj);
    SourceRelativeURI uri = traceURIConverter.getURIForTrace(obj.eResource());
    return new LocationData((ITextRegionWithLineInformation) region, uri);
}
Also used : LocationData(org.eclipse.xtext.generator.trace.LocationData) ILocationData(org.eclipse.xtext.generator.trace.ILocationData) ITextRegion(org.eclipse.xtext.util.ITextRegion) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Example 82 with ITextRegion

use of org.eclipse.xtext.util.ITextRegion in project xtext-xtend by eclipse.

the class FlexTokenRegionProviderTest method testTokenSplit_1.

@Test
public void testTokenSplit_1() throws Exception {
    String model = " axb ";
    ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(2, 1));
    assertEquals(1, tokenRegion.getOffset());
    assertEquals(3, tokenRegion.getLength());
}
Also used : TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) Test(org.junit.Test)

Example 83 with ITextRegion

use of org.eclipse.xtext.util.ITextRegion in project xtext-xtend by eclipse.

the class FlexTokenRegionProviderTest method testTokenMerge_1.

@Test
public void testTokenMerge_1() throws Exception {
    String model = " ab ";
    ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(2, 0));
    assertEquals(1, tokenRegion.getOffset());
    assertEquals(2, tokenRegion.getLength());
}
Also used : TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) Test(org.junit.Test)

Example 84 with ITextRegion

use of org.eclipse.xtext.util.ITextRegion in project xtext-xtend by eclipse.

the class XtendFoldingRegionProvider method computeImportFolding.

protected void computeImportFolding(XtendFile xtendFile, IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor) {
    if (xtendFile.getImportSection() != null && xtendFile.getImportSection().getImportDeclarations().size() > 1) {
        ICompositeNode node = NodeModelUtils.findActualNodeFor(xtendFile.getImportSection());
        if (node != null) {
            ITextRegion textRegion = node.getTextRegion();
            ((IFoldingRegionAcceptorExtension<ITextRegion>) foldingRegionAcceptor).accept(textRegion.getOffset(), textRegion.getLength(), foldingPreferences.isFoldImports());
        }
    }
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) IFoldingRegionAcceptorExtension(org.eclipse.xtext.ui.editor.folding.IFoldingRegionAcceptorExtension) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 85 with ITextRegion

use of org.eclipse.xtext.util.ITextRegion in project xtext-xtend by eclipse.

the class XtendHighlightingCalculator method highlightSpecialIdentifiers.

@Override
protected void highlightSpecialIdentifiers(ILeafNode leafNode, IHighlightedPositionAcceptor acceptor, TerminalRule idRule) {
    super.highlightSpecialIdentifiers(leafNode, acceptor, idRule);
    if (contextualKeywords != null && contextualKeywords.contains(leafNode.getGrammarElement())) {
        ITextRegion leafRegion = leafNode.getTextRegion();
        acceptor.addPosition(leafRegion.getOffset(), leafRegion.getLength(), HighlightingStyles.DEFAULT_ID);
    }
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion)

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