是否可以将Lombok注释用作元注释? [英] Is it possible to use Lombok annotations as a meta-annotation?

查看:199
本文介绍了是否可以将Lombok注释用作元注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为传输对象定义自己的注释,并在其中包含一些Lombok注释作为元注释:

I want to define my own annotation for transfer objects and include there some Lombok annotations as meta-annotations:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Data
@NoArgsConstructor
@AllArgsConstructor
public @interface TransferObject {
}

目的是用@TransferObject注释我的所有传输对象,并继承"以上所有内容.实际上,这是行不通的,Lombok不会处理带有@TransferObject注释的类.

The intent is to annotate all my transfer objects with @TransferObject and "inherit" all of the above. In practice it doesn't work, classes annotated with @TransferObject are not processed by Lombok.

是否有某种方法可以使它正常工作?如果没有,从理论上讲,可以增强Lombok来查找元注释吗?

Is there some way to get this working? If not, it it theoretically possible to enhance Lombok to look for meta-annotations?

注意:我使用的是Java 8.

Note: I'm on Java 8.

更新:看起来在github上有一个功能请求.

UPDATE: It looks like there's a feature request for this on github.

推荐答案

简短回答不是(对于当前版本1.18.4-2018年10月30日)

Short answer is NOT (for current version 1.18.4 - Oct 30, 2018)

根据线程此处:

此功能需要在处理的早期阶段进行解析.目前这是不可能的.可能是因为我们现在有了lombok配置系统,所以我们可能会提出不同的解决方案.

This feature would require resolution in a very early stage of processing. Currently that is not possible. Possibly, since we now have the lombok configuration system, we might come up with a different solution.

实际上,他们在Lombok的

Actually, they have several requests of the similar functionality on Lombok's GitHub page - non of them is implemented.

请考虑批准功能或

Please consider upvoting this feature or this one.

这篇关于是否可以将Lombok注释用作元注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