@PrintMethod 주석을 사용하여 주석이 달린 메서드를 검색하려면 주석 Procssor를 작성하려고합니다. 아래의 테스트 클래스 예를 들어, 테스트 메서드 내에서 코드를 인쇄 할 싶습니다. 그것을 할 수있는 방법이 있습니까?사용자 정의 주석 프로세서 - 주석을 사용하여 메서드 검색
아래 명시된 AnnotationProcessor 클래스에서 메서드 이름 만 가져올 수 있지만 메서드의 세부 정보는 가져올 수 없습니다.
테스트 클래스
public class test {
public static void main(String[] args) {
System.out.println("Args");
}
@PrintMethod
private boolean testMethod(String input) {
if(input!=null) {
return true;
}
return false;
}
}
주석 프로세서 클래스 이것에 대해 궁금
public class AnnotationProcessor extends AbstractProcessor {
//......
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
//retrieve test Anntoation
Set<? extends Element> ann =roundEnv.getElementsAnnotatedWith(PrintMethod.class);
//Print the Method Name
for(Element e: ann) {
String msg="Element ee :"+ee.getSimpleName().toString();
processingEnv.getMessager().printMessage(javax.tools.Diagnostic.Kind.ERROR, msg, e);
}
}
}