001: /*
002: * Copyright 1994-2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.tools.java;
027:
028: /**
029: * This class represents an Java method type.
030: * It overrides the relevant methods in class Type.
031: *
032: * WARNING: The contents of this source file are not part of any
033: * supported API. Code that depends on them does so at its own risk:
034: * they are subject to change or removal without notice.
035: *
036: * @author Arthur van Hoff
037: * @version 1.28, 05/05/07
038: */
039: public final class MethodType extends Type {
040: /**
041: * The return type.
042: */
043: Type returnType;
044:
045: /**
046: * The argument types.
047: */
048: Type argTypes[];
049:
050: /**
051: * Construct a method type. Use Type.tMethod to create
052: * a new method type.
053: * @see Type.tMethod
054: */
055: MethodType(String typeSig, Type returnType, Type argTypes[]) {
056: super (TC_METHOD, typeSig);
057: this .returnType = returnType;
058: this .argTypes = argTypes;
059: }
060:
061: public Type getReturnType() {
062: return returnType;
063: }
064:
065: public Type getArgumentTypes()[] {
066: return argTypes;
067: }
068:
069: public boolean equalArguments(Type t) {
070: if (t.typeCode != TC_METHOD) {
071: return false;
072: }
073: MethodType m = (MethodType) t;
074: if (argTypes.length != m.argTypes.length) {
075: return false;
076: }
077: for (int i = argTypes.length - 1; i >= 0; i--) {
078: if (argTypes[i] != m.argTypes[i]) {
079: return false;
080: }
081: }
082: return true;
083: }
084:
085: public int stackSize() {
086: int n = 0;
087: for (int i = 0; i < argTypes.length; i++) {
088: n += argTypes[i].stackSize();
089: }
090: return n;
091: }
092:
093: public String typeString(String id, boolean abbrev, boolean ret) {
094: StringBuffer buf = new StringBuffer();
095: buf.append(id);
096: buf.append('(');
097: for (int i = 0; i < argTypes.length; i++) {
098: if (i > 0) {
099: buf.append(", ");
100: }
101: buf.append(argTypes[i].typeString("", abbrev, ret));
102: }
103: buf.append(')');
104:
105: return ret ? getReturnType().typeString(buf.toString(), abbrev,
106: ret) : buf.toString();
107: }
108: }
|