I have a simple marker annotation for methods (similar to the first example in Item 35 in Effective Java (2nd ed)):
/**
* Marker annotation for methods that are called from installer's
* validation scripts etc.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface InstallerMethod {
}
Then, in a given package (say com.acme.installer
), which has a few subpackages containing some 20 classes, I'd like to find all methods that are annotated with it. (Because I'd like to do some checks regarding all the annotated methods in a unit test.)
What (if any) is the easiest way to do this? Preferably without adding new 3rd party libraries or frameworks.
Edit: to clarify, obviously method.isAnnotationPresent(InstallerMethod.class)
will be the way to check if a method has the annotation - but this problem includes finding all the methods.