/usr/share/doc/aspectj-doc/adk15notebook/varargs-in-pcds.html is in aspectj-doc 1.8.9-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Using Variable-length arguments in advice and pointcut expressions</title><link rel="stylesheet" type="text/css" href="aspectj-docs.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="index.html" title="The AspectJTM 5 Development Kit Developer's Notebook"><link rel="up" href="varargs.html" title="Chapter 6. Varargs"><link rel="prev" href="varargs.html" title="Chapter 6. Varargs"><link rel="next" href="enumeratedtypes.html" title="Chapter 7. Enumerated Types"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Using Variable-length arguments in advice and pointcut expressions</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="varargs.html">Prev</a> </td><th width="60%" align="center">Chapter 6. Varargs</th><td width="20%" align="right"> <a accesskey="n" href="enumeratedtypes.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="varargs-in-pcds"></a>Using Variable-length arguments in advice and pointcut expressions</h2></div></div></div><p>AspectJ 5 allows variable-length arguments to be used for methods declared within
aspects, and for inter-type declared methods and constructors, in accordance with the rules
outlined in the previous section.</p><p>
AspectJ 5 also allows variable length arguments to be matched by pointcut expressions and
bound as formals in advice.
</p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="matching-signatures-based-on-variable-length-argument-types"></a>Matching signatures based on variable length argument types</h3></div></div></div><p>
Recall from the definition of signature patterns given in the chapter on
annotations (<a class="xref" href="annotations-pointcuts-and-advice.html#signaturePatterns" title="Signature Patterns">Signature Patterns</a>), that <code class="literal">MethodPattern</code>
and <code class="literal">ConstructorPattern</code> are extended to allow a <code class="literal">varargs</code>
pattern in the last argument position of a method or constructor signature.
</p><pre class="programlisting">
FormalsPattern := '..' (',' FormalsPatternAfterDotDot)? |
OptionalParensTypePattern (',' FormalsPattern)* |
TypePattern '...'
FormalsPatternAfterDotDot :=
OptionalParensTypePattern (',' FormalsPatternAfterDotDot)* |
TypePattern '...'
</pre><p>
Method and constructor patterns are used in the <code class="literal">call</code>,
<code class="literal">execution</code>, <code class="literal">initialization</code>,
<code class="literal">preinitialization</code>, and <code class="literal">withincode</code>
pointcut designators. Some examples of usage follow:
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">call(* org.xyz.*.*(int, String...))</span></dt><dd><p>
Matches a call join point for a call to a method defined in the
<code class="literal">org.xyz</code> package, taking an <code class="literal">int</code>
and a <code class="literal">String vararg</code>.
</p></dd><dt><span class="term">execution(* org.xyz.*.*(Integer...))</span></dt><dd><p>
Matches an execution join point for the execution of a method defined in the
<code class="literal">org.xyz</code> package, taking an <code class="literal">Integer vararg</code>.
</p></dd><dt><span class="term">initialization(org.xyz.*.new((Foo || Goo)...))</span></dt><dd><p>
Matches the initialization join point for the construction of an
object in the <code class="literal">org.xyz</code> package via a constructor
taking either a variable number of <code class="literal">Foo</code> parameters or
a variable number of <code class="literal">Goo</code> parameters. (This example
illustrating the use of a type pattern with ...).
</p></dd></dl></div><p>A variable argument parameter and an array parameter are treated as distinct
signature elements, so given the method definitions:
</p><pre class="programlisting">
void foo(String...);
void bar(String[]);
</pre><p>
The pointcut <code class="literal">execution(* *.*(String...))</code> matches the execution join point
for <code class="literal">foo</code>, but not <code class="literal">bar</code>. The pointcut
<code class="literal">execution(* *.*(String[]))</code> matches the execution join point
for <code class="literal">bar</code> but not <code class="literal">foo</code>.
</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="exposing-variable-length-arguments-as-context-in-pointcuts-and-advice"></a>Exposing variable-length arguments as context in pointcuts and advice</h3></div></div></div><p>
When a varargs parameter is used within the body of a method, it has
an array type, as discussed in the introduction to this section. We follow the
same convention when binding a varargs parameter via the <code class="literal">args</code>
pointcut designator. Given a method
</p><pre class="programlisting">
public void foo(int i, String... strings) {
}
</pre><p>
The call or execution join points for <code class="literal">foo</code> will be matched
by the pointcut <code class="literal">args(int,String[])</code>. It is not permitted
to use the varargs syntax within an args pointcut designator - so you
<span class="emphasis"><em>cannot</em></span> write <code class="literal">args(int,String...)</code>.
</p><p>
Binding of a varargs parameter in an advice statement is straightforward:
</p><pre class="programlisting">
before(int i, String[] ss) : call(* foo(int,String...)) && args(i,ss) {
// varargs String... argument is accessible in advice body through ss
// ...
}
</pre><p>Since you cannot use the varargs syntax in the <code class="literal">args</code>
pointcut designator, you also cannot use the varargs syntax to declare
advice parameters.</p><p>Note: the proposal in this section does not allow you to
distinguish between a join point with a signature (int, String...)
and a join point with a signature (int, String[]) based
<span class="emphasis"><em>solely</em></span> on the use of the <code class="literal">args</code>
pointcut designator. If this distinction is required, <code class="literal">args</code>
can always be coupled with <code class="literal">call</code> or
<code class="literal">execution</code>.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="varargs.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="varargs.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="enumeratedtypes.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 6. Varargs </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 7. Enumerated Types</td></tr></table></div></body></html>
|