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;
028:
029: import java.io.DataInputStream;
030: import java.io.IOException;
031: import java.io.PrintWriter;
032: import java.lang.reflect.Modifier;
033:
034: import com.sun.satsa.jcrmic.classfile.constants.JConstantPool;
035: import com.sun.satsa.jcrmic.classfile.attributes.*;
036:
037: /**
038: * This class represents a method.
039: */
040: public class JMethod {
041:
042: /**
043: * Method name.
044: */
045: private String method_name;
046:
047: /**
048: * Method descriptor.
049: */
050: private String descriptor;
051:
052: /**
053: * Method access flags.
054: */
055: private int access_flags;
056:
057: /**
058: * Constant pool reference.
059: */
060: private JConstantPool constant_pool;
061:
062: /**
063: * The names of exceptions declared in the throw clause
064: */
065: private String[] exceptionsThrown;
066:
067: /**
068: * Constructor.
069: * @param constant_pool constant pool reference
070: */
071: public JMethod(JConstantPool constant_pool) {
072: this .constant_pool = constant_pool;
073: }
074:
075: /**
076: * Returns the list of names of exceptions declared in the throw clause.
077: * @return the list of names of exceptions declared in the throw clause
078: */
079: public String[] getExceptionsThrown() {
080: return exceptionsThrown;
081: }
082:
083: /**
084: * Returns method name.
085: * @return method name
086: */
087: public String getMethodName() {
088: return method_name;
089: }
090:
091: /**
092: * Returns method descriptor.
093: * @return method descriptor
094: */
095: public String getMethodDescriptor() {
096: return descriptor;
097: }
098:
099: /**
100: * Parse and resolve Java method.
101: * @param dis input sream
102: * @throws IOException if I/O error occurs
103: */
104: public void parse(DataInputStream dis) throws IOException {
105:
106: access_flags = dis.readUnsignedShort();
107: int name_index = dis.readUnsignedShort();
108: int descriptor_index = dis.readUnsignedShort();
109: int attribute_count = dis.readUnsignedShort();
110: for (int i = 0; i < attribute_count; i++) {
111: int index = dis.readUnsignedShort();
112: JAttribute attribute = JAttribute.create(constant_pool,
113: index);
114: attribute.parse(dis);
115: if (attribute instanceof JExceptionsAttr) {
116: attribute.resolve();
117: exceptionsThrown = ((JExceptionsAttr) attribute)
118: .getExceptions();
119: }
120: }
121:
122: method_name = constant_pool.getConstantUtf8(name_index)
123: .getString();
124: descriptor = constant_pool.getConstantUtf8(descriptor_index)
125: .getString();
126: }
127: }
|