KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > filter > This


1 //
2
// This file is part of the prose package.
3
//
4
// The contents of this file are subject to the Mozilla Public License
5
// Version 1.1 (the "License"); you may not use this file except in
6
// compliance with the License. You may obtain a copy of the License at
7
// http://www.mozilla.org/MPL/
8
//
9
// Software distributed under the License is distributed on an "AS IS" basis,
10
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
// for the specific language governing rights and limitations under the
12
// License.
13
//
14
// The Original Code is prose.
15
//
16
// The Initial Developer of the Original Code is Andrei Popovici. Portions
17
// created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
18
// All Rights Reserved.
19
//
20
// Contributor(s):
21
// $Id: This.java,v 1.2 2003/07/17 11:14:17 apopovic Exp $
22
// =====================================================================
23
//
24
// (history at end)
25
//
26

27 package ch.ethz.prose.filter;
28 import java.util.Collection JavaDoc;
29
30 // used packages
31

32 /**
33  * Class Target is a <em>dynamic</em> filter. A target is the object
34  * receiving a method call or the owner of a field being read or writen.
35  *
36  *
37  * @version $Revision: 1.2 $
38  * @author Andrei Popovici
39  */

40 public
41 class This
42 {
43
44   /** Return a <code>PointCutter</code> that allows advice executions
45    * only for 'this' object that are contained in the specified
46    * collection. Note that according to the java.util.Collection interface,
47    * the comparison <code>this.equalsTo(oneOfTheObjectsInCol)</code>
48    * must return <code>true</code>
49    */

50   public static PointCutter inCollection(Collection JavaDoc col)
51     {
52       PointCutter t = new ObjectInCollectionFilter(ObjectFilter.THIS_OBJECT,col);
53       t.setToString("This.inCollection()");
54       return t;
55     }
56
57
58   /** Return a PointCutter that allows executions only at join-points where
59    * the 'this' object is equal to <code>obj</code>.
60    */

61   public static PointCutter equalsTo(Object JavaDoc obj)
62     {
63       PointCutter t = new ObjectEqualsToFilter(ObjectFilter.THIS_OBJECT,obj);
64       t.setToString("This.equalsTo(" + obj.toString() + ")");
65       return t;
66     }
67
68   /** Return a <code>PointCutter</code> that allows executions at join-points
69    * where <code>this==obj</code>.
70    */

71   public static PointCutter isSameObject(Object JavaDoc obj)
72     {
73       PointCutter t = new ObjectIdenticalToFilter(ObjectFilter.THIS_OBJECT,obj);
74       t.setToString("This.isSameObject(" + obj + ")");
75       return t;
76     }
77
78   /** Return a <code>PointCutter</code> that allows executions at join-points
79    * where <code>this instanceof cls</code>.
80    */

81   public static PointCutter subtypeOf(Class JavaDoc cls)
82     {
83
84       PointCutter t = new ObjectTypeFilter(ObjectFilter.THIS_OBJECT,cls,ObjectTypeFilter.SUBCLASS_INHERITANCE);
85       t.setToString("This.subtypeOf(" + cls.getName() + ")");
86       return t;
87     }
88
89   /** Return a <code>PointCutter</code> that allows executions at join-points
90    * where <code>cls is a subclass/subinterface of this.getClass</code>
91    */

92   public static PointCutter supertypeOf(Class JavaDoc cls)
93     {
94       PointCutter t= new ObjectTypeFilter(ObjectFilter.THIS_OBJECT,cls,ObjectTypeFilter.SUPERCLASS_INHERITANCE);
95       t.setToString("This.superTypeOf(" + cls.getName() + ")");
96       return t;
97     }
98
99   /** Return a <code>PointCutter</code> that allows executions at join-points
100    * with <em>this.class equals cls</em>.
101    */

102   public static PointCutter type(Class JavaDoc cls)
103     {
104       PointCutter t = new ObjectTypeFilter(ObjectFilter.THIS_OBJECT,cls,ObjectTypeFilter.NO_INHERITANCE);
105       t.setToString("This.type(" + cls.getName() + ")");
106       return t;
107     }
108
109   /* Return a <code>PointCutter</code> that allows executions at join-points
110    * where the <em>unqualified</em> class name of <code>this</code> matches
111    * the regexp <code>classRegexp</code>
112    */

113   public static PointCutter type(String JavaDoc classRegexp)
114     {
115       PointCutter t = new ObjectInClassNameFilter(ObjectFilter.THIS_OBJECT,classRegexp);
116       t.setToString("This.type(" + classRegexp+ ")");
117       return t;
118     }
119
120   /** Return a PointCutter that allows execution at join-points
121    * where the pacakge name of <code>this.class</code> matches
122    * the regular expression <code>packageRegexp</code>.
123    */

124   public static PointCutter inPackage(String JavaDoc packageRegexp)
125     {
126       PointCutter t = new ObjectInPackageFilter(ObjectFilter.THIS_OBJECT,packageRegexp);
127       t.setToString("This.inPackage(" + packageRegexp + ")");
128       return t;
129     }
130
131
132
133 }
134 //======================================================================
135
//
136
// $Log: This.java,v $
137
// Revision 1.2 2003/07/17 11:14:17 apopovic
138
// Added inCollection PointCutter. Improved Documentation
139
//
140
// Revision 1.1.1.1 2003/07/02 15:30:52 apopovic
141
// Imported from ETH Zurich
142
//
143
// Revision 1.3 2003/05/25 11:46:50 popovici
144
// Improved 'toString' presentation of aspects
145
//
146
// Revision 1.2 2003/05/06 15:51:44 popovici
147
// Mozilla-ification
148
//
149
// Revision 1.1 2003/05/05 13:57:53 popovici
150
// renaming from runes to prose
151
//
152
// Revision 1.4 2003/04/27 13:08:44 popovici
153
// Specializers renamed to PointCutter
154
//
155
// Revision 1.3 2003/04/26 14:33:48 popovici
156
// subtypeOf, supertypeOf specializers addde to this and target
157
//
158
// Revision 1.2 2003/04/17 14:46:02 popovici
159
// ThiS renamed to This; additional method renamings
160
//
161
// Revision 1.1 2003/04/17 13:59:36 popovici
162
// This class and methods renamed
163
//
164
// Revision 1.5 2003/03/04 18:24:13 popovici
165
// Refactoring of the specializer. De-obfuscation
166
// by exposing the inner classes of the factory methods
167
// The specializer implementations now end in 'filter',
168
// whereas the old factory methods 'xxxS' remain
169
// pure bootstrap objects.
170
//
171
// Revision 1.4 2003/03/04 11:27:24 popovici
172
// Important refactorization step (march):
173
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
174
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
175
// structures
176
//
177
// Revision 1.3 2002/10/25 07:42:37 popovici
178
// Undo Chnages Phillippe
179
//
180
// Revision 1.1 2002/05/16 09:19:11 popovici
181
// ClasseS and CFlow replaced with Target, This; the crosscut spec package is refactorized. Now all
182
// crosscuts are grouped (abstract definitions + concrete definitions). Crosscuts explicitely are dynamic and static, and
183
// or/Not/And combinations can be created.
184
//
185
Popular Tags