use of org.eclipse.xtext.ui.editor.folding.FoldedPosition in project xtext-xtend by eclipse.
the class XtendFoldingRegionProviderTest method testFoldListLiteral_02.
@Test
public void testFoldListLiteral_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);
}
use of org.eclipse.xtext.ui.editor.folding.FoldedPosition in project xtext-xtend by eclipse.
the class XtendFoldingRegionProviderTest method testFoldCopyrightHeader.
@Test
public void testFoldCopyrightHeader() throws Exception {
String content = "/**\n * \n * Hello Copyright\n * \n */\npackage test\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(0, second.getOffset());
assertEquals(35, second.length);
assertTrue(((DefaultFoldedPosition) second).isInitiallyFolded());
}
use of org.eclipse.xtext.ui.editor.folding.FoldedPosition in project xtext-eclipse by eclipse.
the class DefaultFoldingRegionProviderTest method testSignificantPartOfMlComment_03.
@Test
public void testSignificantPartOfMlComment_03() throws Exception {
IFile iFile = createFile("foo/bar.foldingtestlanguage", "\n/**\n *\n * foo\n *\n */\n element foo end");
IXtextDocument document = openFileAndReturnDocument(iFile);
DefaultFoldingRegionProvider reg = createFoldingRegionProvider();
Collection<FoldedPosition> regions = reg.getFoldingRegions(document);
assertEquals(1, regions.size());
FoldedPosition position = Iterables.getOnlyElement(regions);
assertEquals(1, position.getOffset());
assertEquals("/**\n *\n * foo\n *\n */\n".length(), position.getLength());
assertEquals("/**\n *\n * ".length(), position.computeCaptionOffset(document));
IRegion[] projectionRegions = position.computeProjectionRegions(document);
assertEquals(2, projectionRegions.length);
assertEquals("\n".length(), projectionRegions[0].getOffset());
assertEquals("/**\n *\n".length(), projectionRegions[0].getLength());
assertEquals("\n/**\n *\n * foo\n".length(), projectionRegions[1].getOffset());
assertEquals(" *\n */\n".length(), projectionRegions[1].getLength());
}
use of org.eclipse.xtext.ui.editor.folding.FoldedPosition 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());
}
use of org.eclipse.xtext.ui.editor.folding.FoldedPosition in project xtext-eclipse by eclipse.
the class DefaultFoldingRegionProviderTest method testGetFoldingRegions2.
@Test
public void testGetFoldingRegions2() throws Exception {
IFile iFile = createFile("foo/bar.foldingtestlanguage", "element foo \nelement bar \nend \nelement baz end end");
IXtextDocument document = openFileAndReturnDocument(iFile);
DefaultFoldingRegionProvider reg = createFoldingRegionProvider();
Collection<FoldedPosition> regions = reg.getFoldingRegions(document);
assertEquals(2, regions.size());
}
Aggregations