为什么GWT的编辑器框架中的子编辑器需要是包私有的? [英] Why do sub-editors in GWT's editor framework need to be package-private?

查看:115
本文介绍了为什么GWT的编辑器框架中的子编辑器需要是包私有的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚尝试了 GWT的编辑框架和让它为一个小例子工作。但是我想知道为什么子编辑器需要是包私有的?



链接页面的示例中有一个注释,特别提到了包保护字段,但我找不到原因。

  //子包编辑器从包保护字段中检索,通常用UiBinder初始化。 
//许多编辑器中没有有趣的逻辑
public class PersonEditor扩展Dialog implements Editor< Person> {
标签名称编辑器;
AddressEditor addressEditor;
...
}

在我尝试自己的例子中,如果我的子编辑器是包私有的,如果我将它们设置为私有,绑定就不再起作用了。



任何人都可以向我解释为什么这个限制存在?这让我的编码风格显得有些不一致。感谢!

解决方案

类似于UiBinder, EditorDriver 的生成器生成类编辑器类。这些类需要访问编辑器来处理它们。



换句话说,编辑器框架不会修改你的类(没有魔法),所以你必须以某种方式暴露你的子编辑器:package-private已经足够了,但是 public 当然也能工作。

理解发生的最好方法是将 -gen 选项(后跟目录路径)传递给开发模式的GWT编译器,以便输出所有生成的类到磁盘。另外,如果你的编辑器在另一个包含子编辑器的包中扩展了一些其他的类(你想要的东西这个子编辑器必须从子类的包中可见,所以它必须在父类中是 public ,或者是由子类明确公开的(使用不是 private 的访问器方法)。


I've just tried out GWT's editor framework and got it working for a small example. But I was wondering why sub-editors need to be package-private?

There is a comment in an example in the linked page that specifically mentions package-protected fields, but I cannot find the reason why.

// Sub-editors are retrieved from package-protected fields, usually initialized with UiBinder.
// Many Editors have no interesting logic in them
public class PersonEditor extends Dialog implements Editor<Person> {
    Label nameEditor;
    AddressEditor addressEditor;
    ...
}

In the example I tried myself, I only got it working if my sub-editors are package-private, if i make them private, the binding does no longer work.

Can anyone explain to me why this restriction exists? It makes my coding style appear a bit inconsistently. Thanks!

解决方案

Similar to UiBinder, the generator for an EditorDriver generates classes along-side Editor classes. These classes need access to the editors to be able to work with them.

Put differently, the editor framework won't modify you classes (there's no magic), so you have to somehow expose your sub-editors: package-private is enough, but public would of course work too.
The best way to understand what's going on is to pass the -gen option (followed by a directory path) to the GWT compiler of dev mode, so that it outputs all the generated classes to disk. Be warned though: the editor framework is really hard to comprehend!

Also, if your editor extends some other class in another package that contains a sub-editor (that you want to inherit), that subeditor must be visible from the package of the child class, so it has to be public in the parent class, or be explicitly exposed by the child class (using an accessor method that's not private).

这篇关于为什么GWT的编辑器框架中的子编辑器需要是包私有的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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