1 package com.sun.org.apache.bcel.internal.classfile; 2 3 56 import com.sun.org.apache.bcel.internal.Constants; 57 import java.io.*; 58 59 67 public final class Method extends FieldOrMethod { 68 72 public Method() {} 73 74 78 public Method(Method c) { 79 super(c); 80 } 81 82 88 Method(DataInputStream file, ConstantPool constant_pool) 89 throws IOException, ClassFormatError 90 { 91 super(file, constant_pool); 92 } 93 94 101 public Method(int access_flags, int name_index, int signature_index, 102 Attribute[] attributes, ConstantPool constant_pool) 103 { 104 super(access_flags, name_index, signature_index, attributes, constant_pool); 105 } 106 107 114 public void accept(Visitor v) { 115 v.visitMethod(this); 116 } 117 118 121 public final Code getCode() { 122 for(int i=0; i < attributes_count; i++) 123 if(attributes[i] instanceof Code) 124 return (Code)attributes[i]; 125 126 return null; 127 } 128 129 133 public final ExceptionTable getExceptionTable() { 134 for(int i=0; i < attributes_count; i++) 135 if(attributes[i] instanceof ExceptionTable) 136 return (ExceptionTable)attributes[i]; 137 138 return null; 139 } 140 141 144 public final LocalVariableTable getLocalVariableTable() { 145 Code code = getCode(); 146 147 if(code != null) 148 return code.getLocalVariableTable(); 149 else 150 return null; 151 } 152 153 156 public final LineNumberTable getLineNumberTable() { 157 Code code = getCode(); 158 159 if(code != null) 160 return code.getLineNumberTable(); 161 else 162 return null; 163 } 164 165 171 public final String toString() { 172 ConstantUtf8 c; 173 ConstantValue cv; 174 String name, signature, access; String exceptions; 176 StringBuffer buf; 177 Attribute[] attr; 178 179 access = Utility.accessToString(access_flags); 180 181 c = (ConstantUtf8)constant_pool.getConstant(signature_index, 183 Constants.CONSTANT_Utf8); 184 signature = c.getBytes(); 185 186 c = (ConstantUtf8)constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8); 187 name = c.getBytes(); 188 189 signature = Utility.methodSignatureToString(signature, name, access, true, 190 getLocalVariableTable()); 191 buf = new StringBuffer (signature); 192 193 for(int i=0; i < attributes_count; i++) { 194 Attribute a = attributes[i]; 195 196 if(!((a instanceof Code) || (a instanceof ExceptionTable))) 197 buf.append(" [" + a.toString() + "]"); 198 } 199 200 ExceptionTable e = getExceptionTable(); 201 if(e != null) { 202 String str = e.toString(); 203 if(!str.equals("")) 204 buf.append("\n\t\tthrows " + str); 205 } 206 207 return buf.toString(); 208 } 209 210 213 public final Method copy(ConstantPool constant_pool) { 214 return (Method)copy_(constant_pool); 215 } 216 } 217 | Popular Tags |