001: /* MethodType Copyright (C) 1998-2002 Jochen Hoenicke.
002: *
003: * This program is free software; you can redistribute it and/or modify
004: * it under the terms of the GNU General Public License as published by
005: * the Free Software Foundation; either version 2, or (at your option)
006: * any later version.
007: *
008: * This program is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU General Public License for more details.
012: *
013: * You should have received a copy of the GNU General Public License
014: * along with this program; see the file COPYING. If not, write to
015: * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
016: *
017: * $Id: MethodType.java,v 4.9.4.1 2002/05/28 17:34:22 hoenicke Exp $
018: */
019:
020: package jode.type;
021:
022: /**
023: * This type represents an method type.
024: *
025: * @author Jochen Hoenicke
026: */
027: public class MethodType extends Type {
028: final String signature;
029: final Type[] parameterTypes;
030: final Type returnType;
031:
032: public MethodType(String signature) {
033: super (TC_METHOD);
034: this .signature = signature;
035: int index = 1, types = 0;
036: while (signature.charAt(index) != ')') {
037: types++;
038: while (signature.charAt(index) == '[')
039: index++;
040: if (signature.charAt(index) == 'L')
041: index = signature.indexOf(';', index);
042: index++;
043: }
044: parameterTypes = new Type[types];
045:
046: index = 1;
047: types = 0;
048: while (signature.charAt(index) != ')') {
049: int lastindex = index;
050: while (signature.charAt(index) == '[')
051: index++;
052: if (signature.charAt(index) == 'L')
053: index = signature.indexOf(';', index);
054: index++;
055: parameterTypes[types++] = Type.tType(signature.substring(
056: lastindex, index));
057: }
058: returnType = Type.tType(signature.substring(index + 1));
059: }
060:
061: public final int stackSize() {
062: int size = returnType.stackSize();
063: for (int i = 0; i < parameterTypes.length; i++)
064: size -= parameterTypes[i].stackSize();
065: return size;
066: }
067:
068: public Type[] getParameterTypes() {
069: return parameterTypes;
070: }
071:
072: public Class[] getParameterClasses() throws ClassNotFoundException {
073: Class[] paramClasses = new Class[parameterTypes.length];
074: for (int i = paramClasses.length; --i >= 0;)
075: paramClasses[i] = parameterTypes[i].getTypeClass();
076: return paramClasses;
077: }
078:
079: public Type getReturnType() {
080: return returnType;
081: }
082:
083: public Class getReturnClass() throws ClassNotFoundException {
084: return returnType.getTypeClass();
085: }
086:
087: public String getTypeSignature() {
088: return signature;
089: }
090:
091: public String toString() {
092: return signature;
093: }
094:
095: public boolean equals(Object o) {
096: MethodType mt;
097: return (o instanceof MethodType && signature
098: .equals((mt = (MethodType) o).signature));
099: }
100: }
|