Exporting Eclipse Snippets - eclipse

How can I export my Eclipse Snippets so that I can re-use them on another machine?

Display the snippets view: Window -> Show View -> Other ... -> General -> Snippets
Right click in snippets view -> Customize ...
Select Snippet Category
Export

If you add a new snippet a wizard opens. In that window you can export your snippets!

Depends on exactly what you mean by snippets. For Java (and other languages) you can define custom templates, as well as the default ones created by Eclipse.
In Window... Preferences, filter for templates. In the dialog on the right-hand side are buttons for import and export. Select the templates you'd like to export, and click Export...
Save them to a file.
In the other workspace, go to the same location, but do an import, and select the file you created above. This will add the saved templates to the list.
Java also has Code Templates defined (i.e. pieces of code that get put in when you create a new method, class etc). The process is similar here for import/export.

Related

Extend an existing Context Menu inside Eclipse Outline View for Xtext

We have an eclipse plugin which has been created using Xtext. And now I want to add a context menu to an Element inside the Outline View inside Eclipse. I understand that I need to have a menuContribution which will invoke a Command. But what I dont understand is, do I have to create (define) a command in some way or the other.
My plugin.xml contains an extension point for "org.eclipse.ui.menus".
Menu Contribution is something like this:
I find tutorials that talk about creating menu contributions, but there is nothing which will tie up my menuContribution to a command I want to define.
Typically you will need three extensions:
org.eclipse.ui.command
org.eclipse.ui.handlers
org.eclipse.ui.menu
It requires some fidling to get them right. I suggest you look at some open source code and starts from there.
Introduction article: http://www.vogella.com/tutorials/EclipseCommands/article.html
The locationUri of the context menu you like to contribute to should be popup:org.eclipse.xtext.ui.outline.OutlinePageContextMenu. Found here: https://github.com/eclipse/xtext-eclipse/blob/master/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/outline/impl/OutlinePage.java

How to write an Eclipse component (editor, launcher, ...) that can execute my custom DSL files?

Let's say I have defined a small little textual DSL and I have an 'interpreter' that will parse and execute commands of a file in that DSL.
What is the best way to start such an interpreter in Eclipse?
For instance, I want to double click on a file and, based on the fact that it has the extension .mydsl, start the interpreter. Another option could be using a launcher with "Run As ...".
So should I look at implementing a ...
custom launcher (extending org.eclipse.debug.core.launchConfigurationTypes, http://www.vogella.com/tutorials/EclipseLauncherFramework/article.html), or
editor, that is not actually editing the file, but will be called when the file is double clicked (extending EditorPart, https://wiki.eclipse.org/FAQ_How_do_I_create_my_own_editor%3F)
something else?
Thanks for any hints!
For that I would recommend to implement a custom launcher to get for free:
in main toolbar Run button with history support
ability to share launch configuration via version control (in Common tab choose Shared file)
Launch Group support
etc.
In Project Explorer, Package Explorer, Navigator and similar views a double-click opens a file. In order not to confuse the user you should not change this behavior. But in addition to the custom launcher you could consider to implement an editor with a run button similar to PDE's Product Configuration Editor or a view similar to the Ant view that shows your DSL scripts that can be run on double-click.

Netbeans: how to change #author

When creating a new class or interface in Netbeans IDE, an "#author ...." tag appears. How to change its value? If possible, I would like to change it by using Netbeans menu and not by editing some config files :) I'm using Netbeans 7.2
Steps:
Go to Tools -> Templates.
Click on Settings button. A new panel with template settings will appear in your IDE:
Uncomment the last line and change the value of "user" to what ever you like to be inserted after the #author tag.
PS: I think this blog will better explain how to update author template
In case someone else finds this while looking for the same functionality in Eclipse: Window -> Show View -> Templates
-In netbeans go to Tools -> Templates -> Settings
-last line of the file, write like this user=xyz
N:B: Instead of xyz you could be used your name.
I could not find any template or Code completion in Netbeans 15 to get rid of that #author when I added a javadoc to a class. Hence I added another code completion, cc, and let it add the javadoc.
Additional Code Completion

Javadocs getting added everywhere

I use Javadocs to add descriptions to my methods. In Eclipse I just place the mouse over the method name and click on the Add Javadoc menu. Sometimes though I notice it adds a bunch of empty comments to every field and method in my file. This is really annoying and I have no idea why it does this. Am I doing something inadvertently or is this a bug in the Javadocs plugin?
You can define how you want the code template to look. In Eclipse, go to: Window -> preferences. There look up Java -> Code Style -> Code Templates. Then you can define what the javadoc should look like, or not look like.

Adding menu item in Eclipse

I want to write an Eclipse plug-in that adds an item to the Refactor menu in Eclipse JDT? How can I do this?
Thanks a lot
Recently, I was writing a plug-in that performs some re factoring.
Writing the refactoring was not too complicated, but figuring out how add the menu items correctly into the Refactor menu took a lot of time.
Here is the correct plugin.xml snippet:
The Refactor menu tag is a copy of the original "Refactor" menu definition from org.eclipse.jdt.ui. It is important to copy all the separator definitions. For my plug-in, I have also added a new separator called spartanGroup.
The path for the Refactor menu is org.eclipse.jdt.ui.refactoring.menu.
It is possible to figure this information by looking at plugin.xml of the org.eclipse.jdt.ui plug-in. You can find it online (for example here) or you can import the source code of your eclipse build following these steps:
1 File -> Import
2 Select Plug-ins and Fragments and click next.
3 In the "Import From" section choose "The active target platform".
4 In the "Import As" section choose "Project with source folders"
5 In the next screen, locate your plug-in (org.eclipse.jdt.ui) and add it.
6 Click finish and the source code of the plug-in will be imported into your workspace.
You could write a plug-in that utilizes the Platform Command Framework. For details see the official wiki page, that provides several tutorial links: http://wiki.eclipse.org/index.php/Platform_Command_Framework
Basically, you define a command to execute, a menu contribution (where to display it) and a command handler (what to execute).