月食氧气中的注释处理和处理器注册

时间:2018-11-13 16:57:33

标签: java eclipse annotations annotation-processing

我正在尝试使用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
    {}

注释处理器的注释处理器:

    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中注册。
我这是怎么了?
任何帮助表示赞赏。

0 个答案:

没有答案