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 public final class Field extends FieldOrMethod {
00014
00015
00016
00017
00018
00019
00020
00021 public Field(int access_flags, int name_index, int signature_index,
00022 Attribute[] attributes, ConstantPool constant_pool)
00023 {
00024 super(access_flags, name_index, signature_index, attributes, constant_pool);
00025 }
00026
00027
00028
00029
00030 public Field(Field c) {
00031 super(c);
00032 }
00033
00034
00035
00036
00037 Field(DataInputStream file, ConstantPool constant_pool)
00038 throws IOException, ClassFormatError
00039 {
00040 super(file, constant_pool);
00041 }
00042
00043
00044
00045
00046
00047
00048
00049 public void accept(Visitor v) {
00050 v.visitField(this);
00051 }
00052
00053
00054
00055 public final Field copy(ConstantPool constant_pool) {
00056 return (Field)copy_(constant_pool);
00057 }
00058
00059
00060
00061 public final ConstantValue getConstantValue() {
00062 for(int i=0; i < attributes_count; i++)
00063 if(attributes[i].getTag() == Constants.ATTR_CONSTANT_VALUE)
00064 return (ConstantValue)attributes[i];
00065
00066 return null;
00067 }
00068
00069
00070
00071
00072
00073
00074 public final String toString() {
00075 String name, signature, access;
00076
00077
00078 access = Utility.accessToString(access_flags);
00079 access = access.equals("")? "" : (access + " ");
00080 signature = Utility.signatureToString(getSignature());
00081 name = getName();
00082
00083 StringBuffer buf = new StringBuffer(access + signature + " " + name);
00084 ConstantValue cv = getConstantValue();
00085
00086 if(cv != null)
00087 buf.append(" = " + cv);
00088
00089 for(int i=0; i < attributes_count; i++) {
00090 Attribute a = attributes[i];
00091
00092 if(!(a instanceof ConstantValue))
00093 buf.append(" <" + a.toString() + ">");
00094 }
00095
00096 return buf.toString();
00097 }
00098 }