1 package com.silvermindsoftware.hitch.reflect;
2
3 import java.lang.reflect.Method;
4 import java.util.Arrays;
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 public class MethodInfo {
26
27 private Method method;
28 private String name;
29 private Class[] parameterTypes;
30 private Class returnType;
31
32 public MethodInfo(Method method) {
33
34 this.method = method;
35 this.returnType = method.getReturnType();
36 this.name = method.getName();
37 this.parameterTypes = method.getParameterTypes();
38
39 }
40
41 public Method getMethod() {
42 return method;
43 }
44
45 public boolean equals(Object o) {
46 if (this == o) return true;
47 if (o == null || getClass() != o.getClass()) return false;
48
49 MethodInfo that = (MethodInfo) o;
50
51 if (!name.equals(that.name)) return false;
52 if (!Arrays.equals(parameterTypes, that.parameterTypes)) return false;
53 if (!returnType.equals(that.returnType)) return false;
54
55 return true;
56 }
57
58 public int hashCode() {
59 int result;
60 result = name.hashCode();
61 result = 31 * result + Arrays.hashCode(parameterTypes);
62 result = 31 * result + returnType.hashCode();
63 return result;
64 }
65
66
67 public String toString() {
68 StringBuilder params = new StringBuilder("");
69 boolean start = true;
70 for(Class clazz : parameterTypes ) {
71 if(!start) params.append(",");
72 params.append(clazz.getName());
73 start = false;
74 }
75
76 return new StringBuilder(returnType.getName())
77 .append(" ").append(name)
78 .append("(").append(params.toString()).append(")").toString();
79 }
80 }