Clover.NET coverage report - Coverage for s2container.net

Coverage timestamp: 2006年5月30日 11:21:29

File Stats: LOC: 150   Methods: 8
NCLOC: 90 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Framework.Aop\Impl\PointcutImpl.cs 87.5% 94.6% 100.0% 93.4%
coverage coverage
1   #region Copyright
2   /*
3   * Copyright 2005 the Seasar Foundation and the Others.
4   *
5   * Licensed under the Apache License, Version 2.0 (the "License");
6   * you may not use this file except in compliance with the License.
7   * You may obtain a copy of the License at
8   *
9   * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14   * either express or implied. See the License for the specific language
15   * governing permissions and limitations under the License.
16   */
17   #endregion
18  
19   using System;
20   using System.Collections;
21   using System.Reflection;
22   using System.Text.RegularExpressions;
23   using Seasar.Framework.Exceptions;
24  
25   namespace Seasar.Framework.Aop.Impl
26   {
27   /// <summary>
28   /// IPointcutインターフェイスの実装
29   /// </summary>
30   [Serializable]
31   public sealed class PointcutImpl : IPointcut
32   {
33   /// <summary>
34   /// コンパイル済みメソッド名の正規表現
35   /// </summary>
36   private Regex[] regularExpressions_;
37  
38   /// <summary>
39   /// メソッド名の正規表現文字列
40   /// </summary>
41   private string[] methodNames_;
42  
43   /// <summary>
44   /// コンストラクタ
45   /// </summary>
46 3 public PointcutImpl(Type targetType)
47   {
48 0 if(targetType == null) throw new EmptyRuntimeException("targetType");
49 3 this.SetMethodNames(GetMethodNames(targetType));
50   }
51  
52   /// <summary>
53   /// コンストラクタ
54   /// </summary>
55   /// <param name="methodNames">メソッド名の正規表現文字列の配列</param>
56 7 public PointcutImpl(string[] methodNames)
57   {
58 7 if(methodNames == null || methodNames.Length == 0)
59 0 throw new EmptyRuntimeException("methodNames");
60 7 this.SetMethodNames(methodNames);
61   }
62  
63   #region IPointcut メンバ
64  
65   /// <summary>
66   /// 引数で渡されたmethodにAdviceを挿入するか確認します
67   /// </summary>
68   /// <param name="method">MethodBase メソッドとコンストラクタに関する情報を持っています</param>
69   /// <returns>TrueならAdviceを挿入する、FalseならAdviceは挿入されない</returns>
70 12 public bool IsApplied(MethodBase method)
71   {
72 12 return this.IsApplied(method.Name);
73   }
74  
75   /// <summary>
76   /// 引数で渡されたメソッド名にAdviceを挿入するか確認します
77   /// </summary>
78   /// <param name="methodName">メソッド名</param>
79   /// <returns>TrueならAdviceを挿入する、FalseならAdviceは挿入されない</returns>
80 25 public bool IsApplied(string methodName)
81   {
82 25 foreach(Regex regex in regularExpressions_)
83   {
84 28 if(regex.Match(methodName).Success) return true;
85   // if(m.Success && (string.Compare(methodName, m.Value) == 0)) return true;
86   }
87 14 return false;
88   }
89  
90   #endregion
91  
92   /// <summary>
93   /// メソッド名の正規表現文字列
94   /// </summary>
95   public string[] MethodNames
96   {
97 3 get { return methodNames_; }
98   }
99  
100 10 private void SetMethodNames(string[] methodNames)
101   {
102 10 methodNames_ = methodNames;
103 10 regularExpressions_ = new Regex[methodNames.Length];
104 24 for(int i = 0; i < methodNames.Length; ++i)
105   {
106 14 string methodName = @"^" + methodNames[i].Trim() + "$";
107 14 regularExpressions_[i] = new Regex(methodName, RegexOptions.Compiled);
108   }
109   }
110  
111 3 private static string[] GetMethodNames(Type targetType)
112   {
113 3 Hashtable methodNameList = new Hashtable();
114 3 if(targetType.IsInterface) AddInterfaceMethodNames(methodNameList,targetType);
115 7 for(Type type = targetType; type != typeof(object) && type != null; type = type.BaseType)
116   {
117 4 Type[] interfaces = type.GetInterfaces();
118 4 foreach(Type interfaceTemp in interfaces)
119   {
120 6 AddInterfaceMethodNames(methodNameList,interfaceTemp);
121   }
122   }
123 3 string[] methodNames = new string[methodNameList.Count];
124 3 IEnumerator enu = methodNameList.Keys.GetEnumerator();
125 3 int i = 0;
126 9 while(enu.MoveNext())
127   {
128 6 methodNames[i++] = (string) enu.Current;
129   }
130 3 return methodNames;
131   }
132  
133 10 private static void AddInterfaceMethodNames(Hashtable methodNameList, Type interfaceType)
134   {
135 10 MethodInfo[] methods = interfaceType.GetMethods();
136 10 foreach(MethodInfo method in methods)
137   {
138 10 if(!methodNameList.ContainsKey(method.Name))
139 6 methodNameList.Add(method.Name,null);
140   }
141 10 Type[] interfaces = interfaceType.GetInterfaces();
142 10 foreach(Type interfaceTemp in interfaces)
143   {
144 3 AddInterfaceMethodNames(methodNameList,interfaceTemp);
145   }
146   }
147  
148   }
149   }
150