Programmatically folding in Eclipse - eclipse

I'm looking for a (clean) way to programmatically fold/unfold methods (or a bit more lowlevel: an internval of lines) in a JDT-Editor in Eclipse.
I already read documentation about the basic concept of folding (master documents, projection documents), but the documentation didn't help me out so far.
An alternative I ran over is the so-called SWTBot, which could be used to "emulate" a click on the fold/unfold button of the editor, but I currently consider this as an ugly hack.
Has anyone ever did something similar or has a clue/example?

I haven't tried it but looking 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 it works.

Related

Is there a way to disable 'clips' in VS Code?

The clips feature has been around for some versions in VS Code. It automatically tracks what code I wrote (or copied?) and then offers these clips on a popup when starting a similar statement (e.g. a return statement):
However, this feature drives me nuts. There has been no single circumstance where I benefited from it (why would a seasoned programmer repeat parts of his code? Code-reuse, anyone?). However, if I'm typing fast and I'm not careful, I accidentally select it and the whole clip gets pasted.
Is there a way to disable this feature in VS Code? I neither found any corresponding settings in the official docs nor did any search engine point me in the correct direction.
Thanks in advance for your help!

How to completely hide comments in eclipse?

I'm not sure if this is a good place for this question, but I did see a similar question posted here on overflow.
I'm just getting started with Eclipse as an IDE and having difficulty finding a comments toggle. I'd like to completely hide them sometimes. I've seen suggestions that would allow me to collapse entire comment blocks to a single line, but I'd want to hide ALL comments (single lines, blocks, etc) like in visual studio as a comparison. The goal is to gain the screen space to see more actual code simultaneously.
Anyone know of a way, plugin or otherwise?
Thanks!
This might be a bad way of doing it but you could set the syntax highlight for comments to be the same as your background color.

Netbeans IDE Code Snippet Keybinding

I'm not sure if this is possible and if this is the right place to ask, but I'd like to give it a try. I'm currently trying Netbeans IDE, coming from Dreamweaver.
In Dreamweaver I can create Code Snippets and bind a key to them. So for example marking a text and pressing CTRL+B then, surrounds the text with the [strong] tag. Or I created a snippet, when I press SHIFT+CTRL+B it adds a [br /] tag at the position of the cursor.
I could not find a way to do this in Netbeans so far. Does anyone know if this is possilbe, and if, how to achieve this?
There is a Plugin available for that,
Go to Tools->plugins and try out TagMyCode
https://tagmycode.com/
I've been using it for quite some time, there is a library of public snippets and the doc is really helpful.

How to add views to Show In menu for particular file types

I use an older plugin called Veloeclipse for editing Velocity templates in Eclipse. There's been no development on this since 2009, which isn't a problem because it's mainly just for syntax highlighting and format validation. The really annoying thing about it, however, is that when I try to do Show In to view the current Velocity template within my Package Explorer or Project Explorer, the only available option is Properties. That's not really useful. I really need to be able to get to the file in one of the regular explorer views.
So I have sort of two questions:
Is there a way to configure this without having to monkey with any code? A configuration file or something? I've grepped through my Eclipse installation and haven't seen anything, but I'm hoping that there's something I'm missing.
So assuming that the answer to my first question is no, how do I go about modifying the plugin code so that it will show more than the Properties view in the Show In menu? Most of what I found on the plugin development wiki comes from the other direction: how to make your view or perspective appear in the Show In menu.
Any help with this would be hugely appreciated!
Try to check the plugin source code. it might do something different than other editors. What I mean is that the show in menu item that you have there is not the usual extension point but a hard coded context menu option.

Eclipse RCP - Internals of projection (folding) service

I need to make custom text folding as described here: Can I merge Syntax coloring and Folding? OR Projection colored from master document info
I'm digging through code, but its very perplexed... and I cant get access to some classes.
I still haven't found what class decides what to show when ProjectionAnnotation collapsed
I need some info on how folding/projection is implemented, but haven't found any articles.
Please if somebody familiar with Eclipse projection, or knows any articles, help!
The basic goals:
1) make ProjectionAnnotations to show text enclosed in xml tags, instead of first line
2) make ProjectionAnnotations unexpandable(permanently collapsed)
3) remove collapse/expand button (I think I know how to do it, but this decorative and have less priority)
Have a look at the excellent Eclipse corner article, you could also try looking at how Spring IDE implemented it (check out their source code from here).