Code Sequence Diagram Cleanup

This commit is contained in:
Konloch 2021-07-06 13:34:29 -07:00
parent be2896ee3e
commit dd4bec1446

View file

@ -42,7 +42,8 @@ import the.bytecode.club.bytecodeviewer.plugin.PluginManager;
* @author Konloch * @author Konloch
*/ */
public class CodeSequenceDiagram extends Plugin { public class CodeSequenceDiagram extends Plugin
{
public static void open() public static void open()
{ {
if (BytecodeViewer.getLoadedClasses().isEmpty()) if (BytecodeViewer.getLoadedClasses().isEmpty())
@ -54,21 +55,22 @@ public class CodeSequenceDiagram extends Plugin {
} }
@Override @Override
public void execute(ArrayList<ClassNode> classNodeList) { public void execute(ArrayList<ClassNode> classNodeList)
if (BytecodeViewer.viewer.workPane.getCurrentViewer() == null || !(BytecodeViewer.viewer.workPane.getCurrentViewer() instanceof ClassViewer)) { {
if (BytecodeViewer.viewer.workPane.getCurrentViewer() == null || !(BytecodeViewer.viewer.workPane.getCurrentViewer() instanceof ClassViewer))
{
BytecodeViewer.showMessage("First open a class file."); BytecodeViewer.showMessage("First open a class file.");
return; return;
} }
ClassNode c = BytecodeViewer.viewer.workPane.getCurrentViewer().cn; ClassNode c = BytecodeViewer.viewer.workPane.getCurrentViewer().cn;
if (c == null) { if (c == null)
BytecodeViewer.showMessage("ClassNode is null for CodeSequenceDiagram. Please report to @Konloch"); {
BytecodeViewer.showMessage("Current viewer ClassNode is null inside of CodeSequenceDiagram. Please report to @Konloch");
return; return;
} }
JFrame frame;
if (c.name != null) JFrame frame = new JFrame("Code Sequence Diagram - " + c.name);
frame = new JFrame("Code Sequence Diagram - " + c.name);
else
frame = new JFrame("Code Sequence Diagram - Unknown Name");
frame.setIconImages(Resources.iconList); frame.setIconImages(Resources.iconList);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
@ -87,32 +89,37 @@ public class CodeSequenceDiagram extends Plugin {
FontRenderContext frc = new FontRenderContext(affinetransform, true, true); FontRenderContext frc = new FontRenderContext(affinetransform, true, true);
graph.getModel().beginUpdate(); graph.getModel().beginUpdate();
try { try
{
int testX = 10; int testX = 10;
int testY = 0; int testY = 0;
double magicNumber = 5.8; double magicNumber = 5.8;
for (MethodNode m : c.methods) { for (MethodNode m : c.methods)
{
String mIdentifier = c.name + "." + m.name + m.desc; String mIdentifier = c.name + "." + m.name + m.desc;
Object attach = graph.insertVertex(parent, null, mIdentifier, testX, testY, Object attach = graph.insertVertex(parent, null, mIdentifier, testX, testY,
mIdentifier.length() * magicNumber, 30); mIdentifier.length() * magicNumber, 30);
testX += (int) (font.getStringBounds(mIdentifier, frc).getWidth()) + 60; testX += (int) (font.getStringBounds(mIdentifier, frc).getWidth()) + 60;
for (AbstractInsnNode i : m.instructions.toArray()) { for (AbstractInsnNode i : m.instructions.toArray())
if (i instanceof MethodInsnNode) { {
if (i instanceof MethodInsnNode)
{
MethodInsnNode mi = (MethodInsnNode) i; MethodInsnNode mi = (MethodInsnNode) i;
String identifier = mi.owner + "." + mi.name + mi.desc; String identifier = mi.owner + "." + mi.name + mi.desc;
Object node2 = graph.insertVertex(parent, null, identifier, testX, testY, Object node2 = graph.insertVertex(parent, null, identifier, testX, testY, identifier.length() * 5, 30);
identifier.length() * 5, 30);
testX += (int) (font.getStringBounds(identifier, frc).getWidth()) + 60; testX += (int) (font.getStringBounds(identifier, frc).getWidth()) + 60;
graph.insertEdge(parent, null, null, attach, node2); graph.insertEdge(parent, null, null, attach, node2);
attach = node2; attach = node2;
} }
} }
testY += 60; testY += 60;
testX = 10; testX = 10;
} }
} finally { }
finally
{
graph.getModel().endUpdate(); graph.getModel().endUpdate();
} }