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