00001 package de.fub.bytecode.classfile;
00002
00003 import de.fub.bytecode.Constants;
00004 import java.io.*;
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 public final class Method extends FieldOrMethod {
00015
00016
00017
00018
00019 public Method() {}
00020
00021
00022
00023
00024
00025
00026
00027 public Method(int access_flags, int name_index, int signature_index,
00028 Attribute[] attributes, ConstantPool constant_pool)
00029 {
00030 super(access_flags, name_index, signature_index, attributes, constant_pool);
00031 }
00032
00033
00034
00035
00036 public Method(Method c) {
00037 super(c);
00038 }
00039
00040
00041
00042
00043
00044
00045 Method(DataInputStream file, ConstantPool constant_pool)
00046 throws IOException, ClassFormatError
00047 {
00048 super(file, constant_pool);
00049 }
00050
00051
00052
00053
00054
00055
00056
00057 public void accept(Visitor v) {
00058 v.visitMethod(this);
00059 }
00060
00061
00062
00063 public final Method copy(ConstantPool constant_pool) {
00064 return (Method)copy_(constant_pool);
00065 }
00066
00067
00068
00069 public final Code getCode() {
00070 for(int i=0; i < attributes_count; i++)
00071 if(attributes[i] instanceof Code)
00072 return (Code)attributes[i];
00073
00074 return null;
00075 }
00076
00077
00078
00079
00080 public final ExceptionTable getExceptionTable() {
00081 for(int i=0; i < attributes_count; i++)
00082 if(attributes[i] instanceof ExceptionTable)
00083 return (ExceptionTable)attributes[i];
00084
00085 return null;
00086 }
00087
00088
00089
00090
00091
00092
00093 public final String toString() {
00094 ConstantUtf8 c;
00095 ConstantValue cv;
00096 String name, signature, access;
00097 String exceptions;
00098 StringBuffer buf;
00099 Attribute[] attr;
00100
00101 access = Utility.accessToString(access_flags);
00102
00103
00104 c = (ConstantUtf8)constant_pool.getConstant(signature_index,
00105 Constants.CONSTANT_Utf8);
00106 signature = c.getBytes();
00107
00108 c = (ConstantUtf8)constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8);
00109 name = c.getBytes();
00110
00111 signature = Utility.methodSignatureToString(signature, name, access);
00112
00113 buf = new StringBuffer(signature);
00114
00115 for(int i=0; i < attributes_count; i++) {
00116 Attribute a = attributes[i];
00117
00118 if(!((a instanceof Code) || (a instanceof ExceptionTable)))
00119 buf.append(" <" + a.toString() + ">");
00120 }
00121
00122 ExceptionTable e = getExceptionTable();
00123 if(e != null) {
00124 String str = e.toString();
00125 if(!str.equals(""))
00126 buf.append("\n\t\tthrows " + str);
00127 }
00128
00129 return buf.toString();
00130 }
00131 }