Search in sources :

Example 21 with ITextRegion

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

the class TokenRegionProviderTest 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 22 with ITextRegion

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

the class TokenRegionProviderTest method testTokenSplit.

@Test
public void testTokenSplit() throws Exception {
    String model = " a b ";
    ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(2, 1));
    assertEquals(2, tokenRegion.getOffset());
    assertEquals(1, 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 23 with ITextRegion

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

the class TokenRegionProviderTest method testTokenRegionContainsRegion.

@Test
public void testTokenRegionContainsRegion() throws Exception {
    String modelAsString = "a1 / /* comment */ b2";
    List<CommonToken> tokens = getTokens(modelAsString);
    for (int length = 0; length < modelAsString.length(); ++length) {
        for (int offset = 0; offset + length < modelAsString.length(); ++offset) {
            ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(modelAsString, new TextRegion(offset, length));
            // System.out.println(offset + ":" + length + " -> " + tokenRegion);
            CommonToken firstToken = findTokenStartingAt(tokenRegion.getOffset(), tokens);
            assertTrue(firstToken.getStartIndex() <= offset);
            if (tokenRegion.getLength() != 0) {
                CommonToken lastToken = findTokenStopingAt(tokenRegion.getOffset() + tokenRegion.getLength() - 1, tokens);
                assertTrue(lastToken.getStopIndex() >= offset + length - 1);
            }
        }
    }
}
Also used : TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) CommonToken(org.antlr.runtime.CommonToken) Test(org.junit.Test)

Example 24 with ITextRegion

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

the class TokenRegionProviderTest 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 25 with ITextRegion

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

the class TokenRegionProviderTest method testTokenMerge.

@Test
public void testTokenMerge() throws Exception {
    String model = "  ";
    ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(1, 0));
    assertEquals(0, 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)

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