I'd like a mechanism to throw a compile-time warning manually. I'm using it to flag unfinished code so I can't possibly forget about it later. @Deprecated is close but warns at caller site, not at creation site. I'm using eclipse. Something like #Warning in C#.
Why not just add a flag in the source code like //TODO:
or something? And then just search for all occurances of TODO
in the file? You could even have some special flag too like FINISHME
or something.
If you have hundreds of TODOs in your project from the team, you can filter by a string e.g. your initials in the Task pane's top-right menus.
You could try to throw an exception if an unfinished method is called (e.g.)
throw new UnsupportedOperationException()
(Or you could create your own Exception). Obviously this will only help at runtime (unless you do a search or something in your code for it - but Todo would be a better solution for that)
And if you are using eclipse you can mark your unfinished code with // TODO and it will show up on your task list (and the right gutter if you have it configured). Obviously things can get very noisy if you have a lot of Todo tags.
I do this all the time by just putting "*** LEFT OFF HERE ***" or some such. As this is not valid Java or C++ or pretty much any other language syntax, the compiler gives an error message for it.
Of course that gives an error and not a warning. If you want to otherwise successfully compile, I suppose an easy thing to do would be to put a statement that you know will generate a compiler warning with a comment saying "finish this" or whatever.
I'm not sure if there is anything like that in java
but here is something that may help you:
compile the code below like this:
javac -Xprint verbose.java
public class verbose{
public @interface SomeMessage {
String somevalue();
}
@SomeMessage(
somevalue = "WHOOOOHOOOO000000000000000"
)
public static void main(){
System.out.println("Hello");
}
}