我的问题涉及到编写JAXB插件,尤其是
ClassOutline
内部构件。
在里面
com.sun.tools.xjc.outline.ClassOutline
有以下字段:
-
目标
-
裁判
-
implClass类
-
implRef公司
代码:
/**
* This {@link ClassOutline} holds information about this {@link CClassInfo}.
*/
public final @NotNull CClassInfo target;
/**
* The exposed aspect of the a bean.
*
* implClass is always assignable to this type.
* <p>
* Usually this is the public content interface, but
* it could be the same as the implClass.
*/
public final @NotNull JDefinedClass ref;
/**
* The implementation aspect of a bean.
* The actual place where fields/methods should be generated into.
*/
public final @NotNull JDefinedClass implClass;
/**
* The implementation class that shall be used for reference.
* <p>
* Usually this field holds the same value as the {@link #implClass} method,
* but sometimes it holds the user-specified implementation class
* when it is specified.
* <p>
* This is the type that needs to be used for generating fields.
*/
public final @NotNull JClass implRef;
据我所知(
SO Answer
):
-
target
-在中保存信息
Model
,表示已解析和分析的架构文件(.xsd)
-
ref
通常等于
implClass
两者都成立
Code Model
-
implClass类
是放置新生成的字段、方法等的正确位置。
-
implRef
-这是什么?
我想向所描述的类添加新字段
类大纲
,因此代码如下所示:
JDefinedClass dstClass = classOutline.ref;
JFieldVar dstField = dstClass.field(srcField.mods().getValue(),
srcField.type(), srcField.name());
它工作得很好,直到有另一个插件在上面的代码被执行并使用之后才工作
com.sun.tools.xjc.outline.ClassOutline.getDeclaredFields()
方法
想象一下-
Plugin1
创建新字段,然后
CopyablePlugin
已执行并希望添加
clone()
方法,该方法复制每个字段。但是
CopyablePlugin
看不到新生成的字段
插件1
-因为要从中检索所有字段
类大纲
这个
可复制插件
使用
通用域名格式。太阳工具。xjc。概述类大纲。getDeclaredFields()
方法,如下所示:
/**
* Gets all the {@link FieldOutline}s newly declared
* in this class.
*/
public final FieldOutline[] getDeclaredFields() {
List<CPropertyInfo> props = target.getProperties();
// ...
请注意
getDeclaredFields()
从检索属性
ClassOutline.target
字段(这是
模型
-已解析的XSD架构),并完全忽略生成的代码
ClassOutline.implClass
.
这是一个bug还是一个特性?
现在我找到了解决办法。该字段也作为属性添加到
目标
:
classOutline.target.addProperty(prop);
问题
-
你能解释一下吗
ref/implClass/implRef
?
-
我应该在哪里生成全新的字段/方法?进入
ref/implClass
?
-
是否有必要保持
参考/implClass
和
目标
? 添加到的新字段
implClass类
还应添加到
目标
正当
-
是
通用域名格式。太阳工具。xjc。概述类大纲。getDeclaredFields()
对的或者如何正确地从ClassOutline检索所有字段?也许这应该是
目标
和
implClass类
所容纳之物