| Typecasting Plugin classes [message #115773] | 
Tue, 11 November 2003 11:39   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 #116639 is a reply to message #115811] | 
Thu, 13 November 2003 10:17   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.06825 seconds