1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace AspectSharp
.Lang
.AST
18 using System
.Collections
;
21 /// Summary description for MethodSignature.
24 public class MethodSignature
26 protected static readonly String ALL_MARK
= "*";
28 private string _access
= string.Empty
;
29 private String _retType
= String
.Empty
;
30 private String _methodName
= String
.Empty
;
31 private ArrayList _arguments
= new ArrayList();
32 private bool _allAccess
= false;
33 private bool _allRetTypes
= false;
34 private bool _allArguments
= false;
36 protected MethodSignature()
40 public MethodSignature(String retType
, String methodName
)
41 : this("*", retType
, methodName
)
45 public MethodSignature(String access
, String retType
, String methodName
)
47 if (ALL_MARK
.EndsWith(access
))
51 if (ALL_MARK
.Equals(retType
))
55 _access
= String
.Intern(access
.ToLower());
56 _retType
= String
.Intern(retType
.ToLower());
57 _methodName
= String
.Intern(methodName
);
60 public void AddArgumentType(String typeName
)
62 if ( _arguments
.Count
== 0 && ALL_MARK
.Equals(typeName
))
68 _allArguments
= false;
70 _arguments
.Add(String
.Intern(typeName
.ToLower()));
83 get { return _retType; }
86 public String MethodName
88 get { return _methodName; }
91 public String
[] Arguments
93 get { return (String[]) _arguments.ToArray(typeof (String)); }
98 get { return _allAccess; }
101 public bool AllRetTypes
103 get { return _allRetTypes; }
106 public bool AllArguments
108 get { return _allArguments; }
111 public override bool Equals(object obj
)
113 MethodSignature otherMethod
= obj
as MethodSignature
;
115 if (otherMethod
== null)
120 if (otherMethod
.AllRetTypes
== AllRetTypes
&&
121 otherMethod
.AllArguments
== AllArguments
&&
122 otherMethod
.ArgumentsHashCode() == ArgumentsHashCode() &&
123 otherMethod
.MethodName
.Equals(MethodName
) &&
124 otherMethod
.RetType
.Equals(RetType
) &&
125 otherMethod
.Access
.Equals(Access
))
133 public override int GetHashCode()
135 return ArgumentsHashCode() ^ MethodName
.GetHashCode() ^ RetType
.GetHashCode() ^ Access
.GetHashCode();
138 public override String
ToString()
140 return String
.Format("({0} {1} {2}{3})", Access
, RetType
, MethodName
, BuildArguments());
143 private int ArgumentsHashCode()
145 int argsHash
= _arguments
.Count
+ 1;
146 foreach(object item
in _arguments
)
148 argsHash
= argsHash ^ item
.GetHashCode();
153 private String
BuildArguments()
157 return "(" + ALL_MARK
+ ")";
159 else if (_arguments
.Count
== 0)
165 // I know this is optimized et al.
168 String signature
= "("; bool comma
= false;
170 foreach(object item
in _arguments
)
172 if (comma
) signature
+= ", "; else comma
= true;
173 signature
+= item
.ToString();