Instantiate CompilationUnitEditor for usage in a custom Eclipse plugin - eclipse

I currently work on a custom Eclipse plugin. The plugin expects the user to type in some Java code, so I want Code Assistance for that. The plugin looks like this so far
https://marketplace.eclipse.org/content/findreplace-regular-expressions-and-match-evaluators#group-screenshots .
Now my idea was to instantiate a CompilationUnitEditor, e.g. like this
CompilationUnitEditor javaEditor = new CompilationUnitEditor();
Composite placeWhereINeedToHaveIt = new Composite(...
...
javaEditor.createPartControl(placeWhereINeedToHaveIt);
The problem with above code is that I didn't set the EditorInput (i.e. the CompilationUnit ) for the javaEditor, but there is no public method on CompilationUnitEditor allowing me to do this.
What can I do? Any help is appreciated!
I also would like to have the source code for CompilationUnitEditor in my Eclipse IDE. Right know if I hit Alt+Shift+F1 on an active JavaEditor (activating the Eclipse Spy) and then click on CompilationUnitEditor, the source code isn't shown.

Related

How to listen to changes in Java editor to refresh a view part?

I'm implementing an Eclipse plug-in to refresh a new view part when any change occurs in a Java file. Is this possible? And how?
Besides that, I need to identify the abstract syntax tree (AST) of the present code in the Java editor. Any suggestion?
You can listen to changes of the underlying IDocument as described here: Eclipse Plugin to granularly monitor editor changes
The Java editor input also adapts to IJavaElement. For example:
editor.getEditorInput().getAdapter( IJavaElement.class )
If the result is an ICompilationUnit, you can create an AST thereof as described here: https://www.eclipse.org/articles/article.php?file=Article-JavaCodeManipulation_AST/index.html

Could I select super class when creating a new class in IntelliJ IDEA 2016 like in Eclipse?

As you guys know, when we create a new class in Eclipse, we can choose super class what we should extend at the same time like followed sreenshot:
In Eclipse:
However, I can't do that in IntelliJ IDEA:
Is there any menu or wizard to do this?
By the way, I'm using Eclipse MARS and IntelliJ IDEA 2016
The feature you want is called Create subclass.
Use Option + Return (or ALT + Enter on PC) on the class name, and you will have the opportunity to create a subclass of your currently selected class.
You may also choose to invoke this through the "Find All Actions" dialog, which is CTRL+SHIFT+A on PC and is likely similar on Mac.
Still I haven't found any way to select a super class while creating a sub-class in IntelliJ IDEA. But I found that option in Android Studio which looks similar to the way it is done in Eclipse:
using alt + enter --> the latest version of intelliJ has an option of "implement abstract class"

Eclipse plugin Development - Is it possible to add a new option in right-click-on-method menu?

I´m currently developing an Eclipse plugin for my research and my professor wants me to add a new option in the menu that appears when you right-click a method in the editor... something like showing runtime exceptions which can appear in method execution... anyone knows if it´s possible to add a new menu option for this in Eclipse?
You can use the org.eclipse.ui.menus extension point to do this: http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fworkbench_cmd_menus.htm and http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_ui_menus.html

How do I associate a file with a perspective in an eclipse plugin

I have created an editor plug-in for eclipse that is associated with the file extension .eap
I have also created a perspective that contains views for this data.
I would like to add the following behaviour: When I double click on the .eap file I'd like the EAP Perspective to be opened.
Just like what happens when you click on a Java file for the first time.
Any help appreciated!
Will
try {
IWorkbench workbench = PlatformUI.getWorkbench();
workbench.showPerspective(EapPerspective.ID,
workbench.getActiveWorkbenchWindow());
} catch (WorkbenchException e) {
e.printStackTrace();
}
As far as I know, clicking on or opening a Java file for the first time will not open the Java perspective. However, perhaps you are thinking about how after using the New Java Class Wizard, you are prompted to change to the Java perspective.
Regardless, there are several things that you can do:
In the org.eclipse.ui.newWizards extension point, specify the finalPerspective as well as preferredPerspectives
Assuming that you have sub-classed AbstractTextEditor, then override the setFocus() method and add some logic to change to the appropriate perspective, something like this (but be careful to add specific null checks):
getEditorSite().getWorkbenchWindow().getWorkbench().showPerspective(desc.getId(),
getWindow(), pageInput);
The first solution is recommended, although it will not cover all the cases that you are asking for, and the second is a bit naughty as it goes against Eclipse conventions.

Execute code when Eclipse workbench loads

I'm writing an Eclipse plug-in and I've bumped into an issue. Amongst others I'm creating a new custom perspective. I need to execute some code when the workbench loads. I'm using a WorkbenchAdvisor and putting the code in the initialize method. However as it is now it's not being called...
Apparently I need to call this PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor(); but I don't know where to put this... I can't put it in the createInitialLayout of the perspective because this is only called when the perspective is created for the first time.
Any ideas please?
Thanks and regards,
Krt_Malta
You can use the startup extension point to run code before your plugin is loaded. You should place the extension in an seperate plugin, as all code inside the plugin with the startup extension is loaded after the workbench is started.
The interface to look for is org.eclipse.ui.IStartup.
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_startup.html
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ui/IStartup.html