How to get current project in custom "OpenDeclarationAction"? [message #1719545] |
Fri, 08 January 2016 13:14  |
Eclipse User |
|
|
|
I've inherited a somewhat large codebase for an open-source project (https://github.com/davidmichaelkarr/yang-ide/tree/master if you care). I'm going to give some perhaps unnecessary background on my application so it's clear what I'm trying to do.
It implements an Eclipse plugin for a custom specification language that is functionally similar to CORBA IDL (not the syntax or how the products are used) and also XML Schema, in that it has an "import" command that takes a module name, along with an optional "prefix" that should be used to qualify references to the imported components, to prevent naming conflicts.
The plugin has a custom "OpenDeclarationAction" whose intent is like the one in the JDT. It goes to the file and location where the referenced component is defined. There's a change I believe I need to make in this class, but I'll provide a little more background first.
When the plugin starts up in the workspace, it indexes all the files in the workspace with the custom extent defined for this specification language (".yang"). This indexing pass creates a map of all the components defined in the modules, using a "6-tuple" key, where one of the parts of the key is the project the module was in.
In my test case, I'm sitting in one of these files (call it "module1") in one project (call it "project2"), and on a line that references a component that was imported from "module2". There is a "module2" file stored in both "project1" and "project2".
I execute the "open declaration" action at this point, and it brings up "module2", but it gets it from "project1", instead of the copy from "project2", which is more correct.
When I traced through the code, I saw that the "OpenDeclarationAction" wasn't passing the current project to the "index search" facility, so it was just returning the first one it found. My problem is, I don't know how I can obtain the current project from the limited context that I have in the action.
If it matters, here's a small excerpt from my action class:
public class OpenDeclarationAction extends TextEditorAction {
public OpenDeclarationAction(ResourceBundle bundle, String prefix, ITextEditor editor) {
super(bundle, prefix, editor);
}
@Override
public void run() {
I would assume that I have to do something in "run()" to get the current project. The ODA is created in a custom subclass of "org.eclipse.ui.editors.text.TextEditor". It's not clear to me whether it would be valid to obtain the current project in that class and pass the project to the ODA constructor, as the "run()" method is executed at a later time, although I would think the project wouldn't change.
So I just have to get the current project (IProject) in the "run()" method. How would I do that?
|
|
|
|
Powered by
FUDForum. Page generated in 0.04129 seconds