Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Extend class with same name and package
Extend class with same name and package [message #981736] Mon, 12 November 2012 16:58 Go to next message
David Marina is currently offline David MarinaFriend
Messages: 3
Registered: November 2012
Junior Member

I don't know if this is even possible but I would like to listen for some alternatives to this problem:

I am trying to single-source RCP/RAP for an already existing RCP application, trying to mantain the original code while it is possible. In order to test the suitability, I have made some patch RAP fragments for the missing API, sometimes patching classes of org.eclipse.swt with missing methods and sometimes adding full missing controls. In order to modify the original classes, I copied the full class text, as suggested in the guide:

What I am trying to do now is to "forward" the valid methods to the original classes and reduce the patch classes. So they will contain just the forwarding calls and the implementation of the missing methods.
Is it possible to get this using some classloader mechanism to load the class from the host plugin? It it is not, is there a way to extend a class which is in the same package and has the same name?

Re: Extend class with same name and package [message #982094 is a reply to message #981736] Mon, 12 November 2012 23:33 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
Registered: July 2009
Senior Member
That's an interesting challenge Smile

Within any given class loader each qualified class name uniquely identifies one class. Within class any reference to will necessarily refer to the exact same class. If at runtime through class loader trickery an instance of another comes into scope, it will not be assignment compatible, so if you have a field " delegate;" you cannot assign an instance of the foreign class. Thus, to access any features of the foreign class you'd have to go through reflection each and every time.

Programming languages have been proposed with "open classes", which natively support what you are asking for: adding new methods and fields into existing classes. But Java doesn't have this.

Unless you want to go the painful road through heavy class loader trickery and lots of reflection, I would normally recommend doing the adaptation in your own namespace and adjusting the application accordingly.

Depending on how much effort you're willing to invest, the hottest solution could actually be to implement your own byte code transformer that merges two versions of each class into one class at load time - thus implementing your own "open classes" language extension.


Previous Topic:How to Speed up the 'Building Workspace' which work stopper.
Next Topic:IBM ILOG ODM Enterprise PLugin for Eclipse
Goto Forum:

Current Time: Mon Nov 23 16:53:24 GMT 2020

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

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

Back to the top