Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java注释处理-如何处理已处理的代码?_Java_Annotation Processing - Fatal编程技术网

Java注释处理-如何处理已处理的代码?

Java注释处理-如何处理已处理的代码?,java,annotation-processing,Java,Annotation Processing,如果我有课 @GenerateInterface public class _FooImpl {} 我想生成一个接口 public interface Foo {} 它基本上包含了\u FooImpl的所有方法(即getter和setter) 如果我有继承权,比如 @GenerateInterface public class _ParentImpl {} @GenerateInterface public class _ChildImpl extends _ParentImpl {}

如果我有课

@GenerateInterface
public class _FooImpl {}
我想生成一个接口

public interface Foo {}
它基本上包含了
\u FooImpl
的所有方法(即getter和setter)

如果我有继承权,比如

@GenerateInterface
public class _ParentImpl {}

@GenerateInterface
public class _ChildImpl extends _ParentImpl {}
这也会导致接口继承

public interface Parent {}

public interface Child extends Parent {}
我大致知道怎么做。但是如果
\u ParentImpl
是库的一部分呢?该库还必须包含父级

在注释处理器中,如何处理此问题?我无法再次生成
父接口
,因为这样我会有两次相同的接口。我是否可以检测到它已经存在,但可以将它与已经存在但不是库的一部分并因此可以被覆盖的文件区分开来


实际上,我只需要为一个类/接口使用这个函数,这个类/接口由其他任何函数扩展。因此,我可以从
\u ParentImpl
中删除
@GenerateInterface
,并对
父接口的继承进行硬编码。但这将是我最后的选择编辑:或者我可以设置
@Retention(RetentionPolicy.SOURCE)
,而不是完全删除接口,对吗?

已经编译的类不会再次处理。


我创建了一个完整的测试设置,并亲自探索了这个问题。事实证明,只有实际需要编译的文件才能通过注释处理运行。这意味着我可以安全地将
\u ParentImpl
Parent
包含在库中
\u ParentImpl
可以保留注释,然后可以使用
@Retention(RetentionPolicy.CLASS)
结合
@Inherited
以非常方便的方式将注释应用于子类。

接口不能扩展类。对于接口之间的继承,必须使用实现。例如:接口\子接口实现接口_Parent@DheerajRoy不,那不是真的。接口可以
彼此扩展
是的,接口可以彼此扩展,但接口不能扩展class@DheerajRoy没错。然而,我不想在任何地方这样做,因为你的问题还不清楚。你能简化你想做的事情吗?