<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Simon Brown - annotations tag</title>
  <link>http://www.simongbrown.com/blog/tags/annotations/</link>
  <description>Coding the architecture</description>
  <language>en</language>
  <copyright>Simon Brown</copyright>
  <lastBuildDate>Tue, 06 May 2008 13:33:00 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>Java annotations in a Web 2.0 world</title>
    <link>http://www.simongbrown.com/blog/2006/09/05/java_annotations_in_a_web_2_0_world.html</link>
    
      
        <description>
          &lt;p&gt;
Question : What do you get if you cross Java 5 annotations with Web 2.0?
&lt;/p&gt;

&lt;p&gt;
Answer : Something like this - a &lt;a href=&#034;http://en.wikipedia.org/wiki/Tag_cloud&#034;&gt;tag cloud&lt;/a&gt; based upon annotations and their use within a codebase.
&lt;/p&gt;

&lt;div align=&#034;center&#034;&gt;&lt;img src=&#034;http://www.simongbrown.com/blog/images/2006/tagcloud-stripes-basic.png&#034; alt=&#034;Annotation tag cloud for Stripes 1.4&#034; class=&#034;photo&#034; /&gt;&lt;/div&gt;

&lt;p&gt;
I didn&#039;t talk about annotations in my &lt;a href=&#034;http://www.simongbrown.com/blog/2006/09/04/thoughts_on_java_5_features.html&#034;&gt;previous blog entry&lt;/a&gt; and the reason for this is that I&#039;m not really a heavy user of them. A few &lt;code&gt;@Override&lt;/code&gt; annotations here and there (courtesy of Eclipse), a couple of Spring &lt;code&gt;@Transactional&lt;/code&gt; annotations and that&#039;s pretty much it. I&#039;ve often thought about using annotations more (see &lt;a href=&#034;http://www.simongbrown.com/blog/2005/10/05/requirements_coverage.html&#034;&gt;Requirements coverage&lt;/a&gt;, for example) but the spark and necessity have never been there. However, now that I&#039;m doing more Java 5 development and starting to use annotations, I&#039;ve started thinking about other ways in which they could be used.
&lt;/p&gt;

&lt;p&gt;
For me, the interest comes in trying to enrich a codebase with metadata that describes something more about the code than you can get from comments or the code itself. Or failing that, metadata that provides an easier way to find what you&#039;re looking for. For example, wouldn&#039;t it be great to see which code was considered to be &#034;framework code&#034;? What about making it easy to find those few really good examples of Oracle BLOB handling rather than saying, &#034;they&#039;re somewhere in the DAO layer&#034;? What about tagging up classes and methods with a keyword summarising their functional purpose. You&#039;ve probably come across the &lt;a href=&#034;http://javaalmanac.com/&#034;&gt;Java Almanac&lt;/a&gt; during your travels - it&#039;s basically a whole bunch of useful code snippets that demonstrate how to use the various Java APIs. Now, imagine something like this across your own code. You probably have countless examples of APIs, techniques for doing things, implementations of patterns, gotchas and so on. Imagine attaching metadata to your source code by tagging it up, del.icio.us style.
&lt;/p&gt;

