use of org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider in project xtext-eclipse by eclipse.
the class DefaultFoldingRegionProviderTest method testSignificantPartOfModel_02.
@Test
public void testSignificantPartOfModel_02() throws Exception {
IFile iFile = createFile("foo/bar.foldingtestlanguage", "\n" + "element\n" + " 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\n foo\nend\n".length(), position.getLength());
assertEquals("element\n ".length(), position.computeCaptionOffset(document));
IRegion[] projectionRegions = position.computeProjectionRegions(document);
assertEquals(2, projectionRegions.length);
assertEquals("\n".length(), projectionRegions[0].getOffset());
assertEquals("element\n".length(), projectionRegions[0].getLength());
assertEquals("\nelement\n foo\n".length(), projectionRegions[1].getOffset());
assertEquals("end\n".length(), projectionRegions[1].getLength());
}
use of org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider in project xtext-eclipse by eclipse.
the class DefaultFoldingRegionProviderTest method testSignificantPartOfModel_03.
@Test
public void testSignificantPartOfModel_03() throws Exception {
IFile iFile = createFile("foo/bar.foldingtestlanguage", "\n" + "element\n" + " foo 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\n foo end\n".length(), position.getLength());
assertEquals("element\n ".length(), position.computeCaptionOffset(document));
IRegion[] projectionRegions = position.computeProjectionRegions(document);
assertEquals(1, projectionRegions.length);
assertEquals("\n".length(), projectionRegions[0].getOffset());
assertEquals("element\n".length(), projectionRegions[0].getLength());
}
use of org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider 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());
}
use of org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider 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.DefaultFoldingRegionProvider 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());
}
Aggregations