1 21 package proguard.classfile.attribute; 22 23 import proguard.classfile.*; 24 import proguard.classfile.attribute.visitor.*; 25 import proguard.classfile.instruction.*; 26 import proguard.classfile.instruction.visitor.InstructionVisitor; 27 28 33 public class CodeAttribute extends Attribute 34 { 35 public int u2maxStack; 36 public int u2maxLocals; 37 public int u4codeLength; 38 public byte[] code; 39 public int u2exceptionTableLength; 40 public ExceptionInfo[] exceptionTable; 41 public int u2attributesCount; 42 public Attribute[] attributes; 43 44 45 48 public CodeAttribute() 49 { 50 } 51 52 53 56 public Attribute getAttribute(Clazz clazz, String name) 57 { 58 for (int index = 0; index < u2attributesCount; index++) 59 { 60 Attribute attribute = attributes[index]; 61 if (attribute.getAttributeName(clazz).equals(name)) 62 { 63 return attribute; 64 } 65 } 66 67 return null; 68 } 69 70 71 73 public void accept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) 74 { 75 attributeVisitor.visitCodeAttribute(clazz, method, this); 76 } 77 78 79 82 public void instructionsAccept(Clazz clazz, Method method, InstructionVisitor instructionVisitor) 83 { 84 instructionsAccept(clazz, method, 0, u4codeLength, instructionVisitor); 85 } 86 87 88 92 public void instructionAccept(Clazz clazz, Method method, int offset, InstructionVisitor instructionVisitor) 93 { 94 Instruction instruction = InstructionFactory.create(code, offset); 95 instruction.accept(clazz, method, this, offset, instructionVisitor); 96 } 97 98 99 103 public void instructionsAccept(Clazz clazz, Method method, int startOffset, int endOffset, InstructionVisitor instructionVisitor) 104 { 105 int offset = startOffset; 106 107 while (offset < endOffset) 108 { 109 Instruction instruction = InstructionFactory.create(code, offset); 111 int instructionLength = instruction.length(offset); 112 instruction.accept(clazz, method, this, offset, instructionVisitor); 113 offset += instructionLength; 114 } 115 } 116 117 118 121 public void exceptionsAccept(Clazz clazz, Method method, ExceptionInfoVisitor exceptionInfoVisitor) 122 { 123 for (int index = 0; index < u2exceptionTableLength; index++) 124 { 125 exceptionInfoVisitor.visitExceptionInfo(clazz, method, this, exceptionTable[index]); 128 } 129 } 130 131 132 136 public void exceptionsAccept(Clazz clazz, Method method, int offset, ExceptionInfoVisitor exceptionInfoVisitor) 137 { 138 for (int index = 0; index < u2exceptionTableLength; index++) 139 { 140 ExceptionInfo exceptionInfo = exceptionTable[index]; 141 if (exceptionInfo.isApplicable(offset)) 142 { 143 exceptionInfoVisitor.visitExceptionInfo(clazz, method, this, exceptionInfo); 144 } 145 } 146 } 147 148 149 153 public void exceptionsAccept(Clazz clazz, Method method, int startOffset, int endOffset, ExceptionInfoVisitor exceptionInfoVisitor) 154 { 155 for (int index = 0; index < u2exceptionTableLength; index++) 156 { 157 ExceptionInfo exceptionInfo = exceptionTable[index]; 158 if (exceptionInfo.isApplicable(startOffset, endOffset)) 159 { 160 exceptionInfoVisitor.visitExceptionInfo(clazz, method, this, exceptionInfo); 161 } 162 } 163 } 164 165 166 169 public void attributesAccept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) 170 { 171 for (int index = 0; index < u2attributesCount; index++) 172 { 173 attributes[index].accept(clazz, method, this, attributeVisitor); 174 } 175 } 176 } 177
| Popular Tags
|