Search in sources :

Example 6 with AstSelectionProvider

use of org.eclipse.xtext.ui.editor.selection.AstSelectionProvider in project xtext-eclipse by eclipse.

the class AstSelectionProviderTest method testSelectLast.

@Test
public void testSelectLast() throws Exception {
    String zonk = "/* my coment \n*/\nzonk{}";
    String zink = "zink{}";
    String baz = "baz{\n" + zonk + zink + "}";
    String bar = "bar{}";
    String all = "foo(baz){" + bar + baz + "}";
    EObject model = super.getModel(all);
    AstSelectionProvider provider = get(AstSelectionProvider.class);
    final XtextResource res = (XtextResource) model.eResource();
    int indexOfZonk = all.indexOf("zonk");
    Stack<ITextRegion> selections = new Stack<ITextRegion>();
    final TextRegion currentEditorSelection = new TextRegion(indexOfZonk, 1);
    ITextRegion selection = provider.selectPrevious(res, currentEditorSelection);
    selections.push(selection);
    assertEquals(region(all, "zonk"), selection);
    selection = provider.selectEnclosing(res, selection);
    selections.push(selection);
    assertEquals(region(all, zonk), selection);
    selection = provider.selectPrevious(res, selection);
    selections.push(selection);
    assertEquals(region(all, baz), selection);
    selection = provider.selectPrevious(res, selection);
    selections.push(selection);
    assertEquals(region(all, bar + baz), selection);
    selection = provider.selectPrevious(res, selection);
    assertEquals(region(all, all), selection);
    assertEquals(ITextRegion.EMPTY_REGION, provider.selectPrevious(res, selection));
    while (!selections.isEmpty()) {
        ITextRegion previous = selections.pop();
        assertEquals(previous, provider.selectLast(res, selection));
        selection = previous;
    }
    assertEquals(ITextRegion.EMPTY_REGION, provider.selectLast(res, currentEditorSelection));
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) AstSelectionProvider(org.eclipse.xtext.ui.editor.selection.AstSelectionProvider) XtextResource(org.eclipse.xtext.resource.XtextResource) Stack(java.util.Stack) Test(org.junit.Test)

Example 7 with AstSelectionProvider

use of org.eclipse.xtext.ui.editor.selection.AstSelectionProvider in project xtext-eclipse by eclipse.

the class AstSelectionProviderTest method testSelectNext.

@Test
public void testSelectNext() throws Exception {
    String zonk = "zonk{}";
    String zink = "zink{}";
    String baz = "baz{" + zonk + zink + "}";
    String bar = "bar{}";
    String all = "foo(baz){" + bar + baz + "}";
    EObject model = super.getModel(all);
    AstSelectionProvider provider = get(AstSelectionProvider.class);
    final XtextResource res = (XtextResource) model.eResource();
    int indexOfZonk = all.indexOf(zonk);
    ITextRegion selection = provider.selectNext(res, new TextRegion(indexOfZonk, 0));
    assertEquals(region(all, "zonk"), selection);
    selection = provider.selectEnclosing(res, selection);
    assertEquals(region(all, zonk), selection);
    selection = provider.selectNext(res, selection);
    assertEquals(region(all, zonk + zink), selection);
    selection = provider.selectNext(res, selection);
    assertEquals(region(all, baz), selection);
    selection = provider.selectNext(res, selection);
    assertEquals(region(all, all), selection);
    assertEquals(ITextRegion.EMPTY_REGION, provider.selectNext(res, selection));
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) AstSelectionProvider(org.eclipse.xtext.ui.editor.selection.AstSelectionProvider) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

XtextResource (org.eclipse.xtext.resource.XtextResource)7 AstSelectionProvider (org.eclipse.xtext.ui.editor.selection.AstSelectionProvider)7 ITextRegion (org.eclipse.xtext.util.ITextRegion)7 TextRegion (org.eclipse.xtext.util.TextRegion)7 Test (org.junit.Test)7 EObject (org.eclipse.emf.ecore.EObject)5 Stack (java.util.Stack)1