<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Dean Wampler's Mind: Category Java and AspectJ</title>
    <link>http://blog.aspectprogramming.com/articles/category/java-and-aspectj</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Ruminations and Ruinations on Software</description>
    <item>
      <title>ANN: Aquarium V0.4.0 Released with Initial Support for Java Aspects in Aquarium</title>
      <description>&lt;p&gt;The new V0.4.0 release of Aquarium adds support for JRuby. Not only do the regular &amp;ldquo;pure Ruby&amp;rdquo; Aquarium specs run reliably under JRuby (V1.1RC2), but you can now write aspects for Java types with Aquarium!&lt;/p&gt;


	&lt;p&gt;There are some limitations and issues. For details, see my &lt;a href="http://blog.objectmentor.com/articles/2008/02/25/writing-java-aspects-with-jruby-and-aquarium"&gt;blog&lt;/a&gt; at &lt;a href="http://blog.objectmentor.com"&gt;Object Mentor&lt;/a&gt; and the &lt;a href="http://aquarium.rubyforge.org/jruby.html"&gt;JRuby&lt;/a&gt; page at the Aquarium website.&lt;/p&gt;</description>
      <pubDate>Tue, 26 Feb 2008 12:12:25 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:24c72686-dc4f-4346-8342-f8b8a2310752</guid>
      <author>Dean Wampler</author>
      <link>http://blog.aspectprogramming.com/articles/2008/02/26/ann-aquarium-v0-4-0-released-with-initial-support-for-java-aspects-in-aquarium</link>
      <category>AOP</category>
      <category>Java and AspectJ</category>
      <category>Aquarium</category>
      <trackback:ping>http://blog.aspectprogramming.com/articles/trackback/51</trackback:ping>
    </item>
    <item>
      <title>CJUG Downtown 12/18/07: Aspect-Oriented Programming and Software Design</title>
      <description>&lt;p&gt;I&amp;#8217;m reprising my &lt;a href="http://www.cjug.org/Wiki.jsp?page=2007.09.06.west"&gt;&lt;span class="caps"&gt;CJUG&lt;/span&gt; West talk&lt;/a&gt; on &lt;a href="http://www.cjug.org/Wiki.jsp?page=2007.12.18.downtown"&gt;Aspect-Oriented Programming and Software Design in Java and AspectJ&lt;/a&gt; for the downtown Chicago group on December 18th.&lt;/p&gt;


	&lt;p&gt;I will briefly describe the problems that &lt;span class="caps"&gt;AOP&lt;/span&gt; addresses and how the principles of object-oriented design influence &lt;span class="caps"&gt;AOP&lt;/span&gt; and vice versa. If you&amp;#8217;re in the area, I hope to see you &lt;a href="http://www.cjug.org/Wiki.jsp?page=2007.12.18.downtown"&gt;there&lt;/a&gt;.&lt;/p&gt;</description>
      <pubDate>Sat, 08 Dec 2007 12:02:14 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:8cef9449-5110-4429-84c7-5615b6fcc3ba</guid>
      <author>Dean Wampler</author>
      <link>http://blog.aspectprogramming.com/articles/2007/12/08/cjug-downtown-12-18-07-aspect-oriented-programming-and-software-design</link>
      <category>AOP</category>
      <category>Java and AspectJ</category>
      <trackback:ping>http://blog.aspectprogramming.com/articles/trackback/49</trackback:ping>
    </item>
    <item>
      <title>CJUG West 9/6/07: Aspect-Oriented Programming and Software Design</title>
      <description>&lt;p&gt;I&amp;#8217;m giving a talk at the &lt;a href="http://www.cjug.org/Wiki.jsp?page=Welcome"&gt;Chicago Java User&amp;#8217;s Group West&lt;/a&gt; meeting this Thursday at 6:30 PM. The topic is &lt;a href="http://www.cjug.org/Wiki.jsp?page=2007.09.06.west"&gt;Aspect-Oriented Programming and Software Design in Java and AspectJ&lt;/a&gt;. I&amp;#8217;ll briefly describe the problems that &lt;span class="caps"&gt;AOP&lt;/span&gt; addresses and how the principles of object-oriented design influence &lt;span class="caps"&gt;AOP&lt;/span&gt; and &lt;i&gt;vice versa&lt;/i&gt;. If you&amp;#8217;re in the area, I hope to see you &lt;a href="http://www.cjug.org/Wiki.jsp?page=2007.09.06.west"&gt;there&lt;/a&gt;.&lt;/p&gt;</description>
      <pubDate>Tue, 04 Sep 2007 17:55:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:2e02a2cf-149f-4993-a078-43c8e71cdedf</guid>
      <author>Dean Wampler</author>
      <link>http://blog.aspectprogramming.com/articles/2007/09/04/cjug-west-9-6-07-aspect-oriented-programming-and-software-design</link>
      <category>AOP</category>
      <category>Java and AspectJ</category>
      <trackback:ping>http://blog.aspectprogramming.com/articles/trackback/37</trackback:ping>
    </item>
    <item>
      <title>ANN: OOPSLA Tutorial on &amp;quot;Principles of Aspect-Oriented Design in Java and AspectJ&amp;quot;</title>
      <description>&lt;p&gt;I&amp;#8217;m doing a tutorial on aspect-oriented design principles with examples in Java and AspectJ at &lt;span class="caps"&gt;OOPSLA&lt;/span&gt; this year. You can find a description &lt;a href="http://www.oopsla.org/oopsla2007/index.php?page=sub/&amp;#38;id=90"&gt;here&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 04 Sep 2007 10:51:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:efe53cc5-2bc3-4af6-89ce-1c9ce05cc498</guid>
      <author>Dean Wampler</author>
      <link>http://blog.aspectprogramming.com/articles/2007/09/04/ann-oopsla-tutorial-on-principles-of-aspect-oriented-design-in-java-and-aspectj</link>
      <category>AOP</category>
      <category>Java and AspectJ</category>
      <category>OOPSLA</category>
      <category>AOP</category>
      <category>AOD</category>
      <trackback:ping>http://blog.aspectprogramming.com/articles/trackback/36</trackback:ping>
    </item>
    <item>
      <title>AspectJ: Testing that Classes Implement All Required Interfaces</title>
      <description>There was a recent &lt;a href="http://www.nabble.com/Frustrated-Newbie-tf3287156.html"&gt;post&lt;/a&gt; to the &lt;a href="http://www.nabble.com/AspectJ---users-f2219.html"&gt;aspectj-users&lt;/a&gt; group from &amp;#8220;Frustrated Newbie&amp;#8221; who was trying to write a &lt;code&gt;declare error&lt;/code&gt; that would enforce the requirement that all classes implementing one interface, let&amp;#8217;s call it &lt;code&gt;Foo&lt;/code&gt;, also implement a second interface &lt;code&gt;Bar&lt;/code&gt;.  He tried something like the following:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_java "&gt;declare error: within(*..Foo+) &amp;amp;&amp;amp; !within(*..*Bar+):&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
