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 66 public final class Field extends FieldOrMethod { 67 71 public Field(Field c) { 72 super(c); 73 } 74 75 79 Field(DataInputStream file, ConstantPool constant_pool) 80 throws IOException, ClassFormatError 81 { 82 super(file, constant_pool); 83 } 84 85 92 public Field(int access_flags, int name_index, int signature_index, 93 Attribute[] attributes, ConstantPool constant_pool) 94 { 95 super(access_flags, name_index, signature_index, attributes, constant_pool); 96 } 97 98 105 public void accept(Visitor v) { 106 v.visitField(this); 107 } 108 109 112 public final ConstantValue getConstantValue() { 113 for(int i=0; i < attributes_count; i++) 114 if(attributes[i].getTag() == Constants.ATTR_CONSTANT_VALUE) 115 return (ConstantValue)attributes[i]; 116 117 return null; 118 } 119 120 126 public final String toString() { 127 String name, signature, access; 129 access = Utility.accessToString(access_flags); 131 access = access.equals("")? "" : (access + " "); 132 signature = Utility.signatureToString(getSignature()); 133 name = getName(); 134 135 StringBuffer buf = new StringBuffer (access + signature + " " + name); 136 ConstantValue cv = getConstantValue(); 137 138 if(cv != null) 139 buf.append(" = " + cv); 140 141 for(int i=0; i < attributes_count; i++) { 142 Attribute a = attributes[i]; 143 144 if(!(a instanceof ConstantValue)) 145 buf.append(" [" + a.toString() + "]"); 146 } 147 148 return buf.toString(); 149 } 150 151 154 public final Field copy(ConstantPool constant_pool) { 155 return (Field)copy_(constant_pool); 156 } 157 } 158 | Popular Tags |