1 34 35 package org.logicalcobwebs.asm.tree; 36 37 import org.logicalcobwebs.asm.CodeAdapter; 38 import org.logicalcobwebs.asm.Label; 39 import org.logicalcobwebs.asm.Attribute; 40 41 47 48 public class TreeCodeAdapter extends CodeAdapter { 49 50 53 54 public MethodNode methodNode; 55 56 62 63 public TreeCodeAdapter (final MethodNode methodNode) { 64 super(null); 65 this.methodNode = methodNode; 66 } 67 68 public void visitInsn (final int opcode) { 69 AbstractInsnNode n = new InsnNode(opcode); 70 methodNode.instructions.add(n); 71 } 72 73 public void visitIntInsn (final int opcode, final int operand) { 74 AbstractInsnNode n = new IntInsnNode(opcode, operand); 75 methodNode.instructions.add(n); 76 } 77 78 public void visitVarInsn (final int opcode, final int var) { 79 AbstractInsnNode n = new VarInsnNode(opcode, var); 80 methodNode.instructions.add(n); 81 } 82 83 public void visitTypeInsn (final int opcode, final String desc) { 84 AbstractInsnNode n = new TypeInsnNode(opcode, desc); 85 methodNode.instructions.add(n); 86 } 87 88 public void visitFieldInsn ( 89 final int opcode, 90 final String owner, 91 final String name, 92 final String desc) 93 { 94 AbstractInsnNode n = new FieldInsnNode(opcode, owner, name, desc); 95 methodNode.instructions.add(n); 96 } 97 98 public void visitMethodInsn ( 99 final int opcode, 100 final String owner, 101 final String name, 102 final String desc) 103 { 104 AbstractInsnNode n = new MethodInsnNode(opcode, owner, name, desc); 105 methodNode.instructions.add(n); 106 } 107 108 public void visitJumpInsn (final int opcode, final Label label) { 109 AbstractInsnNode n = new JumpInsnNode(opcode, label); 110 methodNode.instructions.add(n); 111 } 112 113 public void visitLabel (final Label label) { 114 methodNode.instructions.add(label); 115 } 116 117 public void visitLdcInsn (final Object cst) { 118 AbstractInsnNode n = new LdcInsnNode(cst); 119 methodNode.instructions.add(n); 120 } 121 122 public void visitIincInsn (final int var, final int increment) { 123 AbstractInsnNode n = new IincInsnNode(var, increment); 124 methodNode.instructions.add(n); 125 } 126 127 public void visitTableSwitchInsn ( 128 final int min, 129 final int max, 130 final Label dflt, 131 final Label labels[]) 132 { 133 AbstractInsnNode n = new TableSwitchInsnNode(min, max, dflt, labels); 134 methodNode.instructions.add(n); 135 } 136 137 public void visitLookupSwitchInsn ( 138 final Label dflt, 139 final int keys[], 140 final Label labels[]) 141 { 142 AbstractInsnNode n = new LookupSwitchInsnNode(dflt, keys, labels); 143 methodNode.instructions.add(n); 144 } 145 146 public void visitMultiANewArrayInsn (final String desc, final int dims) { 147 AbstractInsnNode n = new MultiANewArrayInsnNode(desc, dims); 148 methodNode.instructions.add(n); 149 } 150 151 public void visitTryCatchBlock ( 152 final Label start, 153 final Label end, 154 final Label handler, 155 final String type) 156 { 157 TryCatchBlockNode n = new TryCatchBlockNode(start, end, handler, type); 158 methodNode.tryCatchBlocks.add(n); 159 } 160 161 public void visitMaxs (final int maxStack, final int maxLocals) { 162 methodNode.maxStack = maxStack; 163 methodNode.maxLocals = maxLocals; 164 } 165 166 public void visitLocalVariable ( 167 final String name, 168 final String desc, 169 final Label start, 170 final Label end, 171 final int index) 172 { 173 LocalVariableNode n = new LocalVariableNode(name, desc, start, end, index); 174 methodNode.localVariables.add(n); 175 } 176 177 public void visitLineNumber (final int line, final Label start) { 178 LineNumberNode n = new LineNumberNode(line, start); 179 methodNode.lineNumbers.add(n); 180 } 181 182 public void visitAttribute (final Attribute attr) { 183 attr.next = methodNode.attrs; 184 methodNode.attrs = attr; 185 } 186 } 187 | Popular Tags |