我正在使用Eclipse-Oxygen试验注释处理器
所以我创建了Annotation-Processor项目和Annotation-Example项目 .
注解的实施例:
package com.annotation.example;
import com.annotation.annotation.Anno;
@Anno
public class TestClass
{
public int i;
public static void main(String[] args)
{
System.out.println("Hello annotations");
}
}
注释处理器的注释:
package com.annotation.annotation;
import static java.lang.annotation.RetentionPolicy.SOURCE;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
@Documented @Retention(SOURCE) public @interface Anno
{}
Annotation-Processor的注释处理器:
package com.annotation.processor;
import java.util.Collections;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic.Kind;
import com.annotation.annotation.Anno;
public class AnnoProcessor extends AbstractProcessor
{
@Override
public SourceVersion getSupportedSourceVersion()
{
return SourceVersion.latestSupported();
}
@Override
public Set getSupportedAnnotationTypes()
{
return Collections.singleton(Anno.class.getCanonicalName());
}
@Override
public boolean process(Set allAnnotatedElements, RoundEnvironment roundEnv)
{
for(Element annotatedElement : roundEnv.getElementsAnnotatedWith(Anno.class))
{
System.out.println(annotatedElement.getSimpleName());
processingEnv.getMessager().printMessage(Kind.ERROR, "jus checking");
}
return false;
}
}
javax.annotation.processing.Processor的内容:
com.annotation.processor.AnnoProcessor
我的项目资源管理器:Project Explorer
我的注释处理器仍未在Eclipse中注册 .
我在这做错了什么?
任何帮助表示赞赏 .