views:

128

answers:

4

If I create a custom annotation like this:

public @interface TODO
{
    String msg();    
    String start_date();
}

then a method:

@TODO
(
   msg="will be developed!",
   start_date="05/01/2010"
)
public static void Calculator()
{
}

after I call it:

Calculator();

If I wanted that the compiler warn me about it how could I do that?

+1  A: 

If you are using an IDE, there are plenty of good options. For Eclipse:

  • use the built-in plug-in which locates all TODO, FIXME, etc. words in your code and puts them in a special view.
  • register your own custom builder which can show you the warnings
Bozho
Is it not possible to do it with Java compiler?
xdevel2000
+3  A: 

You must write an annotation processor and invoke apt to run it on your code.

Aaron Digulla
+2  A: 

Use the Annotation Processing Tool (apt) to make your own AnnotationProcessor and print the message with javax.annotation.processing.Messager

Jerome
+2  A: 

There was a similar question, some weeks ago. Here is the link to both the question and my answer.

You can easily adapt this code to your needs.

barjak