Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » creating instance of a class in a project from a plug-in
creating instance of a class in a project from a plug-in [message #207760] Thu, 26 April 2007 15:00 Go to next message
Eclipse UserFriend
Originally posted by: muztanger.gmail.com

I have been reading the FAQ etc for some time now and I have not found a
good solution to the problem i've got.

I am writing a plug-in that is going to analyze the code in the "active"
editor and write a comment. To be able to do this I have to evaluate some
of the variables in the code.

To do that I was thinking that I could make an instance of the class in
the code and examine the variables. But then I would need to have the jars
that the code uses in my classpath. Since I want the plug-in to be as
orthogonal to the "file" as possible, I don't want to include all the
possible .jar files before runtime.

Is there an easy solution to this or am I going in the wrong direction?

brgds
Johan Östrand
Re: creating instance of a class in a project from a plug-in [message #207819 is a reply to message #207760] Thu, 26 April 2007 18:14 Go to previous message
Eclipse UserFriend
Originally posted by: wharley.bea.com

"Johan" <muztanger@gmail.com> wrote in message
news:be1c764150feb2a2676219ca718c18f2$1@www.eclipse.org...
>I have been reading the FAQ etc for some time now and I have not found a
>good solution to the problem i've got.
>
> I am writing a plug-in that is going to analyze the code in the "active"
> editor and write a comment. To be able to do this I have to evaluate some
> of the variables in the code.
>
> To do that I was thinking that I could make an instance of the class in
> the code and examine the variables. But then I would need to have the jars
> that the code uses in my classpath. Since I want the plug-in to be as
> orthogonal to the "file" as possible, I don't want to include all the
> possible .jar files before runtime.
>
> Is there an easy solution to this or am I going in the wrong direction?

Writing compiler code is never easy :-)

The direction you want to take is definitely NOT trying to create an
instance of the class. That will surely lead you into corners you can't get
out of: for instance, what if your code simply can't be instantiated in the
editor, because of platform dependencies, security privileges, etc.?

Rather, you should be looking at how refactoring operations work, based on
the JDT DOM AST and on the JDT Java Model. These are APIs provided by the
compiler to let you investigate and manipulate source code, seeing it the
way that the compiler does (without having to actually instantiate it).

A good starting point would be
http://www.eclipse.org/articles/Article-JavaCodeManipulation _AST/index.html.
You can also look at the implementations of the refactoring operations in
jdt.ui.
Previous Topic:Autopopulate VM arguments in run configurations
Next Topic:PLUG-IN!!!!!
Goto Forum:
  


Current Time: Fri Apr 26 12:26:03 GMT 2024

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

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

Back to the top