2014-09-12 48 views
1

我有一个自定义的Java注解像下面Java注解会员验证上编译

@customelement(folder = "/path/") 
public testMethod() { 

} 

我要验证的文件夹路径(“/路径/”)的文件夹成员变量和报告java源内部错误。我该怎么做?

+0

你想报告一个错误? – 2014-09-12 11:10:18

+0

编译此类时 – Sandip 2014-09-12 11:11:28

+0

这是不可能的。抱歉! – 2014-09-12 11:11:57

回答

0

Java Annotation Element Method return

@Override 
    public boolean process(Set<? extends TypeElement> annotations, 
          RoundEnvironment roundEnv) { 
     Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(CustomAnnotation.class); 
     for(Element te : elements){ 
      CustomAnnotation annotation = te.getAnnotation(CustomAnnotation.class); 
      String folder = annotation.folder(); 
      //... do sth with folder in context of te. 
      //te represent annotated method, e.g. testMethod from your example 
     } 
     return true; 
    } 

还记得注释与@SupportedAnnotationTypes您CompileTimeAnnotationProcessor( “package.CustomAnnotation”)和@SupportedSourceVersion(SourceVersion.RELEASE_7)(或Java语法的任何版本,你要支持)。

如果还有其他问题,我建议阅读这篇优秀的教程博文。