XJC生成另一种字段类型(对get方法的影响)
使用最新的 JAXB (Metro) 并使用 XJC 生成 Java...
想要(正如其他用户所要求的那样)生成 java.util.Set 作为表示无界序列的字段的类型。看起来该类型的字段被 XJC 捕获为 UntypedListField,默认行为是生成 java.util.List(仅 getter)。如果我执行类似于 collection-setter-injector 插件的操作并调整字段的类型,例如
public boolean run(Outline model, Options opt, ErrorHandler errorHandler) {
for (ClassOutline co : model.getClasses()) {
FieldOutline[] fo = co.getDeclaredFields();
for ...
if ((fo[i] instanceof UntypedListField)) {
--> DO SOMETHING WITH THIS FIELD
}
}
}
人们如何调整类型,或者构建新字段是否更容易,然后将其替换为类大纲中声明的字段集?弄乱字段的类型如何影响属性上 get 方法的生成?
Using the latest JAXB (Metro) and generating Java with XJC....
Want to (as other users have asked) generate java.util.Set as a type for fields that represent unbounded sequences. Looks like that type of field is captured by XJC as a UntypedListField and the default behavior is to generate java.util.List (only the getter). If I do something similar to the collection-setter-injector plugin and adjust the field's type like
public boolean run(Outline model, Options opt, ErrorHandler errorHandler) {
for (ClassOutline co : model.getClasses()) {
FieldOutline[] fo = co.getDeclaredFields();
for ...
if ((fo[i] instanceof UntypedListField)) {
--> DO SOMETHING WITH THIS FIELD
}
}
}
How do people adjust the type or is it easier to construct a new field then replace it in the set of declared fields in the class outline? How does messing with the field's type effect the generation of the get method on the property?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您要使用自己的 XJC 插件。这就是你需要做的。替换您的
-->使用此字段执行以下操作
行并执行以下操作。首先,弄清楚 fo[i] 的参数化类型是什么(我称之为 f)。
然后,创建 Set JType。最后将
f
的类型设置为setType
:narrow()
方法用于设置参数化类型。到目前为止看起来不错,但问题是该插件将在 XJC 生成类完成后运行。这意味着吸气剂已经存在。所以我们需要更换它。
这是
replaceGetter()
方法希望您觉得这有帮助。
Looks like you're going for your own XJC Plugin. So here's what you need to do. Replace your
--> DO SOMETHING WITH THIS FIELD
line with the following.First, figure out what's the parameterization type of
fo[i]
(which I'm calling f).Then, create the Set JType. And finally set the type of
f
tosetType
:The method
narrow()
is used to set the parametrization type.Looks good so far, the problem however is that the plugin will run after XJC is done generating the classes. Which means that the getter is already there. So we need to replace it.
And here's the
replaceGetter()
methodHope you find this helpful.