1 9 package com.vladium.jcd.cls; 10 11 import java.io.IOException ; 12 13 import com.vladium.jcd.cls.attribute.*; 14 import com.vladium.jcd.cls.constant.CONSTANT_Utf8_info; 15 import com.vladium.jcd.lib.UDataInputStream; 16 import com.vladium.jcd.lib.UDataOutputStream; 17 18 52 public 53 final class Field_info implements Cloneable , IAccessFlags 54 { 55 57 58 public int m_name_index; 59 public int m_descriptor_index; 60 61 62 public Field_info (final int access_flags, 63 final int name_index, final int descriptor_index, 64 final IAttributeCollection attributes) 65 { 66 m_access_flags = access_flags; 67 68 m_name_index = name_index; 69 m_descriptor_index = descriptor_index; 70 71 m_attributes = attributes; 72 } 73 74 public Field_info (final IConstantCollection constants, 75 final UDataInputStream bytes) 76 throws IOException 77 { 78 m_access_flags = bytes.readU2 (); 79 80 m_name_index = bytes.readU2 (); 81 m_descriptor_index = bytes.readU2 (); 82 83 final int attributes_count = bytes.readU2 (); 85 m_attributes = ElementFactory.newAttributeCollection (attributes_count); 86 87 for (int i = 0; i < attributes_count; i++) 88 { 89 final Attribute_info attribute_info = Attribute_info.new_Attribute_info (constants, bytes); 90 if (DEBUG) System.out.println ("\t[" + i + "] attribute: " + attribute_info); 91 92 m_attributes.add (attribute_info); 93 } 94 } 95 96 102 public String getName (final ClassDef cls) 103 { 104 return ((CONSTANT_Utf8_info) cls.getConstants ().get (m_name_index)).m_value; 105 } 106 107 114 public String getDescriptor (final ClassDef cls) 115 { 116 return ((CONSTANT_Utf8_info) cls.getConstants ().get (m_descriptor_index)).m_value; 117 } 118 119 public boolean isSynthetic () 120 { 121 return m_attributes.hasSynthetic (); 122 } 123 124 126 public final void setAccessFlags (final int flags) 127 { 128 m_access_flags = flags; 129 } 130 131 public final int getAccessFlags () 132 { 133 return m_access_flags; 134 } 135 136 public IAttributeCollection getAttributes () 137 { 138 return m_attributes; 139 } 140 141 142 public String toString () 143 { 144 return "field_info: [modifiers: 0x" + Integer.toHexString(m_access_flags) + ", name_index = " + m_name_index + ", descriptor_index = " + m_descriptor_index + ']'; 145 } 146 147 148 150 153 public Object clone () 154 { 155 try 156 { 157 final Field_info _clone = (Field_info) super.clone (); 158 159 _clone.m_attributes = (IAttributeCollection) m_attributes.clone (); 161 162 return _clone; 163 } 164 catch (CloneNotSupportedException e) 165 { 166 throw new InternalError (e.toString ()); 167 } 168 } 169 170 171 173 public void writeInClassFormat (final UDataOutputStream out) throws IOException 174 { 175 out.writeU2 (m_access_flags); 176 177 out.writeU2 (m_name_index); 178 out.writeU2 (m_descriptor_index); 179 180 m_attributes.writeInClassFormat (out); 181 } 182 183 185 187 189 190 private int m_access_flags; 191 private IAttributeCollection m_attributes; 193 194 private static final boolean DEBUG = false; 195 196 } | Popular Tags |