Search in sources :

Example 16 with FoldedPosition

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

the class DefaultFoldingRegionProviderTest method testSignificantPartOfModel_01.

@Test
public void testSignificantPartOfModel_01() throws Exception {
    IFile iFile = createFile("foo/bar.foldingtestlanguage", "\n" + "element foo\n" + "end\n");
    IXtextDocument document = openFileAndReturnDocument(iFile);
    DefaultFoldingRegionProvider reg = createFoldingRegionProvider();
    Collection<FoldedPosition> regions = reg.getFoldingRegions(document);
    assertEquals(1, regions.size());
    FoldedPosition position = Iterables.getOnlyElement(regions);
    assertEquals("\n".length(), position.getOffset());
    assertEquals("element foo\nend\n".length(), position.getLength());
    assertEquals("element ".length(), position.computeCaptionOffset(document));
    IRegion[] projectionRegions = position.computeProjectionRegions(document);
    assertEquals(1, projectionRegions.length);
    assertEquals("\nelement foo\n".length(), projectionRegions[0].getOffset());
    assertEquals("end\n".length(), projectionRegions[0].getLength());
}
Also used : IFile(org.eclipse.core.resources.IFile) DefaultFoldingRegionProvider(org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider) FoldedPosition(org.eclipse.xtext.ui.editor.folding.FoldedPosition) IRegion(org.eclipse.jface.text.IRegion) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Example 17 with FoldedPosition

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

the class XtendFoldingRegionProviderTest method testNoFoldingIfOnlyOneImport.

@Test
public void testNoFoldingIfOnlyOneImport() throws Exception {
    String content = "package test\nimport java.util.List\nclass Bar{}";
    IFile iFile = testHelper.createFile("test/Bar", content);
    Collection<FoldedPosition> foldingRegions = foldingRegionProvider.getFoldingRegions(openFileAndReturnDocument(iFile));
    assertTrue(foldingRegions.isEmpty());
}
Also used : IFile(org.eclipse.core.resources.IFile) FoldedPosition(org.eclipse.xtext.ui.editor.folding.FoldedPosition) DefaultFoldedPosition(org.eclipse.xtext.ui.editor.folding.DefaultFoldedPosition) Test(org.junit.Test)

Example 18 with FoldedPosition

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

the class XtendFoldingRegionProviderTest method testFoldingOfMoreThanOneImports.

@Test
public void testFoldingOfMoreThanOneImports() throws Exception {
    String content = "package test\nimport java.util.List\nimport java.util.Set\nclass Bar{}";
    Collection<FoldedPosition> foldingRegions = calculateFoldingRegions("test/Bar", content);
    assertEquals(1, foldingRegions.size());
    FoldedPosition first = foldingRegions.iterator().next();
    assertEquals(13, first.getOffset());
    assertEquals(43, first.length);
}
Also used : FoldedPosition(org.eclipse.xtext.ui.editor.folding.FoldedPosition) DefaultFoldedPosition(org.eclipse.xtext.ui.editor.folding.DefaultFoldedPosition) Test(org.junit.Test)

Example 19 with FoldedPosition

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

the class XtendFoldingRegionProviderTest method testFoldCopyrightHeader2.

@Test
public void testFoldCopyrightHeader2() throws Exception {
    String content = "package test\n/**\n * \n * Hello Copyright\n * \n */\nimport java.util.List\nimport java.util.Set\nclass Bar{}";
    Collection<FoldedPosition> foldingRegions = calculateFoldingRegions("test/Bar", content);
    assertEquals(2, foldingRegions.size());
    Iterator<FoldedPosition> iterator = foldingRegions.iterator();
    FoldedPosition first = iterator.next();
    assertEquals(48, first.getOffset());
    assertEquals(43, first.length);
    assertTrue(((DefaultFoldedPosition) first).isInitiallyFolded());
    FoldedPosition second = iterator.next();
    assertEquals(13, second.getOffset());
    assertEquals(35, second.length);
    assertFalse(((DefaultFoldedPosition) second).isInitiallyFolded());
}
Also used : FoldedPosition(org.eclipse.xtext.ui.editor.folding.FoldedPosition) DefaultFoldedPosition(org.eclipse.xtext.ui.editor.folding.DefaultFoldedPosition) Test(org.junit.Test)

Example 20 with FoldedPosition

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

the class XtendFoldingRegionProviderTest method testFoldClosure_02.

@Test
public void testFoldClosure_02() throws Exception {
    String content = "class Foo {\n" + "  def void xxx() {\n" + "    #[1,2,3].filter [ i % 2 == 0 ]\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(71, next.length);
    next = iterator.next();
    assertEquals(12, next.offset);
    assertEquals(58, next.length);
}
Also used : FoldedPosition(org.eclipse.xtext.ui.editor.folding.FoldedPosition) DefaultFoldedPosition(org.eclipse.xtext.ui.editor.folding.DefaultFoldedPosition) Test(org.junit.Test)

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