使用 GWT 生成器进行自定义注释 [英] Using GWT Generators for custom annotations

查看:35
本文介绍了使用 GWT 生成器进行自定义注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过注释而不是界面标记来使用 GWT 生成器?

How can i use GWT generator by annotations instead interface marker?

例如:我有一个带有一些 ui 字段的视图,如按钮和文本框.现在我想要带有注释 @Hide("true") 的字段被 "setVisible(false)" 方法隐藏.

For example: i have a View with some ui fields, like Buttons and TextBoxes. Now i want to fields, which have annotation @Hide("true"), was hidden by "setVisible(false)" method.

我应该在 GWT 模块 xml 文件中使用注释类型而不是接口吗?或者我必须生成我所有的 View 类,解析它,检查注释并在构造函数中调用 setVisible(true) 生成新的 View?或者也许有其他方法可以做到这一点?

Should i use annotation type instead interface in GWT module xml file? Or i have to generate all my View class, parse it, check annotations and generate new View with invoke setVisible(true) in constructor? Or maybe is there some other way to do this?

推荐答案

GWT 生成器由类型触发(传递给 GWT.create()),因此虽然它可以被一个匹配注释,该注释必须在类型本身上,而不是在字段上.此外,更重要的是,这不会发生:https://github.com/gwtproject/gwt/issues/9172

A GWT generator is triggered by a type (passed to GWT.create()), so while it could be called by a matching annotation, that annotation would have to be on the type itself, not on a field. Also, and more importantly, that's not going to happen: https://github.com/gwtproject/gwt/issues/9172

IMO,您应该使用一个注解处理器生成一个辅助类,该类在适当的字段上调用 ​​setVisible,类似于生成的 UiBinder 在其 generateAndBindUi 方法为叫.所以你会调用 UiBinder(如果你使用它),然后调用你生成的帮助类(或者可能让帮助类为你处理 UiBinder 位).

IMO, you should use an annotation processor generating a helper class that calls setVisible on the appropriate fields, similar to how generated UiBinder sets the fields when its generateAndBindUi method is called. So you'd call UiBinder (if you use it), then call your generated helper class (or possibly have the helper class handle the UiBinder bit for you).

这篇关于使用 GWT 生成器进行自定义注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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