When processing Annotations are compile time, is there a way to raise a warning or an error in the compile process?
Yes, using apt
using standardized annotation processing in javac as of JDK 6
I figured out how to do this, although this seems very undocumented throughout the full internet.
My next question which has stumped me, is when I visit say a method declaration, is there a way for me to access the source file being ran against?
> I figured out how to do this, although this seems
> very undocumented throughout the full internet.
> My next question which has stumped me, is when I
> visit say a method declaration, is there a way for me
> to access the source file being ran against?
Both the apt and standardized annotation processing APIs only model up to the the method declaration, the interior of methods and constructors are not covered in the model. However, if you are content using the javac-specified tree API (http://java.sun.com/javase/6/docs/jdk/api/javac/tree/index.html), you can map from a javax.lang.model.Element to a tree representing the source inside a method using com.sun.source.util.Trees.getTree.
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.