1 17 package org.apache.bcel.classfile; 18 19 import java.io.DataInputStream ; 20 import java.io.DataOutputStream ; 21 import java.io.IOException ; 22 import org.apache.bcel.Constants; 23 24 30 public abstract class FieldOrMethod extends AccessFlags implements Cloneable , Node { 31 32 protected int name_index; protected int signature_index; protected int attributes_count; protected Attribute[] attributes; protected ConstantPool constant_pool; 37 38 39 FieldOrMethod() { 40 } 41 42 43 47 protected FieldOrMethod(FieldOrMethod c) { 48 this(c.getAccessFlags(), c.getNameIndex(), c.getSignatureIndex(), c.getAttributes(), c 49 .getConstantPool()); 50 } 51 52 53 59 protected FieldOrMethod(DataInputStream file, ConstantPool constant_pool) throws IOException , 60 ClassFormatException { 61 this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), null, 62 constant_pool); 63 attributes_count = file.readUnsignedShort(); 64 attributes = new Attribute[attributes_count]; 65 for (int i = 0; i < attributes_count; i++) { 66 attributes[i] = Attribute.readAttribute(file, constant_pool); 67 } 68 } 69 70 71 78 protected FieldOrMethod(int access_flags, int name_index, int signature_index, 79 Attribute[] attributes, ConstantPool constant_pool) { 80 this.access_flags = access_flags; 81 this.name_index = name_index; 82 this.signature_index = signature_index; 83 this.constant_pool = constant_pool; 84 setAttributes(attributes); 85 } 86 87 88 94 public final void dump( DataOutputStream file ) throws IOException { 95 file.writeShort(access_flags); 96 file.writeShort(name_index); 97 file.writeShort(signature_index); 98 file.writeShort(attributes_count); 99 for (int i = 0; i < attributes_count; i++) { 100 attributes[i].dump(file); 101 } 102 } 103 104 105 108 public final Attribute[] getAttributes() { 109 return attributes; 110 } 111 112 113 116 public final void setAttributes( Attribute[] attributes ) { 117 this.attributes = attributes; 118 attributes_count = (attributes == null) ? 0 : attributes.length; 119 } 120 121 122 125 public final ConstantPool getConstantPool() { 126 return constant_pool; 127 } 128 129 130 133 public final void setConstantPool( ConstantPool constant_pool ) { 134 this.constant_pool = constant_pool; 135 } 136 137 138 141 public final int getNameIndex() { 142 return name_index; 143 } 144 145 146 149 public final void setNameIndex( int name_index ) { 150 this.name_index = name_index; 151 } 152 153 154 157 public final int getSignatureIndex() { 158 return signature_index; 159 } 160 161 162 165 public final void setSignatureIndex( int signature_index ) { 166 this.signature_index = signature_index; 167 } 168 169 170 173 public final String getName() { 174 ConstantUtf8 c; 175 c = (ConstantUtf8) constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8); 176 return c.getBytes(); 177 } 178 179 180 183 public final String getSignature() { 184 ConstantUtf8 c; 185 c = (ConstantUtf8) constant_pool.getConstant(signature_index, Constants.CONSTANT_Utf8); 186 return c.getBytes(); 187 } 188 189 190 193 protected FieldOrMethod copy_( ConstantPool _constant_pool ) { 194 try { 195 FieldOrMethod c = (FieldOrMethod) clone(); 196 c.constant_pool = _constant_pool; 197 c.attributes = new Attribute[attributes_count]; 198 for (int i = 0; i < attributes_count; i++) { 199 c.attributes[i] = attributes[i].copy(_constant_pool); 200 } 201 return c; 202 } catch (CloneNotSupportedException e) { 203 return null; 204 } 205 } 206 } 207 | Popular Tags |