The algorithm that DiagramMaker uses to analyze example files is relatively simple. Each example file is compiled an in current prototype hard-coded to be displayed in the list box. When example files are selected and Draw Diagram button has been pressed, selected files are loaded into JVM (Java Virtual Machine). DiagramMaker uses Java reflection and introspection API to analyze selected class files. Reflection and introspection technology allows Java programs to analyze the structure of Java classes. For example, one can find out what fields and methods are declared by the class or get an instance of that class by specifying class name as a string.
For each example file, new object is constructed that represents an IC Card. IC Card name is set to the name of that class. The list of incoming messages is simply the list of declared methods that this class has. The list of other ICs is the list of non-primitive fields that this class declares. The list of outgoing messages is the list of declared method in each of non-primitive fields that are declared in example class.
After IC Card object has been constructed, it is added to the display panel. Then each IC Card is examined to see if it contains outgoing messages to other IC Cards that are displayed. If that is the case, the line is drawn between two ICs and the list of messages is printed in the middle of that line. If IC Card has an outgoing message to some other IC, then its task is set to color yellow (the task is being performed with help of other IC Cards). If IC Card does not have any outgoing messages to other ICs, then its task color is set to green (IC Card performs a task by itself).
Here is the source code for DiagramMaker: DiagramMaker.java
, DisplayPanel.java, ICCard.java
Here is the source code for example files: Controller.java
, Model.java , Singleton.java,
View.java