パーツ参照統計の生成

EGL には、プログラムによって参照されるパーツのログを作成するために使用できる 4 つの Java™ クラスが 組み込まれています。

Eclipse IDE 内のパーツ参照統計を生成するには、PartInfoFactory クラスを使用します。IDE 外のログを生成するには、GenerationServer クラスを EGLSDK クラスとともに使用します。

PartInfoFactory

PartInfoFactory クラスは、次の場所にあります。
com.ibm.etools.egl.ui.parts.PartInfoFactory

PartInfoFactory クラスには、以下のメソッドが含まれています。

public static IPartInfo[] getReferencePartList(IFile eglFile)
                 throws Exception
public static IPartInfo[] getReferencePartList(IFile eglFile,
                 boolean removeUnusedMembers)
                 throws Exception
public static IPartInfo[] getReferenceElementsList(IFile eglFile)
                 throws Exception
public static IPartInfo[] getReferenceElementsList(IFile eglFile,
                 boolean removeUnusedMembers)
                 throws Exception
IPartInfo
getReferencePartList() が戻す配列。eglFile 内の最初のメイン・パーツと、その参照先パーツが入っています。
eglFile
参照統計を生成する対象のパーツを含むファイル。
removeUnusedMembers
戻されるパーツのリストから使用されていないパーツを除去するかどうかを指定します。
次の例は、genPart.egl ファイルからパーツ・リストを取得して、IPartInfo のリストに保存します。
IPartInfo[] parts = PartInfoFactory.getReferencePartList(genPart); 

GenerationServer

GenerationServer クラスは、次の場所にあります。
com.ibm.etools.egl.GenerationServer

GenerationServer クラスには、以下のメソッドが含まれています。

public static void addListener(IGenerationListener listener)
public static void removeListener(IGenerationListener listener)
public static void enableGeneration (boolean flag)

enableGeneration を使用すると、パーツの生成を行うかどうかを指示するブール値の true または false フラグを設定することができます。 デフォルトは true です。EGLSDK を呼び出す前に値を false に設定した場合は、これ以降に生成を行うことなく、EGL ソースに関連するパーツの構文解析および作成を行うことができます。

listener
IGenerationListener インターフェースのインスタンス。このトピックの『IGenerationListener インターフェース』を参照してください。
public static IPartInfo[] getAllUniqueReferencedParts(
                             IPartInfo[] parts)
public static IElementInfo[] getAllUniqueReferecedElements(
                                IElementInfo[] elements)
parts
パーツの配列。すべての参照先パーツの配列を作成するために使用されます。 配列内のすべてのパーツは固有です。
elements
要素の配列。参照先パーツ、ネストされた関数、参照先プログラム、およびその他の要素すべての配列を作成するために使用されます。 配列内のすべての要素は固有です。
次の例は、Java プログラム内から EGLSDK クラスを呼び出して、Eclipse IDE 外の EGL 生成を起動します。
GenerationServer.addListener(listener);
com.ibm.etools.egl.util.EGLSDK eglsdk = new com.ibm.etools.egl.util.EGLSDK();
GenerationServer.removeListener(listener); 

IGenerationListener インターフェース

IGenerationListener インターフェースには、以下のメソッドが含まれています。

begin()
特定パーツの生成開始時に呼び出されます。
acceptGeneratedPart(part)
part が生成されたという通知を提供します。関連パーツ (DataTables および FormGroups) を生成している場合、単一の生成に対してこのメソッドが複数回呼び出される場合があります。
acceptAssociatedPart(part)
生成中に part を検出したという通知を生成します。
end()
特定パーツの生成終了時に呼び出されます。

IPartInfo インターフェース

IPartInfo インターフェースには、以下のメソッドが含まれています。

getPackageName()
パーツのパッケージ名を返します。 名前は「.」で区切られたパッケージのストリングになります。
getResourceName()
パーツが定義されているファイルの絶対パス名を返します。
getSource()
このパーツの EGL ソース・テキスト (プログラム、関数、レコードその他のパーツ) を返します。 このメソッドは、EGL パーツが作成済みであり、EGL コンパイル IR の正確性に依存していることを必要とします。
getSource(Set resources, List partList)
このパーツの EGL ソース・テキスト (プログラム、関数、レコードその他のパーツ) を返します。 このメソッドは、EGL パーツが作成済みであることを必要とせず、呼び出し中にこのパーツの EGL ソースの構文解析を行います。

一般に、アクションにおいてすべてのパーツを処理するロジックの前後で、新しい Set および ArrayList が取得され、解放されます。 例えば、次のようになります。

public void run(IAction action) {
    resources = new HashSet();
    partList = new ArrayList();
    Iterator selectionIterator = this.selection.iterator();
    while (selectionIterator.hasNext()) {
       Object object = selectionIterator.next();
       if ((object instanceof IEGLFile)) {
          IEGLFile iEglFile = (IEGLFile) object;
          try {
             IFile eglFile = ResourcesPlugin.getWorkspace().getRoot().getFile(iEglFile.getUnderlyingResource().getFullPath());
             IPartInfo[] associatedParts = PartInfoFactory.getReferencePartList(eglFile);
             generateEglSourceFile(associatedParts, eglFile);
          } catch (Exception e) {
             e.printStackTrace();
          }
       }
    }
    resources = null;
    partList = null;
}
private static void generateEsf(IPartInfo[] associatedParts, IFile eglFile) {
    ....
    associatedParts = GenerationServer.getAllUniqueReferecedParts(associatedParts);
    try {
      BufferedWriter out = new BufferedWriter(new FileWriter(outFile, false));
      for (int i = 0; i < associatedParts.length; i++) {
        out.write(associatedParts[i].getSource(resources, partList));
        out.write("¥n");
      }
      out.close();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

フィードバック