<html><head> | |
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | |
<title>Declare statements</title><link rel="stylesheet" href="aspectj-docs.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.44"><link rel="home" href="index.html" title="The AspectJTM 5 Development Kit Developer's Notebook"><link rel="up" href="ataspectj.html" title="Chapter 9. An Annotation Based Development Style"><link rel="previous" href="ataspectj-itds.html" title="Inter-type Declarations"><link rel="next" href="ataspectj-aspectof.html" title="aspectOf() and hasAspect() methods"></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">Declare statements</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ataspectj-itds.html">Prev</a> </td><th width="60%" align="center">Chapter 9. An Annotation Based Development Style</th><td width="20%" align="right"> <a accesskey="n" href="ataspectj-aspectof.html">Next</a></td></tr></table><hr></div><div class="sect1"><a name="ataspectj-declare"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ataspectj-declare"></a>Declare statements</h2></div></div><p>The previous section on inter-type declarations covered the case | |
of declare parents ... implements. The 1.5.0 release of AspectJ 5 does | |
not support annotation style declarations for declare parents ... extends | |
and declare soft (programs with these declarations would not in general | |
be compilable by a regular Java 5 compiler, reducing the priority of | |
their implementation). These may be supported in a future release.</p><p> | |
Declare annotation is also not supported in the 1.5.0 release of AspectJ 5. | |
</p><p>Declare precedence <span class="emphasis"><i>is</i></span> | |
supported. For declare precedence, use the | |
<tt>@DeclarePrecedence</tt> | |
annotation as in the following example: | |
</p><pre class="programlisting"> | |
public aspect SystemArchitecture { | |
declare precedence : Security*, TransactionSupport, Persistence; | |
// ... | |
} | |
can be written as: | |
@Aspect | |
@DeclarePrecedence("Security*,org.xyz.TransactionSupport,org.xyz.Persistence") | |
public class SystemArchitecture { | |
// ... | |
} | |
</pre><p>We also support annotation style declarations for declare warning and | |
declare error - any corresponding warnings and errors will be emitted at | |
weave time, not when the aspects containing the declarations are compiled. | |
(This is the same behaviour as when using declare warning or error with the | |
code style). Declare warning and error declarations are made by annotating | |
a string constant whose value is the message to be issued.</p><p>Note that the String must be a literal and not the result of the invocation | |
of a static method for example.</p><pre class="programlisting"> | |
declare warning : call(* javax.sql..*(..)) && !within(org.xyz.daos..*) | |
: "Only DAOs should be calling JDBC."; | |
declare error : execution(* IFoo+.*(..)) && !within(org.foo..*) | |
: "Only foo types can implement IFoo"; | |
can be written as... | |
@DeclareWarning("call(* javax.sql..*(..)) && !within(org.xyz.daos..*)") | |
static final String aMessage = "Only DAOs should be calling JDBC."; | |
@DeclareError("execution(* IFoo+.*(..)) && !within(org.foo..*)") | |
static final String badIFooImplementors = "Only foo types can implement IFoo"; | |
// the following is not valid since the message is not a String literal | |
@DeclareError("execution(* IFoo+.*(..)) && !within(org.foo..*)") | |
static final String badIFooImplementorsCorrupted = getMessage(); | |
static String getMessage() { | |
return "Only foo types can implement IFoo " + System.currentTimeMillis(); | |
} | |
</pre></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ataspectj-itds.html">Prev</a> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right"> <a accesskey="n" href="ataspectj-aspectof.html">Next</a></td></tr><tr><td width="40%" align="left">Inter-type Declarations </td><td width="20%" align="center"><a accesskey="u" href="ataspectj.html">Up</a></td><td width="40%" align="right"> aspectOf() and hasAspect() methods</td></tr></table></div></body></html> |