This doesn&amp;#8217;t work, mostly because interfaces don&amp;#8217;t have much real code associated with them, so there aren&amp;#8217;t enough join points to match. 

	&lt;p&gt;As an experiment (which he tried&amp;#8230;), if you drop the second expression, leaving just &lt;code&gt;within(*..Foo+)&lt;/code&gt; you get an error just on the &lt;code&gt;Foo&lt;/code&gt; interface, not on any implementing classes or extending interfaces.&lt;/p&gt;


Through trial and error, I figured out that if you put these interfaces in dedicated packages, say &lt;code&gt;..foo&lt;/code&gt; and &lt;code&gt;..bar&lt;/code&gt;, respectively, the following &lt;i&gt;does&lt;/i&gt; work:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_java "&gt;declare error: within(*..foo.*+) &amp;amp;&amp;amp; !within(*..foo.*) &amp;amp;&amp;amp; !within(*..bar.*+):&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
The second expression &lt;code&gt; !within(*..foo.*)&lt;/code&gt; prevents errors on the interfaces in package &lt;code&gt;foo&lt;/code&gt; itself.

	&lt;p&gt;This isn&amp;#8217;t especially obvious and you may find it inconvenient to package your interfaces like this, but it does work. Actually, there&amp;#8217;s a good case to be made for putting interfaces in separate packages like this, based on the &lt;i&gt;Stable Abstractions Principle&lt;/i&gt; (&lt;a href="http://www.objectmentor.com/resources/articles/stability.pdf"&gt;&lt;span class="caps"&gt;PDF&lt;/span&gt;&lt;/a&gt;, see also &lt;a href="http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod"&gt;here&lt;/a&gt;).&lt;/p&gt;</description>
      <pubDate>Sun, 25 Feb 2007 09:31:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:388e9db8-2076-4a2e-b0d0-052bb76155d7</guid>
      <author>Dean Wampler</author>
      <link>http://blog.aspectprogramming.com/articles/2007/02/25/aspectj-testing-that-classes-implement-all-required-interfaces</link>
      <category>AOP</category>
      <category>Java and AspectJ</category>
      <trackback:ping>http://blog.aspectprogramming.com/articles/trackback/24</trackback:ping>
    </item>
    <item>
      <title>Groovy, JRuby, vs. Jexl Performance, Using Java 5 and Java 6</title>
      <description>&lt;p&gt;I just &lt;a href="http://blog.aspectprogramming.com/articles/2006/12/31/contract4j5-v0-7-0-is-now-available"&gt;released v0.7.0&lt;/a&gt; of Contract4J5, which now supports Groovy and JRuby as alternative scripting languages, in addition to Jexl, the original language used. Along the way, I collected some performance numbers for the three alternatives.&lt;/p&gt;
&lt;p&gt;The following discussion is adapted from the &lt;a href="http://www.contract4j.org/contract4j/c4j5"&gt;&lt;span class="caps"&gt;README&lt;/span&gt;&lt;/a&gt; for the v0.7.0 release.&lt;/p&gt;
&lt;p&gt;I ran the JUnit test suite with all three languages. The numbers below show the 
performance when using binary weaving and load-time
weaving (LTW) and also the performance using the JVMs in &lt;span class="caps"&gt;JDK 5&lt;/span&gt; and &lt;span class="caps"&gt;JDK 6&lt;/span&gt;.&lt;/p&gt;
&lt;br/&gt;
&lt;table border="1"&gt;
    &lt;tr&gt;&lt;th colspan="6"&gt;&lt;span class="caps"&gt;JDK 5&lt;/span&gt; (sec.)&lt;/th&gt;&lt;th colspan="6"&gt;&lt;span class="caps"&gt;JDK 6&lt;/span&gt; (sec.)&lt;/th&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;th colspan="2"&gt;Jexl&lt;/th&gt;&lt;th colspan="2"&gt;Goovy&lt;/th&gt;&lt;th colspan="2"&gt;JRuby&lt;/th&gt;&lt;th colspan="2"&gt;Jexl&lt;/th&gt;&lt;th colspan="2"&gt;Goovy&lt;/th&gt;&lt;th colspan="2"&gt;JRuby&lt;/th&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;th&gt;Binary&lt;/th&gt;&lt;th&gt;&lt;span class="caps"&gt;LTW&lt;/span&gt;&lt;/th&gt;&lt;th&gt;Binary&lt;/th&gt;&lt;th&gt;&lt;span class="caps"&gt;LTW&lt;/span&gt;&lt;/th&gt;&lt;th&gt;Binary&lt;/th&gt;&lt;th&gt;&lt;span class="caps"&gt;LTW&lt;/span&gt;&lt;/th&gt;&lt;th&gt;Binary&lt;/th&gt;&lt;th&gt;&lt;span class="caps"&gt;LTW&lt;/span&gt;&lt;/th&gt;&lt;th&gt;Binary&lt;/th&gt;&lt;th&gt;&lt;span class="caps"&gt;LTW&lt;/span&gt;&lt;/th&gt;&lt;th&gt;Binary&lt;/th&gt;&lt;th&gt;&lt;span class="caps"&gt;LTW&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;21.7&lt;/td&gt;&lt;td&gt;98.6&lt;/td&gt;&lt;td&gt;54.9&lt;/td&gt;&lt;td&gt;324.4&lt;/td&gt;&lt;td&gt;79.6&lt;/td&gt;&lt;td&gt;189.4&lt;/td&gt;&lt;td&gt;17.7&lt;/td&gt;&lt;td&gt;62.9&lt;/td&gt;&lt;td&gt;44.8&lt;/td&gt;&lt;td&gt;133.5&lt;/td&gt;&lt;td&gt;63.2&lt;/td&gt;&lt;td&gt;108.4&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;br/&gt;
&lt;p&gt;These times are approximate &amp;#8220;user times&amp;#8221;, averaged over a few runs, measured on a ThinkPad &lt;span class="caps"&gt;T42&lt;/span&gt; running Ubuntu Linux.
There are slightly different build activities and I/O overhead involved in the &lt;span class="caps"&gt;LTW&lt;/span&gt; numbers,
adding a few percentage points to the numbers. The tests do some different manipulations depending on which interpreter is used. Hence, the results are rough, at best. Most likely, the numbers reflect the relative amounts of overhead to load the interpreters and to set up the &amp;#8220;environments&amp;#8221; for evaluating the scripts, which happens frequently in the test suite. Since the scripts are always very small, evaluation is probably not a large percentage of the execution time. (However, this is speculation!) Your mileage may vary&amp;#8230;&lt;/p&gt;
&lt;p&gt;Note that the &lt;span class="caps"&gt;JDK 6&lt;/span&gt; performance is significantly better. The code was compiled
with the &lt;span class="caps"&gt;JDK 5&lt;/span&gt; &lt;code&gt;javac&lt;/code&gt; and executed using the &lt;span class="caps"&gt;JDK 6 JVM&lt;/span&gt;. Ironically, the performance was slightly slower when compiled with the &lt;span class="caps"&gt;JDK 6&lt;/span&gt; &lt;code&gt;javac&lt;/code&gt;. (This is not reflected in the numbers) &lt;/p&gt;
&lt;p&gt;The Jexl test
runs are roughly twice as fast as the Groovy and JRuby runs, probably because Jexl is a 
more &amp;#8220;minimalist&amp;#8221; environment, incurring less startup and execution overhead. &lt;/p&gt;
&lt;p&gt;While not shown, I observed that the memory 
requirements for Groovy and JRuby are also higher, as you would expect. I didn&amp;#8217;t actually measure memory usage, but I observed this because it was necessary to increase the maximum
heap size for the &lt;span class="caps"&gt;LTW&lt;/span&gt; JUnit run when using Groovy or JRuby. Also, when using JRuby, I had to increase the heap size for the binary-weaving JUnit runs in Eclipse.&lt;/p&gt;
&lt;p&gt;The &lt;span class="caps"&gt;LTW&lt;/span&gt; test runs take significantly longer, but the results are somewhat hard to interpret. Under &lt;span class="caps"&gt;JDK 5&lt;/span&gt;, the Jexl and Groovy runs are five to six times longer, while the JRuby runs are only about 2.5 times longer. Under &lt;span class="caps"&gt;JDK 6&lt;/span&gt;, the Jexl and Groovy runs are a little more than three times longer, while the JRuby run is under twice as long. It is not clear why JRuby &lt;span class="caps"&gt;LTW&lt;/span&gt; configurations perform so much better under both JDKs. However, it is clear that, for all the interpreters, the startup byte-code instrumentation required for &lt;span class="caps"&gt;LTW&lt;/span&gt; is much better under &lt;span class="caps"&gt;JDK 6&lt;/span&gt;.&lt;/p&gt; 
&lt;p&gt;In general, the longer &lt;span class="caps"&gt;LTW&lt;/span&gt; times occur because a weaving step happens
at the beginning of each TestCase, as the class is loaded. The &lt;span class="caps"&gt;JDK 6&lt;/span&gt; speed-up is a
good argument for running this VM, at least for your tests!&lt;/p&gt;
&lt;p&gt;&lt;span class="caps"&gt;LTW&lt;/span&gt; is the most convenient
way to adopt Contract4J5 (true for other aspects, as well), but if the startup time is too
long for your needs, then binary weaving of compiled code provides better performance with
only a modest change in your build process.&lt;/p&gt;</description>
      <pubDate>Sun, 31 Dec 2006 18:38:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:c38fab8d-0ff1-44f5-8d7f-286d6a74fd25</guid>
      <author>Dean Wampler</author>
      <link>http://blog.aspectprogramming.com/articles/2006/12/31/groovy-jruby-vs-jexl-performance-using-java-5-and-java-6</link>
      <category>AOP</category>
      <category>Java and AspectJ</category>
      <category>Contract4J</category>
      <trackback:ping>http://blog.aspectprogramming.com/articles/trackback/23</trackback:ping>
    </item>
    <item>
      <title>Contract4J5 v0.7.0 Is Now Available</title>
      <description>&lt;p&gt;I just released v0.7.0 of &lt;a href="http://www.contract4j.org"&gt;Contract4J5&lt;/a&gt;. This release adds support for using Groovy or JRuby instead of Jexl as the scripting engine for the test scripts embedded in annotations. In fact, Groovy is now the default.&lt;/p&gt;
&lt;p&gt;The advantage of Groovy or JRuby is that they provide a richer environment for more sophisticated testing. They are also better suited for planned, long-term enhancements of Contract4J5 to support user-configurable annotations and behaviors, which will take the tool beyond &lt;i&gt;Design by Contract&lt;/i&gt; support.&lt;/p&gt;
&lt;p&gt;The only major disadvantage over Jexl is lower performance. I&amp;#8217;ll blog about those results next. You can also find details in the &lt;a href="http://www.contract4j.org/contract4j/c4j5"&gt;&lt;span class="caps"&gt;README&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I was pleased to find that all but a few of the existing Jexl-based unit tests worked without modification for Groovy. With a few hacks, I got them to work for JRuby as well. The differences for Groovy include slight differences in how Goovy &lt;i&gt;vs.&lt;/i&gt; Jexl handle protected access (&lt;code&gt;private, protected&lt;/code&gt;, &lt;i&gt;etc.&lt;/i&gt;). Also, Groovy does not force you to provide a public accessor to evaluate tests on member fields, which Jexl required.&lt;/p&gt;
&lt;p&gt;For JRuby, I found that almost all Ruby &lt;i&gt;vs.&lt;/i&gt; Java differences could be handled if I did a few simple replacements of the most common Java idioms in scripts with the corresponding Ruby idioms:
&lt;ul&gt;
&lt;li&gt;Replace &lt;code&gt;equals(...)&lt;/code&gt; with &lt;code&gt;eql?(...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Replace &lt;code&gt;compareTo(...)&lt;/code&gt; with &lt;code&gt;&amp;lt;=&amp;gt;(...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Replace &lt;code&gt;null&lt;/code&gt; with &lt;code&gt;nil&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That is, Contract4J5, when using JRuby, will make these substitutions in your test expressions so they work, most of the time, even though they are written in Java syntax. This tends to work because the test expressions tend to be relatively simple and they often consist of comparisons to &lt;code&gt;null&lt;/code&gt; or calls to &lt;code&gt;String&lt;/code&gt; comparison methods.&lt;/p&gt;</description>
      <pubDate>Sun, 31 Dec 2006 18:19:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:4edaca14-a271-45d7-9cc3-16f3d598d3be</guid>
      <author>Dean Wampler</author>
      <link>http://blog.aspectprogramming.com/articles/2006/12/31/contract4j5-v0-7-0-is-now-available</link>
      <category>AOP</category>
      <category>Java and AspectJ</category>
      <category>Contract4J</category>
      <trackback:ping>http://blog.aspectprogramming.com/articles/trackback/22</trackback:ping>
    </item>
    <item>
      <title>Contract4J5 v0.6.0 Is Now Available</title>
      <description>&lt;p&gt;After a longer-than-expected effort, I&amp;#8217;m pleased to announce the v0.6.0 release of Contract4J5.&lt;/p&gt;


	&lt;p&gt;The &lt;span class="caps"&gt;API&lt;/span&gt; for writing contract tests has not changed, but the internals have been restructured considerably to improve the code quality and make it easier to configure Contract4J5 using property files and &lt;a href="http://www.springframework.org"&gt;Spring Framework&lt;/a&gt; Dependency Injection.&lt;/p&gt;


	&lt;p&gt;The release also provides examples of using Contract4J5 with binary weaving or load-time weaving. The latter is now the preferred way to introduce Contract4J5 into a &amp;#8220;pure-Java&amp;#8221; environment.&lt;/p&gt;


	&lt;p&gt;For more details, see the 
&lt;a href="http://contract4j.org/contract4j/c4j5#notes"&gt;Release Notes&lt;/a&gt; in the &lt;span class="caps"&gt;README&lt;/span&gt; or browse to &lt;a href="http://www.contract4j.org"&gt;http://www.contract4j.org&lt;/a&gt;.&lt;/p&gt;</description>
      <pubDate>Thu, 21 Sep 2006 21:07:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:5edc78e1-2e33-4780-90b6-77960ccb8bea</guid>
      <author>Dean Wampler</author>
      <link>http://blog.aspectprogramming.com/articles/2006/09/21/contract4j5-v0-6-0-is-now-available</link>
      <category>AOP</category>
      <category>Java and AspectJ</category>
      <category>Contract4J</category>
      <category>Contract4J</category>
      <category>AOP</category>
      <category>AspectJ</category>
      <trackback:ping>http://blog.aspectprogramming.com/articles/trackback/20</trackback:ping>
    </item>
    <item>
      <title>Aspect-Oriented Design: &amp;quot;Humane Pointcut Languages&amp;quot;</title>
      <description>&lt;p&gt;I started a discussion yesterday on the &amp;#8220;aspectj-users&amp;#8221; group about &lt;a href="http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg05970.html"&gt;humane pointcut languages&lt;/a&gt;. The notion of &amp;#8220;humane interfaces&amp;#8221; in programming has been discussed by &lt;a href="http://www.martinfowler.com/bliki/HumaneInterface.html"&gt;Martin Fowler&lt;/a&gt; and in the context of user interfaces and product design by &lt;a href="http://jef.raskincenter.org/humane_interface/summary_of_thi.html"&gt;Jef Raskin&lt;/a&gt;.&lt;/p&gt;


This conversation was a spin-off of another &lt;a href="http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg05960.html"&gt;thread&lt;/a&gt; where I made a mistake that I occasionally make. An AspectJ user wanted to apply some after advice after constructor calls in a class that has an annotation, &lt;em&gt;e.g.&lt;/em&gt;,
&lt;pre&gt;
  @MyAnnotation
  public class Foo {
    public Foo(...) {...}
    ...
  }
&lt;/pre&gt;

He needed help writing the pointcut and advice for this case. Without repeating the whole conversation here, at one point I remarked that
&lt;pre&gt;
  call( @MyAnnotation * *.new(..) )
&lt;/pre&gt;
matches constructors annotated with &lt;code&gt;@MyAnnotation&lt;/code&gt;, while
&lt;pre&gt;
  call( * (@MyAnnotation *).new(..) )
&lt;/pre&gt;
matches constructors in classes where the class has the annotation.

In fact, both are invalid expressions because the first &lt;code&gt;*&lt;/code&gt; is for the return type and there is no return type for constructors, so the first &lt;code&gt;*&lt;/code&gt; shouldn&amp;#8217;t be there.  Hence,  the correct statement is that
&lt;pre&gt;
  call( @MyAnnotation *.new(..) )
&lt;/pre&gt;
matches constructors annotated with &lt;code&gt;@MyAnnotation&lt;/code&gt;, while
&lt;pre&gt;
  call( (@MyAnnotation *).new(..) )
&lt;/pre&gt;
matches constructors in classes where the class has the annotation.
&lt;br/&gt;

	&lt;p&gt;This is the sort of mistake I make fairly often and I&amp;#8217;m sure beginners really struggle with the pointcut syntax, although it&amp;#8217;s generally great for experts because it is both succinct and powerful. However, sometimes a more &amp;#8220;human-readable&amp;#8221;, that is &amp;#8220;humane&amp;#8221;, syntax can be a real benefit.&lt;/p&gt;


	&lt;p&gt;In fact, I&amp;#8217;ve been thinking about expressive pointcut languages quite a bit recently, not so much in this context, but more in the context of higher-level &lt;span class="caps"&gt;AOP&lt;/span&gt; abstractions. As I said in the discussion thread, it bothers me that we discuss high-level concerns, say for example security, then turn around and write &lt;acronym title="Pointcut Definitions"&gt;PCD&lt;/acronym&gt;s using very low-level primitives that tend to reference specific classes, methods, &lt;em&gt;etc.&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;Of course, I&amp;#8217;m not the only person who thinks this way and the recent work on AO interface-based programming is a huge step towards making it possible to express aspects with appropriate levels of abstraction.&lt;/p&gt;


	&lt;p&gt;I would like to comment on this issue more in future blogs, but for now, let&amp;#8217;s return to the original problem and look at some things we might do to make &lt;acronym title="Pointcut Definitions"&gt;PCD&lt;/acronym&gt;s more humane.&lt;/p&gt;


	&lt;p&gt;The first thing I suggested in the thread is the addition of special keywords that could be substituted for some of the wild-cards:&lt;/p&gt;


	&lt;table style="border:1px solid black; background:#eee;"&gt;
		&lt;tr&gt;
			&lt;th style="text-align:left;"&gt;Keyword &lt;/th&gt;
			&lt;th&gt;Maps To:&amp;nbsp; &lt;/th&gt;
			&lt;th style="text-align:left;"&gt;Context &lt;/th&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt; &lt;code&gt;$any_return&lt;/code&gt; &lt;/td&gt;
			&lt;td style="vertical-align:middle;text-align:center;"&gt;&lt;code&gt;*&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; Used for any return type &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt; &lt;code&gt;$any_arg&lt;/code&gt; &lt;/td&gt;
			&lt;td style="vertical-align:middle;text-align:center;"&gt;&lt;code&gt;*&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; Used for any &lt;em&gt;one&lt;/em&gt; method argument &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt; &lt;code&gt;$any_arglist&lt;/code&gt; &lt;/td&gt;
			&lt;td style="vertical-align:middle;text-align:center;"&gt;&lt;code&gt;..&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; Used for zero-many method arguments &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt; &lt;code&gt;$any_type&lt;/code&gt; &lt;/td&gt;
			&lt;td style="vertical-align:middle;text-align:center;"&gt;&lt;code&gt;*&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; Used for any  type expression (class, interface, ...) &lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;




So, our previous &lt;acronym title="Pointcut Definition"&gt;PCD&lt;/acronym&gt; that matches calls to the constructors could be written
&lt;pre&gt;
    call( (@MyAnnotation $any_type).new($any_arglist) )
&lt;/pre&gt;

	&lt;p&gt;This is a little more readable, especially for new users, while experts will prefer the more terse form for its brevity.&lt;/p&gt;


	&lt;p&gt;As an aside, you could use a similar mechanism to support regular expression matching while minimizing the potential for confusion, as discussed &lt;a href="http://aspectprogramming.com/papers/The%20Challenges%20of%20Writing%20Reusable%20Aspects%20in%20AspectJ%20v3.pdf"&gt;here&lt;/a&gt;. Something like &lt;code&gt;$re(/(foo|bar)$/)&lt;/code&gt; to match names ending in &lt;code&gt;foo&lt;/code&gt; or &lt;code&gt;bar&lt;/code&gt;, for example.&lt;/p&gt;


Let&amp;#8217;s combine our new &lt;acronym title="Pointcut Definition"&gt;PCD&lt;/acronym&gt; with &lt;code&gt;after&lt;/code&gt; advice, to see a little more context. We want to &amp;#8220;bind&amp;#8221; the newly-created &lt;code&gt;Foo&lt;/code&gt; instance to a variable &lt;code&gt;foo&lt;/code&gt;. Handling newly-created objects is &lt;a href="http://www.eclipse.org/aspectj/doc/released/faq.html#q:adviseconstructors"&gt;tricky&lt;/a&gt;.
&lt;pre&gt;
    after() returning(Foo foo): 
      call( (@MyAnnotation $any_type).new($any_arglist) ) {
        ...
    }
&lt;/pre&gt;
Another approach, if we&amp;#8217;re using the &lt;code&gt;execution&lt;/code&gt; join point, is the following: 
&lt;pre&gt;
    after(Foo foo): 
      execution( (@MyAnnotation $any_type).new($any_arglist) ) &amp;#38;&amp;#38; this(foo) {
        ...
    }
&lt;/pre&gt;

However, the keywords are a small improvement. Let me suggest that a real &amp;#8220;humane&amp;#8221; &lt;span class="caps"&gt;PCD&lt;/span&gt; language should read more like English. Consider this rewriting of the same two expressions, using a made-up pointcut &lt;acronym title="Domain Specific Language"&gt;DSL&lt;/acronym&gt;:
&lt;pre&gt;
    after() returning(Foo foo): 
      call(constructors().takingAnyArgs().inClassesAnnotatedWith(@MyAnnotation)) {
        ...
    }
&lt;/pre&gt;
and
&lt;pre&gt;
    after(Foo foo): 
  execution(constructors().takingAnyArgs().inClassesAnnotatedWith(@MyAnnotation))
    &amp;#38;&amp;#38; bindNewlyConstructedObjectTo(foo) {
    ...
}
&lt;/pre&gt;

	&lt;p&gt;This syntax is inspired by the syntax of mocking frameworks like &lt;a href="http://www.jmock.org"&gt;JMock&lt;/a&gt; and equivalents in Ruby. Certainly my toy &lt;acronym title="Domain Specific Language"&gt;DSL&lt;/acronym&gt; could be improved; I made it up on the fly during the discussion thread yesterday.&lt;/p&gt;


	&lt;p&gt;However, because it reads like English, it is very self-documenting, making comprehension easier by AspectJ neophytes and even experienced AspectJ users who are new to the application. 
I think it&amp;#8217;s useful to remember that most code is &lt;em&gt;write once, read many&lt;/em&gt;. We may not like to type a lot, but a literate style pays dividends over time.&lt;/p&gt;


	&lt;p&gt;Note that the syntax of this &lt;acronym title="Domain Specific Language"&gt;DSL&lt;/acronym&gt; and the standard syntax express essentially the same pointcut language &amp;#8220;abstraction&amp;#8221; for AspectJ.&lt;/p&gt;


	&lt;p&gt;So, I think there is a place for a more &amp;#8220;humane&amp;#8221; form of the AspectJ pointcut &lt;acronym title="Domain Specific Language"&gt;DSL&lt;/acronym&gt;. Similarly, I think that we need &lt;acronym title="Domain Specific Languages"&gt;DSL&lt;/acronym&gt;s appropriate for higher-level &lt;span class="caps"&gt;AOP&lt;/span&gt; abstractions (&lt;em&gt;e.g.&lt;/em&gt;, at the design level) and ideally &lt;span class="caps"&gt;AOP&lt;/span&gt; &lt;acronym title="Domain Specific Languages"&gt;DSL&lt;/acronym&gt;s that are domain-specific for non-trivial domains.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Update 4/28/06:&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;Jonas Bon&amp;eacute;r wrote an interesting blog on &lt;a href="http://jonasboner.com/2006/04/24/domain-driven-pointcut-design/"&gt;Domain Driven Pointcut Design&lt;/a&gt; where he discusses good principles of pointcut design that minimize dependencies on fragile class details and instead rely on metadata annotations, &lt;em&gt;etc.&lt;/em&gt; He also makes an excellent argument that the &amp;#8220;language&amp;#8221; of those annotations should reflect the domain of the annotated class and not mix in other domains, like cross-cutting concerns.&lt;/p&gt;</description>
      <pubDate>Fri, 21 Apr 2006 11:25:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:c74cc194-7212-4b4c-b61f-7b8368cce687</guid>
      <author>Dean Wampler</author>
      <link>http://blog.aspectprogramming.com/articles/2006/04/21/aspect-oriented-design-humane-pointcut-languages</link>
      <category>AOP</category>
      <category>Java and AspectJ</category>
      <category>AOP</category>
      <category>AOSD</category>
      <category>AspectJ</category>
      <category>Design</category>
      <category>Humane</category>
      <trackback:ping>http://blog.aspectprogramming.com/articles/trackback/2</trackback:ping>
    </item>
    <item>
      <title>My Contract4J Article on developerWorks</title>
      <description>&lt;p&gt;This is my inaugural blog hosted on my own web sites. My previous blogs can be found &lt;a href="http://jroller.com/page/deanwampler"&gt;here&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;My article on &lt;a href="http://contract4j.org"&gt;Contract4J&lt;/a&gt; went live on Tuesday, April 11 at &lt;span class="caps"&gt;IBM&lt;/span&gt;&amp;#8217;s &lt;a href="http://www-128.ibm.com/developerworks/java/library/j-aopwork17.html"&gt;developerWorks&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;In the article, I introduce Design by Contract and describe how Contract4J supports DbC in Java, using AspectJ under the hood. I end the article with a discussion of the emerging trends in aspect-oriented design using interfaces. That is, how the familiar interface-based design we&amp;#8217;re used to in &lt;span class="caps"&gt;OOP&lt;/span&gt; is being extended to support aspects.&lt;/p&gt;


	&lt;p&gt;I intend to explore Aspect-Oriented Design in more detail in coming blogs. Please stay tuned!&lt;/p&gt;</description>
      <pubDate>Thu, 13 Apr 2006 13:34:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:9b3aabd1-3c77-4d2f-9f8c-27af98b37f24</guid>
      <author>Dean Wampler</author>
      <link>http://blog.aspectprogramming.com/articles/2006/04/13/my-contract4j-article-on-developerworks</link>
      <category>AOP</category>
      <category>Java and AspectJ</category>
      <category>Contract4J</category>
      <category>AOP</category>
      <category>developerWorks</category>
      <category>AspectJ</category>
      <trackback:ping>http://blog.aspectprogramming.com/articles/trackback/1</trackback:ping>
    </item>
  </channel>
</rss>
