View Javadoc

1   package com.silvermindsoftware.hitch.reflect;
2   
3   import java.lang.reflect.Method;
4   import java.util.Arrays;
5   
6   /**
7    * Copyright 2007 Brandon Goodin
8    *
9    * 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  /**
23   * @svnLink $Revision: 3881 $;$Date: 2009-08-04 15:22:05 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/swing/src/main/java/com/silvermindsoftware/hitch/reflect/MethodInfo.java $
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  }