aboutsummaryrefslogtreecommitdiffstats
path: root/docs/progGuideDB/quickreference.adoc
blob: 01b152e31d9a4ea6dc62f08358b4afd4de86fb5d (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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
[[quick]]
== AspectJ Quick Reference

[[quick-pointcuts]]
=== Pointcuts

[cols=",",]
|===
|*Methods and Constructors* |

|`call(Signature)` |every call to any method or constructor matching
<Signature> at the call site

|`execution(Signature)` |every execution of any method or constructor
matching <Signature>

|*Fields* |

|`get(Signature)` |every reference to any field matching <Signature>

|`set(Signature)` |every assignment to any field matching <Signature>.
The assigned value can be exposed with an `args` pointcut

|*Exception Handlers* |

|`handler(TypePattern)` |every exception handler for any `Throwable`
type in <TypePattern>. The exception value can be exposed with an `args`
pointcut

|*Advice* |

|`adviceexecution()` |every execution of any piece of advice

|*Initialization* |

|`staticinitialization(TypePattern)` |every execution of a static
initializer for any type in <TypePattern>

|`initialization(Signature)` |every initialization of an object when the
first constructor called in the type matches <Signature>, encompassing
the return from the super constructor call to the return of the
first-called constructor

|`preinitialization(Signature)` |every pre-initialization of an object
when the first constructor called in the type matches <Signature>,
encompassing the entry of the first-called constructor to the call to
the super constructor

|*Lexical* |

|`within(TypePattern)` |every join point from code defined in a type in
<TypePattern>

|`withincode(Signature)` |every join point from code defined in a method
or constructor matching <Signature>
|===

[[quick-typePatterns]]
=== Type Patterns

A type pattern is one of

[cols=",",]
|===
|<TypeNamePattern> |all types in <TypeNamePattern>

|<SubtypePattern> |all types in <SubtypePattern>, a pattern with a +.

|<ArrayTypePattern> |all types in <ArrayTypePattern>, a pattern with one
or more []s.

|`!TypePattern` |all types not in <TypePattern>

|`TypePattern0
            && TypePattern1` |all types in both <TypePattern0> and
<TypePattern1>

|`TypePattern0 || TypePattern1` |all types in either <TypePattern0> or
<TypePattern1>

|`( TypePattern )` |all types in <TypePattern>
|===

where <TypeNamePattern> can either be a plain type name, the wildcard
`*` (indicating all types), or an identifier with embedded `*` and `..`
wildcards.

An embedded `*` in an identifier matches any sequence of characters, but
does not match the package (or inner-type) separator ".".

An embedded `..` in an identifier matches any sequence of characters
that starts and ends with the package (or inner-type) separator ".".

[[quick-advice]]
=== Advice

Each piece of advice is of the form

____
[ strictfp ]

AdviceSpec

[ throws

TypeList

] :

Pointcut

\{

Body

}
____

where <AdviceSpec> is one of

`before( Formals ) `::
  runs before each join point
`after( Formals ) returning
          [ ( Formal ) ] `::
  runs after each join point that returns normally. The optional formal
  gives access to the returned value
`after( Formals ) throwing [
          ( Formal ) ] `::
  runs after each join point that throws a
  +
  Throwable
  +
  . If the optional formal is present, runs only after each join point
  that throws a
  +
  Throwable
  +
  of the type of
  +
  Formal
  +
  , and
  +
  Formal
  +
  gives access to the
  +
  Throwable
  +
  exception value
`after( Formals ) `::
  runs after each join point regardless of whether it returns normally
  or throws a
  +
  Throwable
`Type
          around( Formals ) `::
  runs in place of each join point. The join point can be executed by
  calling
  +
  proceed
  +
  , which takes the same number and types of arguments as the around
  advice.

Three special variables are available inside of advice bodies:

`thisJoinPoint`::
  an object of type
  +
  org.aspectj.lang.JoinPoint
  +
  representing the join point at which the advice is executing.
`thisJoinPointStaticPart`::
  equivalent to
  +
  thisJoinPoint.getStaticPart()
  +
  , but may use fewer runtime resources.
`thisEnclosingJoinPointStaticPart`::
  the static part of the dynamically enclosing join point.

[[quick-interType]]
=== Inter-type member declarations

Each inter-type member is one of

`
            Modifiers ReturnType OnType . Id
            ( Formals )
            [ throws TypeList ]
            { Body }
          `::
  a method on
  +
  OnType
  +
  .
`
            abstract Modifiers ReturnType OnType . Id
            ( Formals )
            [ throws TypeList ] ;
          `::
  an abstract method on
  +
  OnType
  +
  .
`
            Modifiers OnType .  new
            ( Formals )
            [ throws TypeList ]
            { Body }
          `::
  a constructor on
  +
  OnType
  +
  .
`
            Modifiers Type OnType . Id
            [ = Expression ] ;
          `::
  a field on
  +
  OnType
  +
  .

[[quick-other]]
=== Other declarations

`
            declare parents :
            TypePattern extends
            Type ;
          `::
  the types in
  +
  TypePattern
  +
  extend
  +
  Type
  +
  .
`
            declare parents : TypePattern
            implements TypeList ;
          `::
  the types in
  +
  TypePattern
  +
  implement the types in
  +
  TypeList
  +
  .
`
            declare warning : Pointcut :
            String ;
          `::
  if any of the join points in
  +
  Pointcut
  +
  possibly exist in the program, the compiler emits the warning
  +
  String
  +
  .
`
            declare error : Pointcut :
            String ;
          `::
  if any of the join points in
  +
  Pointcut
  +
  could possibly exist in the program, the compiler emits the error
  +
  String
  +
  .
`
            declare soft :
            Type :
            Pointcut ;
          `::
  any
  +
  Type
  +
  exception that gets thrown at any join point picked out by
  +
  Pointcut
  +
  is wrapped in
  +
  org.aspectj.lang.SoftException
  +
  .
`
            declare precedence :
            TypePatternList ;
          `::
  at any join point where multiple pieces of advice apply, the advice
  precedence at that join point is in
  +
  TypePatternList
  +
  order.

[[quick-aspectAssociations]]
=== Aspects

Each aspect is of the form

____
[ privileged ]

Modifiers

aspect

Id

[ extends

Type

] [ implements

TypeList

] [

PerClause

] \{

Body

}
____

where <PerClause> defines how the aspect is instantiated and associated
(`issingleton()` by default):

[cols=",,",options="header",]
|===
|PerClause |Description |Accessor
|[ `issingleton()` ] |One instance of the aspect is made. This is the
default. |`aspectOf()` at all join points

|`perthis(Pointcut)` |An instance is associated with each object that is
the currently executing object at any join point in <Pointcut>.
|`aspectOf(Object)` at all join points

|`pertarget(Pointcut)` |An instance is associated with each object that
is the target object at any join point in <Pointcut>.
|`aspectOf(Object)` at all join points

|`percflow(Pointcut)` |The aspect is defined for each entrance to the
control flow of the join points defined by <Pointcut>. |`aspectOf()` at
join points in `cflow(Pointcut)`

|`percflowbelow(Pointcut)` |The aspect is defined for each entrance to
the control flow below the join points defined by <Pointcut>.
|`aspectOf()` at join points in `cflowbelow(Pointcut)`
|===