Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Typecasting Plugin classes
Typecasting Plugin classes [message #115773] Tue, 11 November 2003 16:39 Go to next message
Eclipse UserFriend
Originally posted by: javibasi.yahoo.es

Hi all

I'm experiencing some problems trying to develop an Eclipse plugin and I
wondered if anyone could give me any hint about what I'm not doing well.

A little bit of background: my plugin tries to do some actions on a java
class file from the workspace. In order to do that, it gets an instance of
that class. The problem arises when I try to typecast the object into its
parent class and I get an ClassCastException.

The parent class is contained on a jar file that I've imported into my
plugin. I've tried several ways to instatiate the object:
- Class.forName.
- URLClassLoader, setting as parent the Plugin and Platform Classloaders
and adding the neccesary jars in each case.
- Getting the System ClassLoader and, by reflection, calling the addURL
method to set the new jar path.

But in all that attempts I get the same error. I've been forced to use
reflection to call the methods of my object, and it works. But I'm trying
to find a way to make the typecast in order to use some interfaces that
need it.

I guess I'm making some mistake when I choose the type of classloader I
use to get the instance of the object, but I can't find the right way to
do it.

I've been browsing several forums and newsgroups and I found more people
with this problem but without a final solution, so if anyone has got this
to work, any help would be highly appreciated.

Thanks in advance

Dian Cecht
Re: Typecasting Plugin classes [message #115789 is a reply to message #115773] Tue, 11 November 2003 17:20 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.NO.SPAM.us.ibm.com

You really shouldn't be doing that. You shouldn't load classes from a
workspace into the IDE. Most of the info you can get from JDT.

See:

http://eclipsewiki.swiki.net/114#augmentedClasspath2


NOTE: Wiki seems to be running slowly and timing out today. :-(

--
Thanks, Rich Kulp

Re: Typecasting Plugin classes [message #115811 is a reply to message #115789] Tue, 11 November 2003 18:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: javibasi.yahoo.es

First of all, thanks Rich for your reply

I know the way I'm trying to do these things it's not the best. I agree
that it should be done using JDT and AST, but I'm afraid that my
circunstances are forcing me to do it this way.

The problem is that I'm involved in a migration process, and most of the
utility classes I use are based on instances of classes to get their
properties. So the only way to avoid re-coding the whole stuff is just
trying to get the instance of an object from the workspace.

In fact, I already did it several times and it works fine if you are
careful enough about what kind of instances you get.

So if anyone has a clue on how to do that typecast, I'd be grateful

Thanks in advance

Dian Cecht

Rich Kulp wrote:

> You really shouldn't be doing that. You shouldn't load classes from a
> workspace into the IDE. Most of the info you can get from JDT.

> See:

> http://eclipsewiki.swiki.net/114#augmentedClasspath2


> NOTE: Wiki seems to be running slowly and timing out today. :-(
Re: Typecasting Plugin classes [message #116639 is a reply to message #115811] Thu, 13 November 2003 15:17 Go to previous message
Eclipse UserFriend
Originally posted by: javibasi.yahoo.es

If anyone is interested in this issue, what I finally did was gatting the
instance of my workspace classes by defining an URLClassLoader parented
with the Plugin or Platform classloader. The I used reflection to get and
execute the methods of my workspace object.

I know it's a bit dangerous loading foreing objects into de IDE, but this
is the only way I found, as long as the AST can give you full information
about a class, but cannot return the result of executing a method.

Dian Cecht
Previous Topic:code formatting: can this be done?
Next Topic:generating "implements Cloneable"
Goto Forum:
  


Current Time: Fri Sep 27 02:40:02 GMT 2024

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

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

Back to the top