Results 1 to 3 of 3
  1. #1
    ajeeb is offline Member
    Join Date
    Dec 2008
    Posts
    30
    Rep Power
    0

    Default Creating Custom annotations

    Looking at the source codes of annotations provided by java 5 (like @Override, @SuppressWarnings etc), shows a simple enough code. However, I suppose there is an Annotation Processing Tool that ships in with the jdk 5 compiler that takes care of the functionality you need to implement with any annotation. But there must be some code that goes behind all these which the APT deciphers and brings out the functionality you want to implement. I am in seek of such codes and how to write them if I want to implement some custom functionality out of my custom annotations.

  2. #2
    ajeeb is offline Member
    Join Date
    Dec 2008
    Posts
    30
    Rep Power
    0

    Default

    To be more precise, I am talking about the interpreter which will understand my annotation. Can I get some sample tutorial of such interpreter implementations ?

  3. #3
    mcfrog's Avatar
    mcfrog is offline Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    32
    Rep Power
    0

    Default Runtime-Processing doesn't need APT

    hi,

    the short answer using Reflection:
    just for Runtime-Processing you don't need the mentioned APT. You can just go with
    Java Code:
    YourClassHere.class.getAnnotations()
    provided the given Annotation class uses Runtime-Retention
    Java Code:
    @Retention(RetentionPolicy.RUNTIME)
    The longer answer not using Reflection:
    In fact there is a pretty compact how-to for both Java 5 and 6 from Sun. java.sun.com/j2se/1.5.0/docs/guide/apt/GettingStarted.html (Sorry but forum-given I am a newbee) But the code is unneccessarryy un-understandable without deeper knowledge of the used (Sun) Mirror-API.

    Anyways there is an promising project to simplify the APT-like Annotation compilation: apt-jelly.sourceforge.net (URL: sorry only 2 posts)

    I hope that suffices for the first reply.
    Cheers / beste Gre / lepo pozdravje
    8=:(=)D . o O ( Save the Giraffes )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •