|
|
@@ -1,6 +1,5 @@ |
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
|
|
|
<html> <head> |
|
|
|
<meta http-equiv="Content-Language" content="en-us"> |
|
|
|
<title>AspectJ Reference - Porting Notes</title> |
|
|
|
</head> |
|
|
|
<body> |
|
|
@@ -37,19 +36,21 @@ of the changes between 1.1 and 1.2. The key points are: |
|
|
|
<p><b>The default AspectJ compiler compliance level is now 1.4</b> (whereas in |
|
|
|
previous releases the default compliance level was 1.3). This has a number |
|
|
|
of implications: |
|
|
|
</p> |
|
|
|
<ul> |
|
|
|
<li> class files generated by the compiler are now JRE v1.2 and upwards |
|
|
|
compatible. (At compliance level 1.3, AspectJ generated class files that |
|
|
|
were compatible with JRE 1.1 also). |
|
|
|
were compatible with JRE 1.1 also).</li> |
|
|
|
<li> <code>call</code> pointcuts may match more join points than in the same |
|
|
|
program compiled at compliance level 1.3. |
|
|
|
program compiled at compliance level 1.3.</li> |
|
|
|
</ul> |
|
|
|
<p> |
|
|
|
The AspectJ compiler can be restored to 1.3 compliance settings by specifying the |
|
|
|
"-1.3" option on the command-line. |
|
|
|
</p> |
|
|
|
<p>The following example program illustrates the differences in join point matching |
|
|
|
with the <code>call</code> pointcut designator between 1.4 and 1.3 compliance levels. |
|
|
|
|
|
|
|
</p> |
|
|
|
<pre> |
|
|
|
<code> |
|
|
|
01 class A { |
|
|
@@ -82,22 +83,27 @@ with the <code>call</code> pointcut designator between 1.4 and 1.3 compliance le |
|
|
|
28 } |
|
|
|
</code> |
|
|
|
</pre> |
|
|
|
|
|
|
|
<p> |
|
|
|
When this program is compiled with AspectJ 1.2 using the default compiler options, |
|
|
|
it will produce one line of output when it is executed: |
|
|
|
<p><code>About to call B.doIt(...)</code> |
|
|
|
</p> |
|
|
|
<p><code>About to call B.doIt(...)</code></p> |
|
|
|
<p>The same program compiled under AspectJ 1.1 (or using AspectJ 1.2 with the -1.3 flag specified) |
|
|
|
does not produce any output when it is run. |
|
|
|
</p> |
|
|
|
|
|
|
|
<p> |
|
|
|
The reason for the additional call pcd match is that prior to compliance level 1.4, |
|
|
|
Java compilers produced bytecodes that call A.doIt() (the defining type of the method), |
|
|
|
rather than B.doIt() (the declared type in the program text). The generated call to |
|
|
|
A.doIt() is not matched by the call pcd used in the before advice. At |
|
|
|
compliance level 1.4, the bytecodes retain the declared type of the receiver in the |
|
|
|
program source, generating a call to B.doIt(), which <i>is</i> matched by the call pcd. |
|
|
|
</p> |
|
|
|
|
|
|
|
<p>This is a good example of why the recommended style is to use <code>call(* doIt(..)) && target(B)</code>, |
|
|
|
which always matches based on the actual type of the receiver. |
|
|
|
</p> |
|
|
|
|
|
|
|
<p><b>New warnings emitted by the compiler for unmatched call pcds.</b> Because users have found |
|
|
|
the static type matching used for a type pattern specified in a <code>call</code> pcd confusing |
|
|
@@ -105,6 +111,7 @@ the static type matching used for a type pattern specified in a <code>call</code |
|
|
|
The compiler will now produce a warning whenever a call pointcut designator does not match at a |
|
|
|
join point, and a user may have expected it to. Compiling the above program using AspectJ 1.2 |
|
|
|
produces the following compiler output: |
|
|
|
</p> |
|
|
|
|
|
|
|
<pre> |
|
|
|
<code> |
|
|
@@ -144,6 +151,21 @@ statment. When moving code from 1.1 to 1.2, additional errors may be raised due |
|
|
|
rule. The solution is to recode the declare statement avoiding pointcut expressions that may require a run-time test. |
|
|
|
</p> |
|
|
|
|
|
|
|
<p><b>Declaring a constructor on an interface</b> is now (correctly) prohibited. |
|
|
|
To initialize a field declared on an interface, use initialization, e.g., |
|
|
|
</p> |
|
|
|
<pre>int I.i; |
|
|
|
after(I i) returning: initialization(I) && this(i) { i.i = 2; }</pre> |
|
|
|
<p>For more information, see bug |
|
|
|
<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=49295">49295</a>. |
|
|
|
</p> |
|
|
|
|
|
|
|
<p><b>Declaring a static method on an interface</b> is now (correctly) prohibited. |
|
|
|
One workaround is to define a static method on the aspect instead. |
|
|
|
For more information, see bug |
|
|
|
<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=47754">47754</a>. |
|
|
|
</p> |
|
|
|
|
|
|
|
<h2><a name="pre-1.1">Porting pre-1.1 code to AspectJ 1.1</a></h2> |
|
|
|
<a href="README-11.html">README-11.html</a> contains a discussion |
|
|
|
of the language changes from 1.0 to 1.1. The high points: |