Search in sources :

Example 1 with DefaultLocationInFileProvider

use of org.eclipse.xtext.resource.DefaultLocationInFileProvider in project xtext-eclipse by eclipse.

the class DefaultFoldingRegionProviderTest method testShouldProcessContent.

@SuppressWarnings("deprecation")
@Test
public void testShouldProcessContent() throws Exception {
    IFile iFile = createFile("foo/bar.foldingtestlanguage", "element foo \n" + "element bar \n" + "end \n" + "end");
    IXtextDocument document = openFileAndReturnDocument(iFile);
    DefaultFoldingRegionProvider reg = new DefaultFoldingRegionProvider(new DefaultLocationInFileProvider()) {

        @Override
        protected boolean shouldProcessContent(EObject object) {
            if (object instanceof Element) {
                return !"foo".equals(((Element) object).getName());
            }
            return super.shouldProcessContent(object);
        }
    };
    Collection<FoldedPosition> regions = reg.getFoldingRegions(document);
    assertEquals(1, regions.size());
    assertEquals(0, regions.iterator().next().getOffset());
}
Also used : DefaultLocationInFileProvider(org.eclipse.xtext.resource.DefaultLocationInFileProvider) IFile(org.eclipse.core.resources.IFile) DefaultFoldingRegionProvider(org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider) EObject(org.eclipse.emf.ecore.EObject) Element(org.eclipse.xtext.ui.tests.folding.Element) FoldedPosition(org.eclipse.xtext.ui.editor.folding.FoldedPosition) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Example 2 with DefaultLocationInFileProvider

use of org.eclipse.xtext.resource.DefaultLocationInFileProvider in project xtext-eclipse by eclipse.

the class OutlineTreeProviderTest method testNoNames.

@Test
public void testNoNames() throws Exception {
    final DefaultOutlineTreeProvider noNamesTreeProvider = new DefaultOutlineTreeProvider(new DefaultEObjectLabelProvider(), new DefaultLocationInFileProvider()) {

        @Override
        protected Object _text(Object modelElement) {
            return null;
        }
    };
    final String modelAsText = "element1 { element11 {}} element2 {}";
    IXtextDocument document = createXtextDocument(modelAsText);
    final IOutlineNode rootNode = noNamesTreeProvider.createRoot(document);
    document.readOnly(new IUnitOfWork.Void<XtextResource>() {

        @Override
        public void process(XtextResource state) throws Exception {
            noNamesTreeProvider.createChildren(rootNode, state.getContents().get(0));
            assertEquals(1, rootNode.getChildren().size());
            IOutlineNode modelNode = rootNode.getChildren().get(0);
            assertEquals(state.getURI().trimFileExtension().lastSegment(), modelNode.getText());
            assertTrue(modelNode.hasChildren());
            assertEquals(1, modelNode.getChildren().size());
            IOutlineNode element1 = modelNode.getChildren().get(0);
            assertEquals("<unnamed>", element1.getText().toString());
            assertEquals(new TextRegion(0, 8), element1.getSignificantTextRegion());
            assertEquals(new TextRegion(0, 24), element1.getFullTextRegion());
            assertEquals(modelNode, element1.getParent());
            // node does not know that its children will be skipped
            assertTrue(element1.hasChildren());
            assertTrue(element1.getChildren().isEmpty());
        }
    });
}
Also used : DefaultLocationInFileProvider(org.eclipse.xtext.resource.DefaultLocationInFileProvider) DefaultEObjectLabelProvider(org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider) TextRegion(org.eclipse.xtext.util.TextRegion) XtextResource(org.eclipse.xtext.resource.XtextResource) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) DefaultOutlineTreeProvider(org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider) IOutlineNode(org.eclipse.xtext.ui.editor.outline.IOutlineNode) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test)

Example 3 with DefaultLocationInFileProvider

use of org.eclipse.xtext.resource.DefaultLocationInFileProvider in project xtext-eclipse by eclipse.

the class OutlineTreeProviderTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    final Injector injector = TestsActivator.getInstance().getInjector("org.eclipse.xtext.ui.tests.editor.outline.OutlineTestLanguage");
    with(new ISetup() {

        @Override
        public Injector createInjectorAndDoEMFRegistration() {
            return injector;
        }
    });
    treeProvider = new DefaultOutlineTreeProvider(new DefaultEObjectLabelProvider(), new DefaultLocationInFileProvider());
}
Also used : DefaultLocationInFileProvider(org.eclipse.xtext.resource.DefaultLocationInFileProvider) DefaultEObjectLabelProvider(org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider) Injector(com.google.inject.Injector) DefaultOutlineTreeProvider(org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider) ISetup(org.eclipse.xtext.ISetup)

Example 4 with DefaultLocationInFileProvider

use of org.eclipse.xtext.resource.DefaultLocationInFileProvider in project xtext-eclipse by eclipse.

the class DefaultFoldingRegionProviderTest method testIsHandled.

@SuppressWarnings("deprecation")
@Test
public void testIsHandled() throws Exception {
    IFile iFile = createFile("foo/bar.foldingtestlanguage", "element foo \n" + "element bar \n" + "end \n" + "end");
    IXtextDocument document = openFileAndReturnDocument(iFile);
    DefaultFoldingRegionProvider reg = new DefaultFoldingRegionProvider(new DefaultLocationInFileProvider()) {

        @Override
        protected boolean isHandled(EObject object) {
            if (object instanceof Element) {
                return !"foo".equals(((Element) object).getName());
            }
            return super.isHandled(object);
        }
    };
    Collection<FoldedPosition> regions = reg.getFoldingRegions(document);
    assertEquals(1, regions.size());
    assertEquals("element foo \n".length(), regions.iterator().next().getOffset());
}
Also used : DefaultLocationInFileProvider(org.eclipse.xtext.resource.DefaultLocationInFileProvider) IFile(org.eclipse.core.resources.IFile) DefaultFoldingRegionProvider(org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider) EObject(org.eclipse.emf.ecore.EObject) Element(org.eclipse.xtext.ui.tests.folding.Element) FoldedPosition(org.eclipse.xtext.ui.editor.folding.FoldedPosition) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Aggregations

DefaultLocationInFileProvider (org.eclipse.xtext.resource.DefaultLocationInFileProvider)4 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)3 Test (org.junit.Test)3 IFile (org.eclipse.core.resources.IFile)2 EObject (org.eclipse.emf.ecore.EObject)2 DefaultFoldingRegionProvider (org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider)2 FoldedPosition (org.eclipse.xtext.ui.editor.folding.FoldedPosition)2 DefaultOutlineTreeProvider (org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider)2 DefaultEObjectLabelProvider (org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider)2 AbstractEditorTest (org.eclipse.xtext.ui.testing.AbstractEditorTest)2 Element (org.eclipse.xtext.ui.tests.folding.Element)2 Injector (com.google.inject.Injector)1 ISetup (org.eclipse.xtext.ISetup)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 IOutlineNode (org.eclipse.xtext.ui.editor.outline.IOutlineNode)1 TextRegion (org.eclipse.xtext.util.TextRegion)1 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)1