1 30 31 package oracle.toplink.libraries.asm.tree; 32 33 import oracle.toplink.libraries.asm.ClassVisitor; 34 import oracle.toplink.libraries.asm.CodeVisitor; 35 import oracle.toplink.libraries.asm.Label; 36 import oracle.toplink.libraries.asm.Attribute; 37 38 import java.util.List ; 39 import java.util.ArrayList ; 40 import java.util.Arrays ; 41 42 47 48 public class MethodNode { 49 50 54 55 public int access; 56 57 60 61 public String name; 62 63 66 67 public String desc; 68 69 74 75 public final List exceptions; 76 77 80 81 public Attribute attrs; 82 83 87 88 public final List instructions; 89 90 94 95 public final List tryCatchBlocks; 96 97 100 101 public int maxStack; 102 103 106 107 public int maxLocals; 108 109 113 114 public final List localVariables; 115 116 120 121 public final List lineNumbers; 122 123 126 127 public Attribute codeAttrs; 128 129 143 144 public MethodNode ( 145 final int access, 146 final String name, 147 final String desc, 148 final String [] exceptions, 149 final Attribute attrs) 150 { 151 this.access = access; 152 this.name = name; 153 this.desc = desc; 154 this.exceptions = new ArrayList (); 155 this.instructions = new ArrayList (); 156 this.tryCatchBlocks = new ArrayList (); 157 this.localVariables = new ArrayList (); 158 this.lineNumbers = new ArrayList (); 159 if (exceptions != null) { 160 this.exceptions.addAll(Arrays.asList(exceptions)); 161 } 162 this.attrs = attrs; 163 } 164 165 170 171 public void accept (final ClassVisitor cv) { 172 String [] exceptions = new String [this.exceptions.size()]; 173 this.exceptions.toArray(exceptions); 174 CodeVisitor mv = cv.visitMethod(access, name, desc, exceptions, attrs); 175 if (mv != null && instructions.size() > 0) { 176 int i; 177 for (i = 0; i < instructions.size(); ++i) { 179 Object insn = instructions.get(i); 180 if (insn instanceof Label) { 181 mv.visitLabel((Label)insn); 182 } else { 183 ((AbstractInsnNode)insn).accept(mv); 184 } 185 } 186 for (i = 0; i < tryCatchBlocks.size(); ++i) { 188 ((TryCatchBlockNode)tryCatchBlocks.get(i)).accept(mv); 189 } 190 mv.visitMaxs(maxStack, maxLocals); 192 for (i = 0; i < localVariables.size(); ++i) { 194 ((LocalVariableNode)localVariables.get(i)).accept(mv); 195 } 196 for (i = 0; i < lineNumbers.size(); ++i) { 198 ((LineNumberNode)lineNumbers.get(i)).accept(mv); 199 } 200 Attribute attrs = codeAttrs; 202 while (attrs != null) { 203 mv.visitAttribute(attrs); 204 attrs = attrs.next; 205 } 206 } 207 } 208 } 209 | Popular Tags |