Search in sources :

Example 1 with AstSelectionProvider

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

the class AstSelectionProviderTest method testBug515055_1.

@Test
public void testBug515055_1() throws Exception {
    XtextResource res = getResource(getAsStream("    "));
    AstSelectionProvider provider = get(AstSelectionProvider.class);
    final TextRegion currentEditorSelection = new TextRegion(2, 0);
    assertEquals(ITextRegion.EMPTY_REGION, provider.selectEnclosing(res, currentEditorSelection));
    assertEquals(ITextRegion.EMPTY_REGION, provider.selectEnclosing(res, currentEditorSelection));
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) TextRegion(org.eclipse.xtext.util.TextRegion) AstSelectionProvider(org.eclipse.xtext.ui.editor.selection.AstSelectionProvider) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 2 with AstSelectionProvider

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

the class AstSelectionProviderTest method testBug515055_2.

@Test
public void testBug515055_2() throws Exception {
    XtextResource res = getResource(getAsStream(""));
    AstSelectionProvider provider = get(AstSelectionProvider.class);
    final TextRegion currentEditorSelection = new TextRegion(0, 0);
    assertEquals(ITextRegion.EMPTY_REGION, provider.selectEnclosing(res, currentEditorSelection));
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) TextRegion(org.eclipse.xtext.util.TextRegion) AstSelectionProvider(org.eclipse.xtext.ui.editor.selection.AstSelectionProvider) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 3 with AstSelectionProvider

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

the class AstSelectionProviderTest method testSelectEnclosing.

@Test
public void testSelectEnclosing() 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.selectEnclosing(res, new TextRegion(indexOfZonk, 0));
    assertEquals(region(all, "zonk"), selection);
    selection = provider.selectEnclosing(res, selection);
    assertEquals(region(all, zonk), selection);
    selection = provider.selectEnclosing(res, selection);
    assertEquals(region(all, baz), selection);
    selection = provider.selectEnclosing(res, selection);
    assertEquals(region(all, all), selection);
    assertEquals(ITextRegion.EMPTY_REGION, provider.selectEnclosing(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)

Example 4 with AstSelectionProvider

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

the class AstSelectionProviderTest method testSelectComments.

@Test
public void testSelectComments() 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");
    final TextRegion currentEditorSelection = new TextRegion(indexOfZonk, 1);
    ITextRegion selection = provider.selectPrevious(res, currentEditorSelection);
    assertEquals(region(all, "zonk"), selection);
    selection = provider.selectEnclosing(res, selection);
    assertEquals(region(all, zonk), selection);
    selection = provider.selectPrevious(res, selection);
    assertEquals(region(all, baz), selection);
    selection = provider.selectPrevious(res, 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));
}
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)

Example 5 with AstSelectionProvider

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

the class AstSelectionProviderTest method testSelectPrevious.

@Test
public void testSelectPrevious() 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.selectPrevious(res, new TextRegion(indexOfZonk, 0));
    assertEquals(region(all, "zonk"), selection);
    selection = provider.selectEnclosing(res, selection);
    assertEquals(region(all, zonk), selection);
    selection = provider.selectPrevious(res, selection);
    assertEquals(region(all, baz), selection);
    selection = provider.selectPrevious(res, 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));
}
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