1 19 20 package jode.type; 21 22 27 public class MethodType extends Type { 28 final String signature; 29 final Type[] parameterTypes; 30 final Type returnType; 31 32 public MethodType(String signature) { 33 super(TC_METHOD); 34 this.signature = signature; 35 int index = 1, types = 0; 36 while (signature.charAt(index) != ')') { 37 types++; 38 while (signature.charAt(index) == '[') 39 index++; 40 if (signature.charAt(index) == 'L') 41 index = signature.indexOf(';', index); 42 index++; 43 } 44 parameterTypes = new Type[types]; 45 46 index = 1; 47 types = 0; 48 while (signature.charAt(index) != ')') { 49 int lastindex = index; 50 while (signature.charAt(index) == '[') 51 index++; 52 if (signature.charAt(index) == 'L') 53 index = signature.indexOf(';', index); 54 index++; 55 parameterTypes[types++] 56 = Type.tType(signature.substring(lastindex,index)); 57 } 58 returnType = Type.tType(signature.substring(index+1)); 59 } 60 61 public final int stackSize() { 62 int size = returnType.stackSize(); 63 for (int i=0; i<parameterTypes.length; i++) 64 size -= parameterTypes[i].stackSize(); 65 return size; 66 } 67 68 public Type[] getParameterTypes() { 69 return parameterTypes; 70 } 71 72 public Class [] getParameterClasses() throws ClassNotFoundException { 73 Class [] paramClasses = new Class [parameterTypes.length]; 74 for (int i = paramClasses.length; --i >= 0; ) 75 paramClasses[i] = parameterTypes[i].getTypeClass(); 76 return paramClasses; 77 } 78 79 public Type getReturnType() { 80 return returnType; 81 } 82 83 public Class getReturnClass() throws ClassNotFoundException { 84 return returnType.getTypeClass(); 85 } 86 87 public String getTypeSignature() { 88 return signature; 89 } 90 91 public String toString() { 92 return signature; 93 } 94 95 public boolean equals(Object o) { 96 MethodType mt; 97 return (o instanceof MethodType 98 && signature.equals((mt = (MethodType)o).signature)); 99 } 100 } 101 | Popular Tags |