KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > structures > ClassMember


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.structures;
9
10 import org.gjt.jclasslib.structures.constants.ConstantUtf8Info;
11
12 import java.io.*;
13
14 /**
15     Base class for class members.
16
17     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
18     @version $Revision: 1.5 $ $Date: 2003/08/18 07:52:54 $
19 */

20 public abstract class ClassMember extends AbstractStructureWithAttributes
21                                   implements AccessFlags {
22
23     /** The access flags of this class member. */
24     protected int accessFlags;
25     /** the constant pool index of the name of this class member. */
26     protected int nameIndex;
27     /** the constant pool index of the descriptor of this class member. */
28     protected int descriptorIndex;
29
30     /**
31         Get the access flags of this class member.
32         @return the access flags
33      */

34     public int getAccessFlags() {
35         return accessFlags;
36     }
37
38     /**
39         Set the access flags of this class member.
40         @param accessFlags the access flags
41      */

42     public void setAccessFlags(int accessFlags) {
43         this.accessFlags = accessFlags;
44     }
45
46     /**
47         Get the constant pool index of the name of this class member.
48         @return the index
49      */

50     public int getNameIndex() {
51         return nameIndex;
52     }
53
54     /**
55         Set the constant pool index of the name of this class member.
56         @param nameIndex the index
57      */

58     public void setNameIndex(int nameIndex) {
59         this.nameIndex = nameIndex;
60     }
61
62     /**
63         Get the constant pool index of the descriptor of this class member.
64         @return the index
65      */

66     public int getDescriptorIndex() {
67         return descriptorIndex;
68     }
69
70     /**
71         Set the constant pool index of the descriptor of this class member.
72         @param descriptorIndex the index
73      */

74     public void setDescriptorIndex(int descriptorIndex) {
75         this.descriptorIndex = descriptorIndex;
76     }
77
78     /**
79         Get the name of the class member.
80         @return the name
81         @throws InvalidByteCodeException if the entry is invalid
82      */

83     public String JavaDoc getName() throws InvalidByteCodeException {
84         ConstantUtf8Info cpinfo = classFile.getConstantPoolUtf8Entry(nameIndex);
85         if (cpinfo == null) {
86             return "invalid constant pool index";
87         } else {
88             return cpinfo.getString();
89         }
90     }
91
92     /**
93         Get the verbose descriptor of the class member.
94         @return the descriptor
95         @throws InvalidByteCodeException if the entry is invalid
96      */

97     public String JavaDoc getDescriptor() throws InvalidByteCodeException {
98         ConstantUtf8Info cpinfo = classFile.getConstantPoolUtf8Entry(descriptorIndex);
99         if (cpinfo == null) {
100             return "invalid constant pool index";
101         } else {
102             return cpinfo.getString();
103         }
104     }
105
106     /**
107         Get the the access flags of this class as a hex string.
108         @return the hex string
109      */

110     public String JavaDoc getFormattedAccessFlags() {
111         return printAccessFlags(accessFlags);
112     }
113
114     /**
115         Get the verbose description of the access flags of this class.
116         @return the description
117      */

118     public String JavaDoc getAccessFlagsVerbose() {
119         return printAccessFlagsVerbose(accessFlags);
120     }
121
122     public void read(DataInput in)
123         throws InvalidByteCodeException, IOException {
124
125         accessFlags = in.readUnsignedShort();
126         nameIndex = in.readUnsignedShort();
127         descriptorIndex = in.readUnsignedShort();
128
129         readAttributes(in);
130
131     }
132
133     public void write(DataOutput out)
134         throws InvalidByteCodeException, IOException {
135
136         out.writeShort(accessFlags);
137         out.writeShort(nameIndex);
138         out.writeShort(descriptorIndex);
139
140         writeAttributes(out);
141     }
142
143 }
144
Popular Tags