KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > cglib > core > Signature


1 /*
2  * Copyright 2003 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package net.sf.cglib.core;
17
18 import org.objectweb.asm.Type;
19
20 /**
21  * A representation of a method signature, containing the method name,
22  * return type, and parameter types.
23  */

24 public class Signature {
25     private String JavaDoc name;
26     private String JavaDoc desc;
27
28     public Signature(String JavaDoc name, String JavaDoc desc) {
29         // TODO: better error checking
30
if (name.indexOf('(') >= 0) {
31             throw new IllegalArgumentException JavaDoc("Name '" + name + "' is invalid");
32         }
33         this.name = name;
34         this.desc = desc;
35     }
36
37     public Signature(String JavaDoc name, Type returnType, Type[] argumentTypes) {
38         this(name, Type.getMethodDescriptor(returnType, argumentTypes));
39     }
40
41     public String JavaDoc getName() {
42         return name;
43     }
44
45     public String JavaDoc getDescriptor() {
46         return desc;
47     }
48
49     public Type getReturnType() {
50         return Type.getReturnType(desc);
51     }
52
53     public Type[] getArgumentTypes() {
54         return Type.getArgumentTypes(desc);
55     }
56
57     public String JavaDoc toString() {
58         return name + desc;
59     }
60
61     public boolean equals(Object JavaDoc o) {
62         if (o == null)
63             return false;
64         if (!(o instanceof Signature))
65             return false;
66         Signature other = (Signature)o;
67         return name.equals(other.name) && desc.equals(other.desc);
68     }
69
70     public int hashCode() {
71         return name.hashCode() ^ desc.hashCode();
72     }
73 }
74
Popular Tags