Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to get current project in custom "OpenDeclarationAction"?
How to get current project in custom "OpenDeclarationAction"? [message #1719545] Fri, 08 January 2016 18:14 Go to next message
David M. Karr is currently offline David M. KarrFriend
Messages: 744
Registered: July 2009
Senior Member
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?
Re: How to get current project in custom "OpenDeclarationAction"? [message #1719634 is a reply to message #1719545] Sun, 10 January 2016 17:47 Go to previous message
David M. Karr is currently offline David M. KarrFriend
Messages: 744
Registered: July 2009
Senior Member
I've managed to resolve this. The following SO posting describes the solution: http://stackoverflow.com/questions/34702070/how-can-an-eclipse-texteditoraction-know-what-project-the-current-file-is-in .
Previous Topic:How can I set defaults used in MavenProjectWizard pages, or even bypass them?
Next Topic:Change name of log file (".log") in RCP
Goto Forum:
  


Current Time: Tue Jan 25 03:17:29 GMT 2022

Powered by FUDForum. Page generated in 0.02266 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top