Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Implement partial classes
Implement partial classes [message #259105] Wed, 18 March 2009 09:14 Go to next message
Eclipse UserFriend
Hello.

I heed to implement something like partial classes in Java.
I am looking for a hook in JDT to interfere the compile process. All I
found is the extension: CompilationParticipant. But the problem is that
the compile API are hided in internal packages.

Here is the simplest use case:
I have a class:

package mypackage;
public class MyClass {
}

I want the file MyClass.class to contain an additional member after
building, for example:

package mypackage;
public class MyClass {
public void myMethod() {}
}

So, you have a class, save it, and the builder produces a class file with
an additional method, but the source file is untouched.

I just need a plugin that will do this work. Is it possible in any way?
Re: Implement partial classes [message #259109 is a reply to message #259105] Wed, 18 March 2009 11:17 Go to previous messageGo to next message
Eclipse UserFriend
"Ruslan " <metaruslan@gmail.com> wrote in message
news:a668072522f82d9e77e5786f8c4b9265$1@www.eclipse.org...
> Hello.
>
> I heed to implement something like partial classes in Java.
> I am looking for a hook in JDT to interfere the compile process. All I
> found is the extension: CompilationParticipant. But the problem is that
> the compile API are hided in internal packages.
>
> Here is the simplest use case:
> I have a class:
>
> package mypackage;
> public class MyClass {
> }
>
> I want the file MyClass.class to contain an additional member after
> building, for example:
> package mypackage;
> public class MyClass {
> public void myMethod() {}
> }
>
> So, you have a class, save it, and the builder produces a class file with
> an additional method, but the source file is untouched.
>
> I just need a plugin that will do this work. Is it possible in any way?


There is no way to do that with the existing API. (In particular,
CompilationParticipant will not let you modify an existing compilation
unit.)

Just as a technicality, one thing to be aware of is that literally speaking
you _can't_ "implement something like partial classes in Java." The
language definition doesn't permit it. You can implement a language
something like Java that has partial classes; you can't call it Java or Sun
may sue you.

Anyway, I would suggest looking into how AJDT (the AspectJ tooling) has
approached this problem. I'm pretty sure they had to fork and modify the
JDT plug-in code.

Another possibility is to invoke a bytecode manipulation library such as
BCEL, ASM, etc., as a separate builder step following Java compilation.

Out of interest, what's your use case? Why do you need this?

-Walter Harley
JDT APT lead
Re: Implement partial classes [message #259117 is a reply to message #259109] Thu, 19 March 2009 05:16 Go to previous messageGo to next message
Eclipse UserFriend
We have classes that are generated by code generator. And only a little
part is written by hand. We want to separate this to the generated part
and to the other part. Now we have to use inheritance for this, but it is
not convenient. We want parcial classes just like in .NET.
Re: Implement partial classes [message #259147 is a reply to message #259117] Fri, 20 March 2009 02:08 Go to previous message
Eclipse UserFriend
"Ruslan " <metaruslan@gmail.com> wrote in message
news:8a4812535f5fee77a53dc38ff8f2288d$1@www.eclipse.org...
> We have classes that are generated by code generator. And only a little
> part is written by hand. We want to separate this to the generated part
> and to the other part. Now we have to use inheritance for this, but it is
> not convenient. We want parcial classes just like in .NET.

Well, do as pleases you, but personally my hunch is that writing your own
version of Java will eventually prove even less convenient than inheritance.
Previous Topic:Duplicate JDWP commands from Eclipse
Next Topic:How to see javadoc in Quick Outline
Goto Forum:
  


Current Time: Wed May 07 13:09:17 EDT 2025

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

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

Back to the top