Bruce Chapman found the new "apt" tool that we all get with Java 5. The tool allows you to run your own code inside the compiler, so you can examine the source being compiled, generate other code, and more. This comes in really handy when you are using annotations, and already people are looking at adding Design by Contract annotations that apt enforces.
Apt internally runs javac code, so it can't actually be deprecated. But it will be interesting to see the innovation that comes out of being able to plug-in to this layer!
Read: Deprecate JAVAC
-
Deprecate javac in favour of the Java 5 "apt" tool? (9 messages)
- Posted by: Dion Almaer
- Posted on: October 14 2004 11:40 EDT
Threaded Messages (9)
- Disappointed by Bill Burke on October 14 2004 13:15 EDT
- Disappointed by Kyle Marvin on October 14 2004 14:36 EDT
-
Disappointed by Bill Burke on October 14 2004 02:46 EDT
- Disappointed by Kyle Marvin on October 14 2004 03:21 EDT
-
Disappointed by Bill Burke on October 14 2004 02:46 EDT
- Disappointed by Kyle Marvin on October 14 2004 14:36 EDT
- Deprecate javac in favour of the Java 5 "apt" tool? by James Watson on October 14 2004 14:27 EDT
- finally properties? by Tom Eugelink on October 15 2004 02:21 EDT
- Apt not all it's cooked up to be by Toby Reyelts on October 15 2004 13:11 EDT
- Apt not all it's cooked up to be by Brian Miller on October 15 2004 14:47 EDT
- Apt not all it's cooked up to be by Juozas Baliuka on October 16 2004 01:38 EDT
- Apt not all it's cooked up to be by Brian Miller on October 15 2004 14:47 EDT
-
Disappointed[ Go to top ]
- Posted by: Bill Burke
- Posted on: October 14 2004 13:15 EDT
- in response to Dion Almaer
After reading the "apt" api it seems that you cannot run annotation processors after javac. :( Am I wrong here?
Bill -
Disappointed[ Go to top ]
- Posted by: Kyle Marvin
- Posted on: October 14 2004 14:36 EDT
- in response to Bill Burke
After reading the "apt" api it seems that you cannot run annotation processors after javac. :( Am I wrong here?Bill
Mostly true. If a side effect of annotation processing is the generation of new source artifacts that contain annotations, then that artifact will be processed and compiled in a new round after the original compile. This will continue until no new source artifacts are generated.
But for any single artifact the order is generally:
1. parse - syntax errors emitted here, and processing stops on errors
2. call annotation processors - can do semantic validation driven by annotations, generate additional info/warning/errors or new source/text/binary artifacts
3. compile
Bill, I have a fair amount of experience working w/ apt... if you tell me more specifically the use case you feel is blocked, maybe I can suggest something.
-- Kyle -
Disappointed[ Go to top ]
- Posted by: Bill Burke
- Posted on: October 14 2004 14:46 EDT
- in response to Kyle Marvin
I want to use it for JBoss AOP. Basically, the first pass will load annotations for interceptor bindings, second phase would happen after Javac so that the AOP framework can massage/aspectize the bytecode. Basically, I'm not doing any java source code generation, but rather transformation.After reading the "apt" api it seems that you cannot run annotation processors after javac. :( Am I wrong here?Bill
Mostly true. If a side effect of annotation processing is the generation of new source artifacts that contain annotations, then that artifact will be processed and compiled in a new round after the original compile. This will continue until no new source artifacts are generated.But for any single artifact the order is generally:1. parse - syntax errors emitted here, and processing stops on errors2. call annotation processors - can do semantic validation driven by annotations, generate additional info/warning/errors or new source/text/binary artifacts3. compileBill, I have a fair amount of experience working w/ apt... if you tell me more specifically the use case you feel is blocked, maybe I can suggest something.-- Kyle
I'm looking for a nice way to implement our AOP precompiler.
Bill -
Disappointed[ Go to top ]
- Posted by: Kyle Marvin
- Posted on: October 14 2004 15:21 EDT
- in response to Bill Burke
I want to use it for JBoss AOP. Basically, the first pass will load annotations for interceptor bindings, second phase would happen after Javac so that the AOP framework can massage/aspectize the bytecode. Basically, I'm not doing any java source code generation, but rather transformation.I'm looking for a nice way to implement our AOP precompiler.Bill
Yeah, I'm not sure APT can fully help you here. Its processing model is oriented towards the tasks I describe in my previous post (semantic validation of annotations and generation of new artifacts), not to post-compilation mods to class files. You could use it to process/validate the annotations and then drop some secondary file that is used as input to a post-apt aspect tool.
The APT classes also have invocation entry points so it can be called from other java code (similar to how javac can be invoked in-process); so another possibility is for your precompiler to just invoke apt (the classes, not the executable) as part of its larger processing. I don't think these entry points are documented, though. -
Deprecate javac in favour of the Java 5 "apt" tool?[ Go to top ]
- Posted by: James Watson
- Posted on: October 14 2004 14:27 EDT
- in response to Dion Almaer
Couldn't this be used to implement aspect oriented developement? -
finally properties?[ Go to top ]
- Posted by: Tom Eugelink
- Posted on: October 15 2004 02:21 EDT
- in response to Dion Almaer
So this is the place to add my long wished for properties support?
@get String name;
public void setName(name) {this.name = name;}
@get @set String name;
@get @set @PropChange String name;
@get @set @PropChange @VetoChange String name;
Complete with compiler error if the class which contains a @PropChange does not have a "firePropetyChangedEvent" method? -
Apt not all it's cooked up to be[ Go to top ]
- Posted by: Toby Reyelts
- Posted on: October 15 2004 13:11 EDT
- in response to Dion Almaer
There are some serious misunderstandings about what apt is actually useful for. As the documentation states, apt only provides a "source-based, read-only view of program structure." You use apt to generate new code, not modify existing code. This means that apt is mostly useless for a large set of tools.
IMHO, Sun needs to extends apt to make the AST they provide writable. That would make it very useful for all sorts of tools (including the aforementioned JBoss AOP).
God bless,
-Toby Reyelts -
Apt not all it's cooked up to be[ Go to top ]
- Posted by: Brian Miller
- Posted on: October 15 2004 14:47 EDT
- in response to Toby Reyelts
IMHO, Sun needs to extends apt to make the AST they provide writable.
Agreed, but there are prerequisites that need fixing. Javac's AST API isn't publicized, and merely to view it a person must contaminate himself by accepting Sun's community license.
On java.net I read your suggestion that "For platforms like Java and .NET, we'll probably start to see ASTs that are language agnostic, but virtual machine specific." That's a fascinating prediction of yours. You seem to be alluding to AST reconstruction from bytecode, which is what decompilers do. Is even the best decompiler (Jad?) reliable at this, especially if the classfile was optimized or compiled from a non-Java language?
Anyway, I agree with you that a publicly mutable AST would be awesome. -
Apt not all it's cooked up to be[ Go to top ]
- Posted by: Juozas Baliuka
- Posted on: October 16 2004 13:38 EDT
- in response to Brian Miller
It must be possible to use eclipse compiler for this stuff
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/