@@ -69,6 +69,8 @@ public class InstructionPrinter {
6969
7070 protected List <AbstractInsnNode > matchedInsns ;
7171 protected Map <LabelNode , Integer > labels ;
72+ private boolean firstLabel = false ;
73+ private ArrayList <String > info = new ArrayList <>();
7274
7375 public InstructionPrinter (MethodNode m , TypeAndName [] args ) {
7476 this .args = args ;
@@ -99,64 +101,17 @@ public InstructionPrinter(MethodNode m, InstructionPattern pattern,
99101 * @return The print as an ArrayList
100102 */
101103 public ArrayList <String > createPrint () {
102- ArrayList <String > info = new ArrayList <>();
104+ firstLabel = false ;
105+ info .clear ();
103106 ListIterator <?> it = mNode .instructions .iterator ();
104- boolean firstLabel = false ;
105107 while (it .hasNext ()) {
106108 AbstractInsnNode ain = (AbstractInsnNode ) it .next ();
107- String line = "" ;
108- if (ain instanceof VarInsnNode ) {
109- line = printVarInsnNode ((VarInsnNode ) ain );
110- } else if (ain instanceof IntInsnNode ) {
111- line = printIntInsnNode ((IntInsnNode ) ain );
112- } else if (ain instanceof FieldInsnNode ) {
113- line = printFieldInsnNode ((FieldInsnNode ) ain );
114- } else if (ain instanceof MethodInsnNode ) {
115- line = printMethodInsnNode ((MethodInsnNode ) ain );
116- } else if (ain instanceof LdcInsnNode ) {
117- line = printLdcInsnNode ((LdcInsnNode ) ain );
118- } else if (ain instanceof InsnNode ) {
119- line = printInsnNode ((InsnNode ) ain );
120- } else if (ain instanceof JumpInsnNode ) {
121- line = printJumpInsnNode ((JumpInsnNode ) ain );
122- } else if (ain instanceof LineNumberNode ) {
123- line = printLineNumberNode ();
124- } else if (ain instanceof LabelNode ) {
125- if (firstLabel
126- && BytecodeViewer .viewer .appendBracketsToLabels
127- .isSelected ())
128- info .add ("}" );
129-
130- line = printLabelnode ((LabelNode ) ain );
131-
132- if (BytecodeViewer .viewer .appendBracketsToLabels .isSelected ()) {
133- if (!firstLabel )
134- firstLabel = true ;
135- line += " {" ;
136- }
137- } else if (ain instanceof TypeInsnNode ) {
138- line = printTypeInsnNode ((TypeInsnNode ) ain );
139- } else if (ain instanceof FrameNode ) {
140- line = printFrameNode ((FrameNode ) ain );
141- } else if (ain instanceof IincInsnNode ) {
142- line = printIincInsnNode ((IincInsnNode ) ain );
143- } else if (ain instanceof TableSwitchInsnNode ) {
144- line = printTableSwitchInsnNode ((TableSwitchInsnNode ) ain );
145- } else if (ain instanceof LookupSwitchInsnNode ) {
146- line = printLookupSwitchInsnNode ((LookupSwitchInsnNode ) ain );
147- } else if (ain instanceof InvokeDynamicInsnNode ) {
148- line = printInvokeDynamicInsNode ((InvokeDynamicInsnNode ) ain );
149- } else if (ain instanceof MultiANewArrayInsnNode ) {
150- line = printMultiANewArrayInsNode ((MultiANewArrayInsnNode ) ain );
151- } else {
152- line += "UNADDED OPCODE: " + nameOpcode (ain .getOpcode ()) + " "
153- + ain ;
154- }
109+ String line = printInstruction (ain );
155110 if (!line .isEmpty ()) {
156111 if (match )
157112 if (matchedInsns .contains (ain ))
158113 line = " -> " + line ;
159-
114+
160115 info .add (line );
161116 }
162117 }
@@ -165,6 +120,60 @@ public ArrayList<String> createPrint() {
165120 info .add ("}" );
166121 return info ;
167122 }
123+
124+ public String printInstruction (AbstractInsnNode ain )
125+ {
126+ String line = "" ;
127+ if (ain instanceof VarInsnNode ) {
128+ line = printVarInsnNode ((VarInsnNode ) ain );
129+ } else if (ain instanceof IntInsnNode ) {
130+ line = printIntInsnNode ((IntInsnNode ) ain );
131+ } else if (ain instanceof FieldInsnNode ) {
132+ line = printFieldInsnNode ((FieldInsnNode ) ain );
133+ } else if (ain instanceof MethodInsnNode ) {
134+ line = printMethodInsnNode ((MethodInsnNode ) ain );
135+ } else if (ain instanceof LdcInsnNode ) {
136+ line = printLdcInsnNode ((LdcInsnNode ) ain );
137+ } else if (ain instanceof InsnNode ) {
138+ line = printInsnNode ((InsnNode ) ain );
139+ } else if (ain instanceof JumpInsnNode ) {
140+ line = printJumpInsnNode ((JumpInsnNode ) ain );
141+ } else if (ain instanceof LineNumberNode ) {
142+ line = printLineNumberNode ();
143+ } else if (ain instanceof LabelNode ) {
144+ if (firstLabel
145+ && BytecodeViewer .viewer .appendBracketsToLabels
146+ .isSelected ())
147+ info .add ("}" );
148+
149+ line = printLabelnode ((LabelNode ) ain );
150+
151+ if (BytecodeViewer .viewer .appendBracketsToLabels .isSelected ()) {
152+ if (!firstLabel )
153+ firstLabel = true ;
154+ line += " {" ;
155+ }
156+ } else if (ain instanceof TypeInsnNode ) {
157+ line = printTypeInsnNode ((TypeInsnNode ) ain );
158+ } else if (ain instanceof FrameNode ) {
159+ line = printFrameNode ((FrameNode ) ain );
160+ } else if (ain instanceof IincInsnNode ) {
161+ line = printIincInsnNode ((IincInsnNode ) ain );
162+ } else if (ain instanceof TableSwitchInsnNode ) {
163+ line = printTableSwitchInsnNode ((TableSwitchInsnNode ) ain );
164+ } else if (ain instanceof LookupSwitchInsnNode ) {
165+ line = printLookupSwitchInsnNode ((LookupSwitchInsnNode ) ain );
166+ } else if (ain instanceof InvokeDynamicInsnNode ) {
167+ line = printInvokeDynamicInsNode ((InvokeDynamicInsnNode ) ain );
168+ } else if (ain instanceof MultiANewArrayInsnNode ) {
169+ line = printMultiANewArrayInsNode ((MultiANewArrayInsnNode ) ain );
170+ } else {
171+ line += "UNADDED OPCODE: " + nameOpcode (ain .getOpcode ()) + " "
172+ + ain ;
173+ }
174+
175+ return line ;
176+ }
168177
169178 protected String printVarInsnNode (VarInsnNode vin ) {
170179 StringBuilder sb = new StringBuilder ();
0 commit comments