001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.satsa.jcrmic.classfile.constants;
028:
029: import java.io.DataInputStream;
030: import java.io.IOException;
031:
032: /**
033: * This class represents a symbolic reference to a field or method
034: * without indicating which class or interface type it belongs to.
035: */
036:
037: public class JConstantNameAndType extends JConstant {
038:
039: /**
040: * Name index.
041: */
042: private int name_index;
043: /**
044: * Descriptor index.
045: */
046: private int descriptor_index;
047:
048: /**
049: * Name.
050: */
051: private String name;
052: /**
053: * Descriptor.
054: */
055: private String descriptor;
056:
057: /**
058: * Returns the name.
059: * @return the name.
060: */
061: public String getName() {
062: resolve();
063: return name;
064: }
065:
066: /**
067: * Returns the descriptor.
068: * @return the descriptor.
069: */
070: public String getDescriptor() {
071: resolve();
072: return descriptor;
073: }
074:
075: /**
076: * Constructor.
077: * @param cp constant pool reference
078: */
079: public JConstantNameAndType(JConstantPool cp) {
080: super (cp);
081: }
082:
083: /**
084: * Resolves the constant pool entry.
085: */
086: private void resolve() {
087:
088: if (!resolved) {
089: name = cp.getConstantUtf8(name_index).getString();
090: descriptor = cp.getConstantUtf8(descriptor_index)
091: .getString();
092: resolved = true;
093: }
094: }
095:
096: /**
097: * Parses constant pool entry.
098: * @param dis input stream
099: * @throws IOException if I/O exception occurs
100: */
101: public void parse(DataInputStream dis) throws IOException {
102: name_index = dis.readUnsignedShort();
103: descriptor_index = dis.readUnsignedShort();
104: }
105: }
|