01: package com.silvermindsoftware.hitch.reflect;
02:
03: import java.lang.reflect.Method;
04: import java.util.Arrays;
05:
06: /**
07: * Copyright 2007 Brandon Goodin
08: *
09: * Licensed under the Apache License, Version 2.0 (the "License");
10: * you may not use this file except in compliance with the License.
11: * You may obtain a copy of the License at
12: *
13: * http://www.apache.org/licenses/LICENSE-2.0
14: *
15: * Unless required by applicable law or agreed to in writing, software
16: * distributed under the License is distributed on an "AS IS" BASIS,
17: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18: * See the License for the specific language governing permissions and
19: * limitations under the License.
20: */
21:
22: public class MethodInfo {
23:
24: private Method method;
25: private String name;
26: private Class[] parameterTypes;
27: private Class returnType;
28:
29: public MethodInfo(Method method) {
30:
31: this .method = method;
32: this .returnType = method.getReturnType();
33: this .name = method.getName();
34: this .parameterTypes = method.getParameterTypes();
35:
36: }
37:
38: public Method getMethod() {
39: return method;
40: }
41:
42: public boolean equals(Object o) {
43: if (this == o)
44: return true;
45: if (o == null || getClass() != o.getClass())
46: return false;
47:
48: MethodInfo that = (MethodInfo) o;
49:
50: if (!name.equals(that.name))
51: return false;
52: if (!Arrays.equals(parameterTypes, that.parameterTypes))
53: return false;
54: if (!returnType.equals(that.returnType))
55: return false;
56:
57: return true;
58: }
59:
60: public int hashCode() {
61: int result;
62: result = name.hashCode();
63: result = 31 * result + Arrays.hashCode(parameterTypes);
64: result = 31 * result + returnType.hashCode();
65: return result;
66: }
67:
68: public String toString() {
69: StringBuilder params = new StringBuilder("");
70: boolean start = true;
71: for (Class clazz : parameterTypes) {
72: if (!start)
73: params.append(",");
74: params.append(clazz.getName());
75: start = false;
76: }
77:
78: return new StringBuilder(returnType.getName()).append(" ")
79: .append(name).append("(").append(params.toString())
80: .append(")").toString();
81: }
82: }
|