001: /*
002: This library is free software; you can redistribute it and/or
003: modify it under the terms of the GNU General Public
004: License as published by the Free Software Foundation; either
005: version 2 of the license, or (at your option) any later version.
006: */
007:
008: package org.gjt.jclasslib.structures;
009:
010: import org.gjt.jclasslib.structures.constants.ConstantUtf8Info;
011:
012: import java.io.*;
013:
014: /**
015: Base class for class members.
016:
017: @author <a href="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
018: @version $Revision: 1.5 $ $Date: 2003/08/18 07:52:54 $
019: */
020: public abstract class ClassMember extends
021: AbstractStructureWithAttributes implements AccessFlags {
022:
023: /** The access flags of this class member. */
024: protected int accessFlags;
025: /** the constant pool index of the name of this class member. */
026: protected int nameIndex;
027: /** the constant pool index of the descriptor of this class member. */
028: protected int descriptorIndex;
029:
030: /**
031: Get the access flags of this class member.
032: @return the access flags
033: */
034: public int getAccessFlags() {
035: return accessFlags;
036: }
037:
038: /**
039: Set the access flags of this class member.
040: @param accessFlags the access flags
041: */
042: public void setAccessFlags(int accessFlags) {
043: this .accessFlags = accessFlags;
044: }
045:
046: /**
047: Get the constant pool index of the name of this class member.
048: @return the index
049: */
050: public int getNameIndex() {
051: return nameIndex;
052: }
053:
054: /**
055: Set the constant pool index of the name of this class member.
056: @param nameIndex the index
057: */
058: public void setNameIndex(int nameIndex) {
059: this .nameIndex = nameIndex;
060: }
061:
062: /**
063: Get the constant pool index of the descriptor of this class member.
064: @return the index
065: */
066: public int getDescriptorIndex() {
067: return descriptorIndex;
068: }
069:
070: /**
071: Set the constant pool index of the descriptor of this class member.
072: @param descriptorIndex the index
073: */
074: public void setDescriptorIndex(int descriptorIndex) {
075: this .descriptorIndex = descriptorIndex;
076: }
077:
078: /**
079: Get the name of the class member.
080: @return the name
081: @throws InvalidByteCodeException if the entry is invalid
082: */
083: public String getName() throws InvalidByteCodeException {
084: ConstantUtf8Info cpinfo = classFile
085: .getConstantPoolUtf8Entry(nameIndex);
086: if (cpinfo == null) {
087: return "invalid constant pool index";
088: } else {
089: return cpinfo.getString();
090: }
091: }
092:
093: /**
094: Get the verbose descriptor of the class member.
095: @return the descriptor
096: @throws InvalidByteCodeException if the entry is invalid
097: */
098: public String getDescriptor() throws InvalidByteCodeException {
099: ConstantUtf8Info cpinfo = classFile
100: .getConstantPoolUtf8Entry(descriptorIndex);
101: if (cpinfo == null) {
102: return "invalid constant pool index";
103: } else {
104: return cpinfo.getString();
105: }
106: }
107:
108: /**
109: Get the the access flags of this class as a hex string.
110: @return the hex string
111: */
112: public String getFormattedAccessFlags() {
113: return printAccessFlags(accessFlags);
114: }
115:
116: /**
117: Get the verbose description of the access flags of this class.
118: @return the description
119: */
120: public String getAccessFlagsVerbose() {
121: return printAccessFlagsVerbose(accessFlags);
122: }
123:
124: public void read(DataInput in) throws InvalidByteCodeException,
125: IOException {
126:
127: accessFlags = in.readUnsignedShort();
128: nameIndex = in.readUnsignedShort();
129: descriptorIndex = in.readUnsignedShort();
130:
131: readAttributes(in);
132:
133: }
134:
135: public void write(DataOutput out) throws InvalidByteCodeException,
136: IOException {
137:
138: out.writeShort(accessFlags);
139: out.writeShort(nameIndex);
140: out.writeShort(descriptorIndex);
141:
142: writeAttributes(out);
143: }
144:
145: }
|