1 34 35 package org.logicalcobwebs.asm.tree; 36 37 import org.logicalcobwebs.asm.ClassVisitor; 38 import org.logicalcobwebs.asm.CodeVisitor; 39 import org.logicalcobwebs.asm.Label; 40 import org.logicalcobwebs.asm.Attribute; 41 42 import java.util.List ; 43 import java.util.ArrayList ; 44 import java.util.Arrays ; 45 46 49 50 public class MethodNode { 51 52 56 57 public int access; 58 59 62 63 public String name; 64 65 68 69 public String desc; 70 71 76 77 public final List exceptions; 78 79 82 83 public Attribute attrs; 84 85 89 90 public final List instructions; 91 92 96 97 public final List tryCatchBlocks; 98 99 102 103 public int maxStack; 104 105 108 109 public int maxLocals; 110 111 115 116 public final List localVariables; 117 118 122 123 public final List lineNumbers; 124 125 128 129 public Attribute codeAttrs; 130 131 145 146 public MethodNode ( 147 final int access, 148 final String name, 149 final String desc, 150 final String [] exceptions, 151 final Attribute attrs) 152 { 153 this.access = access; 154 this.name = name; 155 this.desc = desc; 156 this.exceptions = new ArrayList (); 157 this.instructions = new ArrayList (); 158 this.tryCatchBlocks = new ArrayList (); 159 this.localVariables = new ArrayList (); 160 this.lineNumbers = new ArrayList (); 161 if (exceptions != null) { 162 this.exceptions.addAll(Arrays.asList(exceptions)); 163 } 164 this.attrs = attrs; 165 } 166 167 172 173 public void accept (final ClassVisitor cv) { 174 String [] exceptions = new String [this.exceptions.size()]; 175 this.exceptions.toArray(exceptions); 176 CodeVisitor mv = cv.visitMethod(access, name, desc, exceptions, attrs); 177 if (mv != null && instructions.size() > 0) { 178 int i; 179 for (i = 0; i < instructions.size(); ++i) { 181 Object insn = instructions.get(i); 182 if (insn instanceof Label) { 183 mv.visitLabel((Label)insn); 184 } else { 185 ((AbstractInsnNode)insn).accept(mv); 186 } 187 } 188 for (i = 0; i < tryCatchBlocks.size(); ++i) { 190 ((TryCatchBlockNode)tryCatchBlocks.get(i)).accept(mv); 191 } 192 mv.visitMaxs(maxStack, maxLocals); 194 for (i = 0; i < localVariables.size(); ++i) { 196 ((LocalVariableNode)localVariables.get(i)).accept(mv); 197 } 198 for (i = 0; i < lineNumbers.size(); ++i) { 200 ((LineNumberNode)lineNumbers.get(i)).accept(mv); 201 } 202 Attribute attrs = codeAttrs; 204 while (attrs != null) { 205 mv.visitAttribute(attrs); 206 attrs = attrs.next; 207 } 208 } 209 } 210 } 211 | Popular Tags |