1

私の質問は、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によって新しく生成されたフィールドは表示されません。Plugin1ClassOutlineCopyablePlugincom.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.targetModelClassOutline.implClass

それはバグですか、それとも機能ですか?

今のところ、回避策を見つけました。同じフィールドがプロパティとして にも追加されますtarget:

classOutline.target.addProperty(prop);

質問

  1. の役割を教えてくださいref/implClass/implRef
  2. 完全に新しいフィールド/メソッドをどこで生成する必要がありますか? ref/implClassに?
  3. との間で一貫性を保つ必要がref/implClassありtargetますか? に追加された新しいフィールドimplClassは にも追加されるべきtargetですよね?
  4. 正しいcom.sun.tools.xjc.outline.ClassOutline.getDeclaredFields()ですか?または、ClassOutline からすべてのフィールドを適切に取得するにはどうすればよいですか? たぶん、これはtargetimplClassコンテンツの結合である必要がありますか?
4

1 に答える 1