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 class method.
034: */
035:
036: public class JConstantMethodRef extends JConstant {
037:
038: /**
039: * Class constant pool entry index.
040: */
041: private int class_index;
042:
043: /**
044: * Method name and type constant pool entry index.
045: */
046: private int nameAndType_index;
047:
048: /**
049: * Class name.
050: */
051: protected String class_name;
052:
053: /**
054: * Method name.
055: */
056: protected String method_name;
057:
058: /**
059: * Method descriptor.
060: */
061: protected String descriptor;
062:
063: /**
064: * Returns class name.
065: * @return class name
066: */
067: public String getClassName() {
068: resolve();
069: return class_name;
070: }
071:
072: /**
073: * Returns method name.
074: * @return method name
075: */
076: public String getMethodName() {
077: resolve();
078: return method_name;
079: }
080:
081: /**
082: * Returns method descriptor.
083: * @return method descriptor
084: */
085: public String getDescriptor() {
086: resolve();
087: return descriptor;
088: }
089:
090: /**
091: * Constructor.
092: * @param cp constant pool reference
093: */
094: public JConstantMethodRef(JConstantPool cp) {
095: super (cp);
096: }
097:
098: /**
099: * Resolves the constant pool entry.
100: */
101: private void resolve() {
102:
103: if (!resolved) {
104:
105: class_name = cp.getConstantClass(class_index)
106: .getClassName();
107:
108: JConstantNameAndType nameAndTypeConstant = cp
109: .getConstantNameAndType(nameAndType_index);
110:
111: method_name = nameAndTypeConstant.getName();
112: descriptor = nameAndTypeConstant.getDescriptor();
113:
114: resolved = true;
115: }
116: }
117:
118: /**
119: * Parses constant pool entry.
120: * @param dis input stream
121: * @throws IOException if I/O exception occurs
122: */
123: public void parse(DataInputStream dis) throws IOException {
124: class_index = dis.readUnsignedShort();
125: nameAndType_index = dis.readUnsignedShort();
126: }
127: }
|