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 65 public abstract class FieldOrMethod extends AccessFlags implements Cloneable , Node { 66 protected int name_index; protected int signature_index; protected int attributes_count; protected Attribute[] attributes; protected ConstantPool constant_pool; 71 72 FieldOrMethod() {} 73 74 78 protected FieldOrMethod(FieldOrMethod c) { 79 this(c.getAccessFlags(), c.getNameIndex(), c.getSignatureIndex(), 80 c.getAttributes(), c.getConstantPool()); 81 } 82 83 89 protected FieldOrMethod(DataInputStream file, ConstantPool constant_pool) 90 throws IOException, ClassFormatError 91 { 92 this(file.readUnsignedShort(), file.readUnsignedShort(), 93 file.readUnsignedShort(), null, constant_pool); 94 95 attributes_count = file.readUnsignedShort(); 96 attributes = new Attribute[attributes_count]; 97 for(int i=0; i < attributes_count; i++) 98 attributes[i] = Attribute.readAttribute(file, constant_pool); 99 } 100 101 108 protected FieldOrMethod(int access_flags, int name_index, int signature_index, 109 Attribute[] attributes, ConstantPool constant_pool) 110 { 111 this.access_flags = access_flags; 112 this.name_index = name_index; 113 this.signature_index = signature_index; 114 this.constant_pool = constant_pool; 115 116 setAttributes(attributes); 117 } 118 119 125 public final void dump(DataOutputStream file) throws IOException 126 { 127 file.writeShort(access_flags); 128 file.writeShort(name_index); 129 file.writeShort(signature_index); 130 file.writeShort(attributes_count); 131 132 for(int i=0; i < attributes_count; i++) 133 attributes[i].dump(file); 134 } 135 136 139 public final Attribute[] getAttributes() { return attributes; } 140 141 144 public final void setAttributes(Attribute[] attributes) { 145 this.attributes = attributes; 146 attributes_count = (attributes == null)? 0 : attributes.length; 147 } 148 149 152 public final ConstantPool getConstantPool() { return constant_pool; } 153 154 157 public final void setConstantPool(ConstantPool constant_pool) { 158 this.constant_pool = constant_pool; 159 } 160 161 164 public final int getNameIndex() { return name_index; } 165 166 169 public final void setNameIndex(int name_index) { 170 this.name_index = name_index; 171 } 172 173 176 public final int getSignatureIndex() { return signature_index; } 177 178 181 public final void setSignatureIndex(int signature_index) { 182 this.signature_index = signature_index; 183 } 184 185 188 public final String getName() { 189 ConstantUtf8 c; 190 c = (ConstantUtf8)constant_pool.getConstant(name_index, 191 Constants.CONSTANT_Utf8); 192 return c.getBytes(); 193 } 194 195 198 public final String getSignature() { 199 ConstantUtf8 c; 200 c = (ConstantUtf8)constant_pool.getConstant(signature_index, 201 Constants.CONSTANT_Utf8); 202 return c.getBytes(); 203 } 204 205 208 protected FieldOrMethod copy_(ConstantPool constant_pool) { 209 FieldOrMethod c = null; 210 211 try { 212 c = (FieldOrMethod)clone(); 213 } catch(CloneNotSupportedException e) {} 214 215 c.constant_pool = constant_pool; 216 c.attributes = new Attribute[attributes_count]; 217 218 for(int i=0; i < attributes_count; i++) 219 c.attributes[i] = attributes[i].copy(constant_pool); 220 221 return c; 222 } 223 } 224 | Popular Tags |