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