blob: 948bbef577f3a4f658682385b2e5ce2cfe5af00d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/* *******************************************************************
* Copyright (c) 2003 Contributors.
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Common Public License v1.0
* which accompanies this distribution and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* Wes Isberg initial implementation
* ******************************************************************/
// START-SAMPLE library-pointcutIdioms Standard pointcut idioms
package org.aspectj.langlib;
import java.io.*;
/**
* Library of pointcut idioms to use in combination with
* other pointcuts.
*
* @author Wes Isberg
*/
public class Pointcuts {
// ------- not staticly-determinable
public pointcut adviceCflow() : cflow(adviceexecution());
public pointcut notInAdviceCflow() : !adviceCflow();
public pointcut cflowMainExecution() :
cflow(mainExecution());
// ------- staticly-determinable
public pointcut mainExecution() :
execution(public static void main(String[]));
/** staticly-determinable to never match any join point */
public pointcut never() : if(false)
&& execution(ThreadDeath *(ThreadDeath, ThreadDeath));
public pointcut anyMethodExecution() :
execution(* *(..));
public pointcut anyPublicMethodExecution() :
execution(public * *(..));
public pointcut anyNonPrivateMethodExecution() :
execution(!private * *(..));
public pointcut anyConstructorExecution() :
execution(new(..));
public pointcut anyPublicConstructorExecution() :
execution(public new(..));
public pointcut anyNonPrivateConstructorExecution() :
execution(!private new(..));
public pointcut anyPublicFieldGet() :
get(public * *);
public pointcut anyNonPrivateFieldGet() :
get(!private * *);
public pointcut anyPublicFieldSet() :
set(public * *);
public pointcut anyNonPrivateFieldSet() :
set(!private * *); // also !transient?
public pointcut withinSetter() :
withincode(* set*(..));
public pointcut withinGetter() :
withincode(Object+ get*(..));
public pointcut anyNonPublicFieldSetOutsideConstructorOrSetter() :
set(!public * *) && !withincode(new(..))
&& !withinSetter();
public pointcut anyRunnableImplementation() :
staticinitialization(Runnable+);
public pointcut anyGetSystemErrOut() :
get(PrintStream System.err) || get(PrintStream System.out);
public pointcut anySetSystemErrOut() :
call(void System.setOut(..)) || call(void System.setErr(..));
public pointcut withinAnyJavaCode() :
within(java..*) || within(javax..*);
public pointcut notWithinJavaCode() :
!withinAnyJavaCode();
public pointcut toStringExecution() :
execution(String toString()) && !within(String);
/** call or execution of any Thread constructor, including subclasses */
public pointcut anyThreadConstruction() :
call(Thread+.new(..)) || execution(Thread+.new(..));
/**
* Any calls to java.io classes
* (but not methods declared only on their subclasses).
*/
public pointcut anyJavaIOCalls() :
call(* java.io..*.*(..)) || call(java.io..*.new(..));
/**
* Any calls to java.awt or javax.swing classes
* (but not methods declared only on their subclasses).
*/
public pointcut anyJavaAWTOrSwingCalls() :
call(* java.awt..*.*(..)) || call(java.awt..*.new(..))
|| call(* javax.swing..*.*(..)) || call(javax.swing..*.new(..));
public pointcut cloneImplementationsInNonCloneable() :
execution(Object !Cloneable+.clone());
public pointcut runImplementationsInNonRunnable() :
execution(void !Runnable+.run());
/** any calls to java.lang.reflect or Class.get* (except getName()) */
public pointcut anySystemReflectiveCalls() :
call(* java.lang.reflect..*.*(..))
|| (!call(* Class.getName())
&& call(* Class.get*(..)));
/** standard class-loading calls by Class and ClassLoader */
public pointcut anySystemClassLoadingCalls() :
call(Class Class.forName(..))
|| call(Class ClassLoader.loadClass(..));
public pointcut anySystemProcessSpawningCalls() :
call(Process Runtime.exec(..))
|| call(Class ClassLoader.loadClass(..));
public pointcut mostThrowableReadCalls() :
call(* Throwable+.get*(..))
|| call(* Throwable+.print*(..))
|| call(String Throwable+.toString(..));
public pointcut exceptionWrappingCalls() :
(args(Throwable+,..) || args(.., Throwable+))
&& (set(Throwable+ Throwable+.*)
|| (call(* Throwable+.*(..))
|| call(Throwable+.new(..))));
private Pointcuts() {}
}
//END-SAMPLE library-pointcutIdioms
aspect A {
private static aspect PointcutsOnly {
/** require this library to only contain pointcuts */
declare error : within(Pointcuts) &&
(Pointcuts.anyMethodExecution()
|| Pointcuts.anyNonPrivateConstructorExecution()
|| set(* *)) : "only pointcuts permitted in Pointcuts";
// does not pick out field definitions -- too costly
// set(* Pointcuts.*) || get(* Pointcuts.*)
}
}
class PointcutQuestions {
public pointcut anyCodeThrowingException() : // XXX broken?
execution(* *(..) throws Exception+)
|| execution(new(..) throws Exception+);
}
|