&lt;pre class=&#034;codeSample&#034;&gt;@Keywords({&#034;oracleblobhandling&#034;, &#034;frameworkcode&#034;})
@Keywords({&#034;interestratecalculation&#034;, &#034;businesslogic&#034;})
@Pattern(&#034;factory&#034;)
&lt;/pre&gt;

&lt;p&gt;
Now, imagine for a moment that you&#039;ve tagged up your source code and put effort into enriching the metadata associated with it. Something like the tag cloud shown above gives you an immediate view on which annotations you&#039;ve used, how often they&#039;re used and so on. The screenshot above is a basic tag cloud that shows the annotations used within a codebase, the size of each showing the relative frequency with which each annotation is used. Click on an annotation and you can get more information about exactly where the annotation is used.
&lt;/p&gt;

&lt;div align=&#034;center&#034;&gt;&lt;img src=&#034;http://www.simongbrown.com/blog/images/2006/tagcloud-stripes-detail.png&#034; alt=&#034;Annotation usages for Stripes 1.4&#034; class=&#034;photo&#034; /&gt;&lt;/div&gt;

&lt;p&gt;
Just out of curiosity, I built a tag cloud from the Java 5 source code. Only 440 uses of &lt;code&gt;@Deprecated&lt;/code&gt;. ;-)
&lt;/p&gt;

&lt;div align=&#034;center&#034;&gt;&lt;img src=&#034;http://www.simongbrown.com/blog/images/2006/tagcloud-java5-basic.png&#034; alt=&#034;Annotation tag cloud for Java 5&#034;  class=&#034;photo&#034; /&gt;&lt;/div&gt;

&lt;p&gt;
Taking this concept further, you can get access to the actual values associated with annotation attributes, so it would be easy to build a tag cloud based upon only the values associated with an &lt;code&gt;@Keywords&lt;/code&gt; annotation, for example. Effectively, you can filter and group on whatever level of annotation information you want to because it&#039;s all available via a set of APIs.
&lt;/p&gt;

&lt;p&gt;
I&#039;ve only just started playing with this so it&#039;ll be interesting to see how it pans out. Having attempted to generate tag clouds from a number of projects, I&#039;ll say the following. (1) Not many projects are using annotations (hence the small tag clouds!) and (2) the annotation processing APIs are a little verbose and sometimes unstable.
&lt;/p&gt;

&lt;p&gt;
I&#039;ll save the technical details for another day, but essentially I&#039;ve taken the tag cloud code out of &lt;a href=&#034;http://pebble.sf.net&#034;&gt;Pebble&lt;/a&gt; and dropped it into an &lt;a href=&#034;http://java.sun.com/j2se/1.5.0/docs/guide/apt/GettingStarted.html&#034;&gt;Annotation Processor&lt;/a&gt;, which gets executed through the Annotation Processing Tool (&lt;code&gt;apt&lt;/code&gt;), via the &lt;code&gt;apt&lt;/code&gt; Ant task that&#039;s included with Ant 1.7 beta 1.
&lt;/p&gt;

&lt;p&gt;
What do you think? Would you find this a useful addition to your development environment?
&lt;/p&gt;
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <comments>http://www.simongbrown.com/blog/2006/09/05/java_annotations_in_a_web_2_0_world.html#comments</comments>
    <guid isPermaLink="true">http://www.simongbrown.com/blog/2006/09/05/java_annotations_in_a_web_2_0_world.html</guid>
    <pubDate>Tue, 05 Sep 2006 20:29:00 GMT</pubDate>
  </item>
  
  <item>
    <title>Requirements coverage</title>
    <link>http://www.simongbrown.com/blog/2005/10/05/requirements_coverage.html</link>
    
      
        <description>
          &lt;p&gt;
Via &lt;a href=&#034;http://www.theserverside.com/news/thread.tss?thread_id=36946&#034;&gt;TheServerSide.com&lt;/a&gt;, I just read an article called &lt;a href=&#034;http://www.technobuff.net/webapp/product/showTutorial.do?name=jrequire&amp;tssar&#034;&gt;Requirement Coverage - Another dimension to Unit Testing&lt;/a&gt;. Essentially, it talks about a way to map requirements onto your unit tests and then use those unit tests to help you determine that you actually have coverage of the requirements. This is done through a tool called &lt;a href=&#034;http://www.technobuff.net/webapp/product/showProduct.do?name=jrequire&amp;jrequire_wp_res1&#034;&gt;JRequire&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Now I&#039;ve not used the tool, but I have been thinking about something similar for a little while. Well, kind of. I mean, the thought of mapping my requirements to my unit tests (even if they are really acceptance tests) doesn&#039;t enthrall me. On a large project in the past, we had a fairly large spreadsheet that mapped flows from use cases onto high level operations on service interfaces. I must admit that I left the project before any real development started so I don&#039;t know if this approach was eventually taken down to the code level. If it was, I don&#039;t even want to think about how complex this would have become.
&lt;/p&gt;

&lt;p&gt;
Anyway, I think that there&#039;s a simpler way to do this. If you take most [ requirements | use cases | stories ], you can typically map these back to a single entry point in the application. I&#039;m thinking of things like an action in a web MVC architecture, a listener in a desktop application or even an operation on a service. Assuming a Java implementation, what if you were to use an annotation to highlight the fact that these points of entry represent a requirement or a particular flow through a use case? Depending on how your requirements are coded, you could also annotate methods that implement exceptional flows if desired.
&lt;/p&gt;

&lt;p&gt;
How about something like...
&lt;/p&gt;

&lt;pre class=&#034;codeSample&#034;&gt;@Requirement(id=1,name=&#034;Get account balance&#034;)
public String execute(HttpServletRequest request,
  HttpServletResponse response) {
  ...
}&lt;/pre&gt;

&lt;p&gt;
I need to think about this some more but there are some obvious benefits.
&lt;ol&gt;
&lt;li&gt;Searching for the code that implements a certain requirement is easy because you can just search for the annotation.&lt;/li&gt;
&lt;li&gt;The annotations could be used at runtime to produce stats about how frequently features implemented from requirements are actually used, perhaps by reflecting on the annotations or by code injection.&lt;/li&gt;
&lt;li&gt;The above technique could also be used to get coverage information on requirements during acceptance test runs, ensuring that your acceptance tests do test all requirements.&lt;/li&gt;
&lt;/ol&gt;
I think there&#039;s something here and the lack of traceability between requirements and code is certainly a gap in most projects. Any thoughts? How do you map requirements to code?
&lt;/p&gt;
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <comments>http://www.simongbrown.com/blog/2005/10/05/requirements_coverage.html#comments</comments>
    <guid isPermaLink="true">http://www.simongbrown.com/blog/2005/10/05/requirements_coverage.html</guid>
    <pubDate>Wed, 05 Oct 2005 14:17:15 GMT</pubDate>
  </item>
  
  </channel>
</rss>
