This content has been marked as final. Show 10 replies
can any one suggest a good tutorial for annotation asIf you are using JDK 5, the apt getting started guide can be found here:
i am new to annotation.
I do not know of one, that explains the ins and outs, but if you find an example Annotation that modifies source code, let me know!
but if you find an example Annotation that modifiesYou won't.
source code, let me know!
Annotation Processing with APT or a JSR269 tool does not permit you to modify source code. You can generate new source files but not modify existing ones.
This is not the case see: http://java.sun.com/javaee/5/docs/api/javax/ejb/Stateful.html
If this were the case there would be NO implmentation of the persistance, yet it would still work!
The questions was targeted at the implementation of such a (specific) mechinisum. Please not the annotation does not define HOW data is to be persisted, just that it should be (We are looking for an example on HOW we generate code that does the actual work).
This is not the case see:That page does not change my view that APT and JSR269 do not provide a mechanism to modify existing code.
Annotations may be processed at build time or run time. APT and JSR269 address build time processing. java.lang.reflect addresses run time processing. I do not know how the @Stateful annotation causes statefulness, I do know that APT or javac will NOT be directly modifying the annotated code.
There are many mechanisms available to you. Your job is to understand the strengths and limitations of each and work out which combination of mechanisms best meets your need.
If you describe what you want to achieve rather than ask how to do something impossible, we might be able to point you in the right direction.
I am looking to use annotations to (Fill in) implementation detail, given a proper annotation processor. I guess I was assuming APT was an (Annotation Processor), if this is not the case, can someone point me twards one?
I am looking to use annotations to (Fill in)The apt tool or javac with JSR 269 can be used for this purpose, subject to the capabilities provided in those APIs. Both APIs present a read-only view of the source code; the source code cannot be directly modified via those APIs. However, as Bruce has noted, if the annotated class is designed to inherit from a generated class or return objects from a generated subclass, much of the effect of modifying the annotated source can be achieved.
implementation detail, given a proper annotation
processor. I guess I was assuming APT was an
(Annotation Processor), if this is not the case, can
someone point me twards one?
So, what I am hearing is this is not possable, how does one put a request in for this???
Alternatly, how does one acomplish this?
Hmmm maybe there is a way to modify the parsed stuff.
javax.lang.model is read-only but it's just an interface... maybe one could use the underlying implementation classes of this interface.
If I output the class name of an instance of javax.lang.model.element.Element, I get "com.sun.tools.javac.code.Symbol$ClassSymbol".
There is an API Documentation of these classes... of course it says not to use this classes ;-). I think i am going to figure out if these classes can be used to modify the parsed source structure tomorrow. I really need this too ;-).
Please don't resurrect old threads. I'm locking this one.