CLMemberInfo.java |
1 // Copyright 2012- Bill Campbell, Swami Iyer and Bahar Akbal-Delibas 2 3 package jminusminus; 4 5 import java.io.IOException; 6 import java.util.ArrayList; 7 8 /** 9 * This abstract base class represents the member_info structure. 10 */ 11 abstract class CLMemberInfo { 12 /** 13 * member_info.access_flags item. 14 */ 15 public int accessFlags; 16 17 /** 18 * member_info.name_index item. 19 */ 20 public int nameIndex; 21 22 /** 23 * member_info.descriptor_index item. 24 */ 25 public int descriptorIndex; 26 27 /** 28 * member_info.attributes_count item. 29 */ 30 public int attributesCount; 31 32 /** 33 * member_info.attributes item. 34 */ 35 public ArrayList<CLAttributeInfo> attributes; 36 37 /** 38 * Constructs a CLMemberInfo object. 39 * 40 * @param accessFlags member_info.access_flags item. 41 * @param nameIndex member_info.name_index item. 42 * @param descriptorIndex member_info.descriptor_index item. 43 * @param attributesCount member_info.attributes_count item. 44 * @param attributes member_info.attributes item. 45 */ 46 protected CLMemberInfo(int accessFlags, int nameIndex, int descriptorIndex, 47 int attributesCount, ArrayList<CLAttributeInfo> attributes) { 48 this.accessFlags = accessFlags; 49 this.nameIndex = nameIndex; 50 this.descriptorIndex = descriptorIndex; 51 this.attributesCount = attributesCount; 52 this.attributes = attributes; 53 } 54 55 /** 56 * Writes the contents of this class member to the specified output stream. 57 * 58 * @param out output stream. 59 * @throws IOException if the contents of this class member can't be written to the specified 60 * output stream. 61 */ 62 public void write(CLOutputStream out) throws IOException { 63 out.writeShort(accessFlags); 64 out.writeShort(nameIndex); 65 out.writeShort(descriptorIndex); 66 out.writeShort(attributesCount); 67 for (CLAttributeInfo attributeInfo : attributes) { 68 attributeInfo.write(out); 69 } 70 } 71 } 72 73 /** 74 * This class represents the field_info structure. 75 */ 76 class CLFieldInfo extends CLMemberInfo { 77 /** 78 * Constructs a CLFieldInfo object. 79 * 80 * @param accessFlags field_info.access_flags item. 81 * @param nameIndex field_info.name_index item. 82 * @param descriptorIndex field_info.descriptor_index item. 83 * @param attributesCount field_info.attributes_count item. 84 * @param attributes field_info.attributes item. 85 */ 86 public CLFieldInfo(int accessFlags, int nameIndex, int descriptorIndex, int attributesCount, 87 ArrayList<CLAttributeInfo> attributes) { 88 super(accessFlags, nameIndex, descriptorIndex, attributesCount, attributes); 89 } 90 } 91 92 /** 93 * This class represents the method_info structure. 94 */ 95 class CLMethodInfo extends CLMemberInfo { 96 /** 97 * Constructs a CLMethodInfo object. 98 * 99 * @param accessFlags method_info.access_flags item. 100 * @param nameIndex method_info.name_index item. 101 * @param descriptorIndex method_info.descriptor_index item. 102 * @param attributesCount method_info.attributes_count item. 103 * @param attributes method_info.attributes item. 104 */ 105 106 public CLMethodInfo(int accessFlags, int nameIndex, int descriptorIndex, int attributesCount, 107 ArrayList<CLAttributeInfo> attributes) { 108 super(accessFlags, nameIndex, descriptorIndex, attributesCount, attributes); 109 } 110 } 111