01: /*
02: * Copyright 2003 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 name;
26: private String desc;
27:
28: public Signature(String name, String desc) {
29: // TODO: better error checking
30: if (name.indexOf('(') >= 0) {
31: throw new IllegalArgumentException("Name '" + name
32: + "' is invalid");
33: }
34: this .name = name;
35: this .desc = desc;
36: }
37:
38: public Signature(String name, Type returnType, Type[] argumentTypes) {
39: this (name, Type.getMethodDescriptor(returnType, argumentTypes));
40: }
41:
42: public String getName() {
43: return name;
44: }
45:
46: public String getDescriptor() {
47: return desc;
48: }
49:
50: public Type getReturnType() {
51: return Type.getReturnType(desc);
52: }
53:
54: public Type[] getArgumentTypes() {
55: return Type.getArgumentTypes(desc);
56: }
57:
58: public String toString() {
59: return name + desc;
60: }
61:
62: public boolean equals(Object o) {
63: if (o == null)
64: return false;
65: if (!(o instanceof Signature))
66: return false;
67: Signature other = (Signature) o;
68: return name.equals(other.name) && desc.equals(other.desc);
69: }
70:
71: public int hashCode() {
72: return name.hashCode() ^ desc.hashCode();
73: }
74: }
|