私の質問は、JAXB プラグイン、特にClassOutline
内部の記述に関するものです。
フィールドcom.sun.tools.xjc.outline.ClassOutline
があります:
- 目標
- 参照
- 実装クラス
- 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
- それは何ですか?
で記述されたクラスに新しいフィールドを追加したいClassOutline
ので、コードは次のようになります。
JDefinedClass dstClass = classOutline.ref;
JFieldVar dstField = dstClass.field(srcField.mods().getValue(),
srcField.type(), srcField.name());
上記のコードが実行され、com.sun.tools.xjc.outline.ClassOutline.getDeclaredFields()
メソッドを使用した後に機能する別のプラグインがあるまで、それはうまく機能します。
想像してみてください-Plugin1
新しいフィールドを作成し、次にCopyablePluginclone()
が実行され、すべてのフィールドをコピーするメソッドを追加したいと考えています。ただし、次のようなusesメソッドからすべてのフィールドを取得するため、-CopyablePlugin
によって新しく生成されたフィールドは表示されません。Plugin1
ClassOutline
CopyablePlugin
com.sun.tools.xjc.outline.ClassOutline.getDeclaredFields()
/**
* Gets all the {@link FieldOutline}s newly declared
* in this class.
*/
public final FieldOutline[] getDeclaredFields() {
List<CPropertyInfo> props = target.getProperties();
// ...
これは、フィールド (これは- 解析された XSD スキーマです)getDeclaredFields()
からプロパティを取得し、 に生成されたコードを完全に無視することに注意してください。ClassOutline.target
Model
ClassOutline.implClass
それはバグですか、それとも機能ですか?
今のところ、回避策を見つけました。同じフィールドがプロパティとして にも追加されますtarget
:
classOutline.target.addProperty(prop);
質問
- の役割を教えてください
ref/implClass/implRef
。 - 完全に新しいフィールド/メソッドをどこで生成する必要がありますか?
ref/implClass
に? - との間で一貫性を保つ必要が
ref/implClass
ありtarget
ますか? に追加された新しいフィールドimplClass
は にも追加されるべきtarget
ですよね? - 正しい
com.sun.tools.xjc.outline.ClassOutline.getDeclaredFields()
ですか?または、ClassOutline からすべてのフィールドを適切に取得するにはどうすればよいですか? たぶん、これはtarget
とimplClass
コンテンツの結合である必要がありますか?