Generating part reference statistics

EGL includes four Java™ classes that you can use to create a log of parts referenced by a program.

Use the PartInfoFactory class to generate part reference statistics within the Eclipse IDE; use the GenerationServer class in combination with the EGLSDK class to generate a log outside of the IDE.

PartInfoFactory

The PartInfoFactory class is found in the following location:
com.ibm.etools.egl.ui.parts.PartInfoFactory

The PartInfoFactory class includes the following methods:

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
The array that getReferencePartList() returns, containing the first main part in eglFile and its referenced parts.
eglFile
The file that contains the part for which you are generating reference statistics.
removeUnusedMembers
Specifies whether unused parts should be eliminated from the list of returned parts.
The following example retrieves a part list from the genPart.egl file and stores the list in IPartInfo:
IPartInfo[] parts = PartInfoFactory.getReferencePartList(genPart); 

GenerationServer

The GenerationServer class is found in the following location:
com.ibm.etools.egl.GenerationServer

The GenerationServer class includes the following methods:

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

enableGeneration allows the setting of a boolean true or false flag to indicate whether generation of the part is to occur. The default is true. If you set the value to false before invoking the EGLSDK, you can parse and build a list of parts related to an EGL source, without causing subsequent generation to occur.

listener
An instance of the IGenerationListener interface. See "IGenerationListener interface" in this topic.
public static IPartInfo[] getAllUniqueReferencedParts(
                             IPartInfo[] parts)
public static IElementInfo[] getAllUniqueReferecedElements(
                                IElementInfo[] elements)
parts
an array of parts, used to create an array of all referenced parts. All parts in the array are unique.
elements
an array of elements, used to create an array of all referenced parts, nested functions, referenced programs, and other elements. All elements in the array are unique.
The following example calls the EGLSDK class from within a Java program to invoke EGL generation outside the Eclipse IDE.
GenerationServer.addListener(listener);
com.ibm.etools.egl.util.EGLSDK eglsdk = new com.ibm.etools.egl.util.EGLSDK();
GenerationServer.removeListener(listener); 

IGenerationListener interface

The IGenerationListener interface includes the following methods:

begin()
Invoked at the beginning of generation for a given part.
acceptGeneratedPart(part)
Provides notification that part was generated. This method may be called multiple times for a single generation if you are generating associated parts (DataTables and FormGroups).
acceptAssociatedPart(part)
Provides notification that part was encountered during generation.
end()
Invoked at the end of generation for a given part.

IPartInfo interface

The IPartInfo interface includes the following methods:

getPackageName()
Returns the packagename of the part. The name will be a '.' delimited string of packages.
getResourceName()
Returns the full pathname of the file that the part is defined in.
getSource()
Returns the EGL source text for this part, which could be a program, function, record or other part. This method requires that the EGL part has been built and relies on the accuracy of the EGL compiled IR.
getSource(Set resources, List partList)
Returns the EGL source text for this part, which could be a program, function, record or other part. This method does not requires that the EGL part has been built and will cause a parsing of this part's EGL source during the call.

Typically, a new Set and ArrayList are obtained and then released surrounding the logic to process all parts in the action. For example,

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();
    }
  }

Feedback