Software folding in Eclipse

I am looking for a (clean) way to programmatically fold / expand methods (or a slightly lower level: line spacing) in a JDT editor in Eclipse.

I already read the documentation about the basic concept of folding (basic documents, projection documents), but the documentation has not helped me yet.

The alternative that I came across is the so-called SWTBot, which can be used to "emulate" a click on the "fold / unlold" button of the editor, but at present I find this an ugly hack.

Has anyone ever done something similar or had a key / example?

+4
source share
1 answer

I have not tried, but looked at JavaEditor.class in JDT. I saw the following code:

IJavaElement[] elements = ....; IJavaFoldingStructureProviderExtension extension= (IJavaFoldingStructureProviderExtension) JavaPlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider(); extension.collapseElements(elements); extension.expandElements(elements); 

Please let me know if this works.

0
source

Source: https://habr.com/ru/post/1437747/


All Articles