1:
38:
39: package ;
40:
41: import ;
42: import ;
43:
44: public class MethodSignatureParser extends GenericSignatureParser
45: {
46: private TypeVariable[] typeParameters;
47: private Type[] argTypes;
48: private Type retType;
49: private Type[] throwsSigs;
50:
51: public MethodSignatureParser(Method method, String signature)
52: {
53: this(method, method.getDeclaringClass().getClassLoader(), signature);
54: }
55:
56: public MethodSignatureParser(Constructor method, String signature)
57: {
58: this(method, method.getDeclaringClass().getClassLoader(), signature);
59: }
60:
61: private MethodSignatureParser(GenericDeclaration wrapper,
62: ClassLoader loader, String signature)
63: {
64: super(wrapper, loader, signature);
65:
66: if (peekChar() == '<')
67: {
68: typeParameters = readFormalTypeParameters();
69: }
70: else
71: {
72: typeParameters = new TypeVariable[0];
73: }
74: consume('(');
75: ArrayList<Type> args = new ArrayList<Type>();
76: while (peekChar() != ')')
77: {
78: args.add(readTypeSignature());
79: }
80: argTypes = new Type[args.size()];
81: args.toArray(argTypes);
82: consume(')');
83: retType = readTypeSignature();
84: ArrayList<Type> throwsSigs = new ArrayList<Type>();
85: while (peekChar() == '^')
86: {
87: consume('^');
88: if(peekChar() == 'T')
89: {
90: throwsSigs.add(readTypeVariableSignature());
91: }
92: else
93: {
94: throwsSigs.add(readClassTypeSignature());
95: }
96: }
97: this.throwsSigs = new Type[throwsSigs.size()];
98: throwsSigs.toArray(this.throwsSigs);
99: end();
100: }
101:
102: public TypeVariable[] getTypeParameters()
103: {
104: TypeImpl.resolve(typeParameters);
105: return typeParameters;
106: }
107:
108: public Type[] getGenericParameterTypes()
109: {
110: TypeImpl.resolve(argTypes);
111: return argTypes;
112: }
113:
114: public Type getGenericReturnType()
115: {
116: retType = TypeImpl.resolve(retType);
117: return retType;
118: }
119:
120: public Type[] getGenericExceptionTypes()
121: {
122: TypeImpl.resolve(throwsSigs);
123: return throwsSigs;
124: }
125:
126: private Type readTypeSignature()
127: {
128: switch (peekChar())
129: {
130: case 'T':
131: return readTypeVariableSignature();
132: case 'L':
133: return readClassTypeSignature();
134: case '[':
135: return readArrayTypeSignature();
136: case 'Z':
137: consume('Z');
138: return boolean.class;
139: case 'B':
140: consume('B');
141: return byte.class;
142: case 'S':
143: consume('S');
144: return short.class;
145: case 'C':
146: consume('C');
147: return char.class;
148: case 'I':
149: consume('I');
150: return int.class;
151: case 'F':
152: consume('F');
153: return float.class;
154: case 'J':
155: consume('J');
156: return long.class;
157: case 'D':
158: consume('D');
159: return double.class;
160: case 'V':
161: consume('V');
162: return void.class;
163: default:
164: throw new GenericSignatureFormatError();
165: }
166: }
167: }