Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / AspectSharp / AspectSharp.Lang / AST / MethodSignature.cs
blob62f564a7dec99b2ad960135bdedd0fbd6d97a7fc
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
18 using System.Collections;
20 /// <summary>
21 /// Summary description for MethodSignature.
22 /// </summary>
23 [Serializable]
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))
49 _allAccess = true;
51 if (ALL_MARK.Equals(retType))
53 _allRetTypes = true;
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))
64 _allArguments = true;
66 else
68 _allArguments = false;
70 _arguments.Add(String.Intern(typeName.ToLower()));
73 public string Access
75 get
77 return _access;
81 public String RetType
83 get { return _retType; }
86 public String MethodName
88 get { return _methodName; }
91 public String[] Arguments
93 get { return (String[]) _arguments.ToArray(typeof (String)); }
96 public bool AllAccess
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)
117 return false;
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))
127 return true;
130 return false;
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();
150 return argsHash;
153 private String BuildArguments()
155 if (_allArguments)
157 return "(" + ALL_MARK + ")";
159 else if (_arguments.Count == 0)
161 return "()";
163 else
165 // I know this is optimized et al.
166 // TODO: Refactor
168 String signature = "("; bool comma = false;
170 foreach(object item in _arguments)
172 if (comma) signature += ", "; else comma = true;
173 signature += item.ToString();
176 signature += ")";
178 return signature;