Search in sources :

Example 6 with FoldedPosition

use of org.eclipse.xtext.ui.editor.folding.FoldedPosition in project xtext-xtend by eclipse.

the class XtendFoldingRegionProviderTest method testFoldSetLiteral_02.

@Test
public void testFoldSetLiteral_02() throws Exception {
    String content = "class Foo {\n" + "  def xxx() {\n" + "    #{1,2}\n" + "  }\n" + "}";
    Collection<FoldedPosition> foldingRegions = calculateFoldingRegions("test/Foo", content);
    assertEquals(2, foldingRegions.size());
    Iterator<FoldedPosition> iterator = foldingRegions.iterator();
    FoldedPosition next = iterator.next();
    assertEquals(0, next.offset);
    assertEquals(42, next.length);
    next = iterator.next();
    assertEquals(12, next.offset);
    assertEquals(29, next.length);
}
Also used : FoldedPosition(org.eclipse.xtext.ui.editor.folding.FoldedPosition) DefaultFoldedPosition(org.eclipse.xtext.ui.editor.folding.DefaultFoldedPosition) Test(org.junit.Test)

Example 7 with FoldedPosition

use of org.eclipse.xtext.ui.editor.folding.FoldedPosition in project xtext-xtend by eclipse.

the class XtendFoldingRegionProviderTest method testFoldAnonymousClass.

@Test
public void testFoldAnonymousClass() throws Exception {
    String content = "class Foo {\n" + " val foo = new Runnable() {\n" + "   override run() {\n" + "   }\n" + " }\n" + "}";
    Collection<FoldedPosition> foldingRegions = calculateFoldingRegions("test/Bar", content);
    assertEquals(3, foldingRegions.size());
    Iterator<FoldedPosition> iterator = foldingRegions.iterator();
    FoldedPosition next = iterator.next();
    assertEquals(0, next.offset);
    assertEquals(69, next.length);
    next = iterator.next();
    assertEquals(12, next.offset);
    assertEquals(56, next.length);
    next = iterator.next();
    assertEquals(40, next.offset);
    assertEquals(25, next.length);
}
Also used : FoldedPosition(org.eclipse.xtext.ui.editor.folding.FoldedPosition) DefaultFoldedPosition(org.eclipse.xtext.ui.editor.folding.DefaultFoldedPosition) Test(org.junit.Test)

Example 8 with FoldedPosition

use of org.eclipse.xtext.ui.editor.folding.FoldedPosition in project xtext-eclipse by eclipse.

the class AbstractFoldingTest method insertFoldingRegionMarkers.

protected String insertFoldingRegionMarkers(IXtextDocument document, String lineSeparator) {
    List<String> lines = Arrays.asList(document.get().split(lineSeparator));
    try {
        for (FoldedPosition foldingRegion : foldingRegionProvider.getFoldingRegions(document)) {
            // Insert the beginning folding region marker at the beginning of the corresponding line
            int startLine = document.getLineOfOffset(foldingRegion.offset);
            lines.set(startLine, b() + lines.get(startLine));
            // Insert the end folding region marker at the end of the corresponding line
            int endLine = document.getLineOfOffset(foldingRegion.offset + foldingRegion.length) - 1;
            lines.set(endLine, lines.get(endLine) + e());
        }
    } catch (BadLocationException e) {
        throw new RuntimeException(e);
    }
    return Joiner.on(lineSeparator).join(lines);
}
Also used : FoldedPosition(org.eclipse.xtext.ui.editor.folding.FoldedPosition) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 9 with FoldedPosition

use of org.eclipse.xtext.ui.editor.folding.FoldedPosition 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 10 with FoldedPosition

use of org.eclipse.xtext.ui.editor.folding.FoldedPosition in project xtext-eclipse by eclipse.

the class DefaultFoldingRegionProviderTest method testGetFoldingRegionsWithMlCommentStart.

@Test
public void testGetFoldingRegionsWithMlCommentStart() throws Exception {
    IFile iFile = createFile("foo/bar.foldingtestlanguage", "/**\n*/\n element foo \nelement bar end \nelement baz end end");
    IXtextDocument document = openFileAndReturnDocument(iFile);
    DefaultFoldingRegionProvider reg = createFoldingRegionProvider();
    Collection<FoldedPosition> regions = reg.getFoldingRegions(document);
    assertEquals(2, regions.size());
}
Also used : IFile(org.eclipse.core.resources.IFile) DefaultFoldingRegionProvider(org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider) 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

FoldedPosition (org.eclipse.xtext.ui.editor.folding.FoldedPosition)32 Test (org.junit.Test)31 IFile (org.eclipse.core.resources.IFile)19 DefaultFoldingRegionProvider (org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider)18 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)18 AbstractEditorTest (org.eclipse.xtext.ui.testing.AbstractEditorTest)18 DefaultFoldedPosition (org.eclipse.xtext.ui.editor.folding.DefaultFoldedPosition)13 IRegion (org.eclipse.jface.text.IRegion)7 EObject (org.eclipse.emf.ecore.EObject)2 DefaultLocationInFileProvider (org.eclipse.xtext.resource.DefaultLocationInFileProvider)2 Element (org.eclipse.xtext.ui.tests.folding.Element)2 BadLocationException (org.eclipse.jface.text.BadLocationException)1