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

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

问题描述

我怎样才能使用GWT生成器通过批注而不是接口标记?



例如:我有一个视图与一些ui字段,如按钮和文本框。现在我想要字段,其中有注解@Hide(true),被setVisible(false)方法隐藏。

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

解决方案

GWT生成器由一个类型触发(传递给 GWT.create()),所以虽然可以通过匹配的注释来调用,但注释必须位于类型本身上,而不是字段上。此外,更重要的是,这不会发生: https://github.com/gwtproject/gwt / issues / 9172

IMO应该使用一个注释处理器来生成一个调用 setVisible 在相应的字段上,类似于当其调用 generateAndBindUi 方法时生成的UiBinder设置字段的方式。所以你可以调用UiBinder(如果你使用它),然后调用你生成的帮助类(或者可能让帮助类为你处理UiBinder位)。


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

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.

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?

解决方案

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, 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天全站免登陆