<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>The Object Teams Blog</title>
	<atom:link href="http://blog.objectteams.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.objectteams.org</link>
	<description>Everthing Object Teams - adding team spirit to your objects.</description>
	<pubDate>Thu, 26 Jan 2012 14:32:23 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Help the JDT Compiler helping you! - 1: Resource Leaks</title>
		<link>http://blog.objectteams.org/2012/01/help-the-jdt-compiler-helping-you-1-resource-leaks/</link>
		<comments>http://blog.objectteams.org/2012/01/help-the-jdt-compiler-helping-you-1-resource-leaks/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 14:25:14 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[analysis]]></category>

		<category><![CDATA[bug]]></category>

		<category><![CDATA[JDT]]></category>

		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=131</guid>
		<description><![CDATA[During the Juno cycle a lot of work in the JDT has gone into more sophisticated static analysis, and some more is still in the pipe-line. I truly hope that once Juno is shipped this will help all JDT users to find more bugs immediately while still typing. However, early feedback regarding these features shows [...]]]></description>
			<content:encoded><![CDATA[<p>During the Juno cycle a lot of work in the JDT has gone into more sophisticated static analysis, and some more is still in the pipe-line. I truly hope that once Juno is shipped this will help all JDT users to find more bugs immediately while still typing. However, early feedback regarding these features shows that users are starting to expect miracles from the analysis <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>On the one hand seeing this is flattering, but on the other hand it makes me think we should perhaps explain what exactly the analysis can see and what is beyond its vision. If you take a few minutes learning about the concepts behind the analysis you&#8217;ll not only understand its limitations, but more importantly you will learn how to write code that&#8217;s better readable - in this case for reading by the compiler. Saying: with only slightly rephrasing your programs you can help the compiler to better understand what&#8217;s going on, to the effect that the compiler can answer with much more useful error and warning messages.</p>
<p>Since there&#8217;s a lot of analysis in this JDT compiler I will address just one topic per blog post. This post goes to improvements in the detection of resource leaks.</p>
<h2>Resource leaks - the basics</h2>
<p>Right when everybody believed that Eclipse Indigo RC 4 was ready for the great release, another <a href="http://dev.eclipse.org/mhonarc/lists/cross-project-issues-dev/msg06246.html">blocker bug</a> was detected: a simple resource leak basically prevented Eclipse from launching on a typical Linux box if more than 1000 bundles are installed. Coincidentally, at the same time the JDT team was finishing up work on the new try-with-resources statement introduced in Java 7. So <a href="http://blog.objectteams.org/2011/06/a-use-case-for-java-7/">I was thinking</a>: shouldn&#8217;t the compiler help users to migrate from notoriously brittle handling of resources to the new construct that was designed specifically to facilitate a safe style of working with resources?</p>
<h3>What&#8217;s a resource?</h3>
<p>So, how can the compiler know about resources? Following the try-with-resources concept, any instance of type <code>java.lang.AutoCloseable</code> is a resource. Simple, huh? In order to extend the analysis also to pre Java 7 code, we also consider <code>java.io.Closeable</code> (available since 1.5).</p>
<h3>Resource life cycle</h3>
<p>The expected life cycle of any resource is : <em>allocate&mdash;use&mdash;close</em>. Simple again. </p>
<p>From this we conclude the code pattern we have to look for: where does the code allocate a closeable and no call to close() is seen afterwards. Or perhaps a call is seen but not all execution paths will reach that call, etc.</p>
<h3>Basic warnings</h3>
<p>With <a href="http://download.eclipse.org/eclipse/downloads/drops/S-3.8M3-201110271800/eclipse-news-M3.html#JDT-resource-leaks">Juno M3</a> we released a <a href="http://blog.deepakazad.com/2011/10/detecting-resource-leaks-with-eclipse.html">first analysis</a> that could now tell you things like:</p>
<ul style="list-style:none;">
<li><img valign="middle" src="http://blog.objectteams.org/wp-uploads/2012/01/error_obj.gif"/> Resource leak: &#8220;input&#8221; is never closed
<li><img valign="middle" src="http://blog.objectteams.org/wp-uploads/2012/01/error_obj.gif"/> Resource leak: &#8220;input&#8221; is never closed at this location (<em>if a method exit happens before reaching close()</em>)
</ul>
<p>If the problem occurs only on some execution paths the warnings are softened (saying &#8220;potential leak&#8221; etc.).</p>
<p>Good, <strong>but</strong>&#8230;</p>
<h2>Signal to noise - part 1</h2>
<p>It turned out that the analysis was causing significant noise. How come? The concepts are so clear and all code that wouldn&#8217;t exhibit the simple <em>allocate&mdash;use&mdash;close</em> life cycle should indeed by revised, shouldn&#8217;t it?</p>
<p>In fact we found several patterns, where these warnings were indeed useless.</p>
<h3>Resource-less resources</h3>
<p>We learned that not every subtype of <code>Closeable</code> really represents a resource that needs leak prevention. How many times have you invoked <code>close()</code> on a <code>StringWriter</code>, e.g.? Just have a look at its implementation and you&#8217;ll see why this isn&#8217;t worth the effort. Are there more classes in this category?</p>
<p>Indeed we found a total of 7 classes in <code>java.io</code> that purely operate on Java objects without allocating any resources from the operating system:</p>
<ul>
<li><code>StringReader</code></li>
<li><code>StringWriter</code></li>
<li><code>ByteArrayInputStream</code></li>
<li><code>ByteArrayOutputStream</code></li>
<li><code>CharArrayReader</code></li>
<li><code>CharArrayWriter</code></li>
<li><code>StringBufferInputStream</code></li>
</ul>
<p>For none of these does it make sense to warn about missing <code>close()</code>.</p>
<p>To account for these classes we simply added a <strong>white list</strong>: if a class is in the list suppress any warnings/errors. This white list consists of exactly those 7 classes listed above. Sub-classes of these classes are not considered.</p>
<h3>Wrapper resources</h3>
<p>Another group of classes implementing <code>Closeable</code> showed up, that are not strictly resources themselves. Think of <code>BufferedInputStream</code>! Does it need to be closed?</p>
<p>Well? What&#8217;s your answer? The correct answer is: it depends. A few examples:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="otj" style="font-family:monospace;">	<span style="color: #7F0055; font-weight: bold;">void</span> wrappers<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">String</span> content<span style="color: #000000;">&#41;</span> <span style="color: #7F0055; font-weight: bold;">throws</span> <span style="color: #000000; font-weight: normal">IOException</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #000000; font-weight: normal">Reader</span> r1, r2, r3, r4<span style="color: #000000;">;</span>
		r1 <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">BufferedReader</span><span style="color: #000000;">&#40;</span><span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">FileReader</span><span style="color: #000000;">&#40;</span><span style="color: #2A00ff;">&quot;someFile&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		r2 <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">BufferedReader</span><span style="color: #000000;">&#40;</span><span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">StringReader</span><span style="color: #000000;">&#40;</span>content<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		r3 <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">FileReader</span><span style="color: #000000;">&#40;</span><span style="color: #2A00ff;">&quot;somefile&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		r4 <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">BufferedReader</span><span style="color: #000000;">&#40;</span>r3<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		r3.<span style="color: #000000;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>How many leaks? With same added smartness the compiler will signal only one resource leak: on <code>r1</code>. All others are safe: </p>
<ul>
<li><code>r2</code> is a wrapper for a resource-less closeable: no OS resources are ever allocated here.</li>
<li><code>r3</code> is explicitly closed</li>
<li><code>r4</code> is just a wrapper around <code>r3</code> and since that is properly closed, <code>r4</code> does not hold onto any OS resources at the end.</li>
<li>returning to <code>r1</code>, why is that a leak? It&#8217;s a wrapper, too, but now the underlying resource (a <code>FileReader</code>) is not directly closed so it&#8217;s the responsibility of the wrapper and can only be triggered by calling <code>close()</code> on the wrapper <code>r1</code>.</li>
</ul>
<p>Summarizing: wrappers don&#8217;t directly hold an OS resource, but delegate to a next closeable. Depending on the nature and state of the nested closeable the wrapper may or may not be responsible for closing. In arbitrary chains of wrappers with a relevant resource at the bottom, closing any closeable in the chain (including the bottom) will suffice to release the single resource. If a wrapper chain is not properly closed the problem will be flagged against the outer-most wrapper, since calling <code>close()</code> at the wrapper will be delegated along all elements of the chain, which is the cleanest way of closing.</p>
<p>Also for wrappers the question arises: how does the compiler know? Again we set up a <strong>white list</strong> with all wrapper classes we found in the JRE: 20 classes in <code>java.io</code>, 12 in <code>java.util.zip</code> and 5 in other packages (the full lists are in <a href="http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/tree/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java">TypeConstants.java</a>, search for &#8220;_CLOSEABLES&#8221;).</p>
<h2>Status and outlook</h2>
<p>Yes, <a href="http://inhabitat.com/wp-content/blogs.dir/1/files/2012/01/costa-concordia-fuel-spill-1-537x356.jpg">a leak can be a stop-ship problem</a>.</p>
<p>Starting with Juno M3 we have basic analysis of resource leaks; starting with Juno M5 the analysis uses the two white lists mentioned above: resource-less closeables and resource wrappers. In real code this significantly reduces the number of false positives, which means: for the remaining warnings the signal-to-noise ratio is significantly better.</p>
<p>M5 will actually bring more improvements in this analysis, but that will be subject of a next post.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2012/01/help-the-jdt-compiler-helping-you-1-resource-leaks/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A little statistics of the day</title>
		<link>http://blog.objectteams.org/2012/01/a-little-statistics-of-the-day/</link>
		<comments>http://blog.objectteams.org/2012/01/a-little-statistics-of-the-day/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 18:27:14 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[bug]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=129</guid>
		<description><![CDATA[My latest query in Eclipse&#8217;s bugzilla answered 189 bugs.
Out of these a certain TLA was mentioned just in the bug summaries 54 times.
Additionally, the long form of the same word occurred 5 times.
Those who have followed my previous posts, know which three letters I&#8217;m referring to. Looks like they&#8217;re even more relevant in some Eclipse [...]]]></description>
			<content:encoded><![CDATA[<p>My latest query in Eclipse&#8217;s bugzilla answered <strong>189 bugs</strong>.</p>
<p>Out of these a certain TLA was mentioned just in the bug summaries <strong>54 times</strong>.<br />
Additionally, the long form of the same word occurred <strong>5 times</strong>.</p>
<p>Those who have followed my previous posts, know which three letters I&#8217;m referring to. Looks like they&#8217;re even more relevant in some Eclipse components than I ever fancied (no - not telling, in which component I searched <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2012/01/a-little-statistics-of-the-day/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Object Teams with Null Annotations</title>
		<link>http://blog.objectteams.org/2011/12/object-teams-with-null-annotations/</link>
		<comments>http://blog.objectteams.org/2011/12/object-teams-with-null-annotations/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 21:32:14 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[OTDT]]></category>

		<category><![CDATA[Object Teams]]></category>

		<category><![CDATA[analysis]]></category>

		<category><![CDATA[bug]]></category>

		<category><![CDATA[EclipseCon]]></category>

		<category><![CDATA[JDT]]></category>

		<category><![CDATA[modularity]]></category>

		<category><![CDATA[null]]></category>

		<category><![CDATA[presentation]]></category>

		<category><![CDATA[product line]]></category>

		<category><![CDATA[release]]></category>

		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=128</guid>
		<description><![CDATA[The recent release of Juno M4 brought an interesting combination: The Object Teams Development Tooling now natively supports annotation-based null analysis for Object Teams (OT/J). How about that? 
  
The path behind us
Annotation-based null analysis has been added to Eclipse in several stages:

Using OT/J for prototyping
As discussed in this post, OT/J excelled once more [...]]]></description>
			<content:encoded><![CDATA[<p>The recent release of <a href="http://www.eclipse.org/downloads/index-developer.php">Juno M4</a> brought an interesting combination: The <a href="http://www.eclipse.org/objectteams">Object Teams</a> <a href="http://wiki.eclipse.org/Object_Teams_Development_Tooling">Development Tooling</a> now natively supports annotation-based null analysis for Object Teams <a href="http://wiki.eclipse.org/OTJ">(OT/J)</a>. How about that? <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<center><img src="http://blog.objectteams.org/wp-uploads/2011/01/nonpe.png" alt="NO NPE" title="NO NPE" width="64" height="64"/>  <img src="http://www.eclipse.org/objectteams/images/ot_64n.png" /></center></p>
<h3>The path behind us</h3>
<p><a href="http://wiki.eclipse.org/JDT_Core/Null_Analysis">Annotation-based null analysis</a> has been added to Eclipse in several stages:</p>
<dl>
<dt style="font-weight:bold;">Using OT/J for prototyping</dt>
<dd style="margin-left:15px;margin-bottom:5px;">As discussed in <a href="http://blog.objectteams.org/2011/03/null-annotations-prototyping-without-the-pain/">this post</a>, OT/J excelled once more in a complex development challenge: it solved the conflict between extremely tight integration and separate development without double maintenance. That part was real fun.</dd>
<dt style="font-weight:bold;">Applying the prototype to numerous platforms</dt>
<dd style="margin-left:15px;margin-bottom:5px;">Next I <a href="http://blog.objectteams.org/2011/08/mix-n-match-language-support/">reported</a> that only one binary deployment of the OT/J-based prototype sufficed to upgrade any of 12 different versions of the JDT to support null annotations &#8212; looks like a cool product line</dd>
<dt style="font-weight:bold;">Pushing the prototype into the JDT/Core</dt>
<dd style="margin-left:15px;margin-bottom:5px;">Next all of the JDT team (<a href="http://www.eclipse.org/projects/project.php?id=eclipse.jdt.core">Core</a> and <a href="http://www.eclipse.org/projects/project.php?id=eclipse.jdt.ui">UI</a>) invested efforts to make the new feature an integral part of the JDT. Thanks to all for this great collaboration!</dd>
<dt style="font-weight:bold;">Merging the changes into the OTDT</dt>
<dd style="margin-left:15px;margin-bottom:5px;">Now, that the new stuff was mixed back into the plain-Java implementation of the JDT, it was no longer applicable to other variants, but the routine merge between JDT/Core HEAD and Object Teams automatically brought it back for us. With the <a href="http://www.eclipse.org/objectteams/download.php#R21">OTDT 2.1 M4</a>, annotation-based null analysis is integral part of the OTDT.</dd>
</dl>
<h3 style="margin-top:20px;">Where we are now</h3>
<p>Regarding the JDT, others like <a href="http://www.jroller.com/andyl/entry/no_more_npe_s">Andrey</a>, <a href="http://blog.deepakazad.com/2011/12/annotation-based-null-analysis-with-jdt.html">Deepak</a> and <a href="http://eclipseandjazz.blogspot.com/2011/12/inter-procedural-null-analysis-using.html">Aysush</a> have beaten me in blogging about the new coolness. It seems the feature even made it to become a <a href="http://jaxenter.com/eclipse-juno-3-8-4-2-edges-ever-closer-with-milestone-4-39780.html">top mention</a> of the <a href="http://download.eclipse.org/eclipse/downloads/drops4/S-4.2M4-201112092100/eclipse-news-M4.html">Eclipse SDK Juno M4</a>. Thanks for spreading the word!</p>
<p>Ah, and thanks to <a href="http://www.fosslc.org">FOSSLC</a> you can now watch my <a title="Bye, bye, NPE, at ECE 2011" href="http://www.fosslc.org/drupal/content/bye-bye-npe">ECE 2011 presentation</a> on this topic.</p>
<h3>Two problems of OOP, and their solutions</h3>
<p>Now, OT/J with null annotations is indeed an interesting mix, because it solves two inherent problems of object-oriented programming, which couldn&#8217;t differ more:</p>
<p><b>1.: NullPointerException</b> is the most widespread and most <b>embarrassing bug</b> that we produce day after day, again and again. Pushing support for null annotations into the JDT has one major motivation: if you use the JDT but don&#8217;t use null annotations <b>you&#8217;ll no longer have an excuse</b>. For no good reasons your code will retain these miserable properties:</p>
<ul>
<li>It <b>will throw</b> those embarrassing NPEs.</li>
<li>It doesn&#8217;t tell the reader about fundamental <b>design decisions</b>: which part of the code is <b>responsible</b> for handling which potential problems?</li>
</ul>
<p>Why is this problem inherent to OOP? The dangerous operator that causes the exception is this:<br />
<center style="margin:-5px;"><a href='http://blog.objectteams.org/wp-uploads/2011/12/npddot.png'><img width="550" src="http://blog.objectteams.org/wp-uploads/2011/12/npddot.png" alt="" title="The DOT" class="aligncenter size-medium wp-image-126" /></a></center><br />
right, the tiny little <b>dot</b>. And that happens to be the least dispensable operator in OOP.</p>
<p><b>2.: Objectivity</b> seems to be a central property on any approach that is based just on <b>Objects</b>. While so many other activities in software engineering are based on the insight that complex problems with many stakeholders involved can best be addressed using <b>perspectives</b> and <b>views</b> etc., OOP forces you to abandon all that: an object is an object is an object. Think of a very simple object: a File. Some part of the application will be interested in the content so it can decode the bytes and do s.t. meaningful with it, another part of the application (maybe an underlying framework) will mainly be interested in the path in the filesystem and how it can be protected against concurrent writing, still other parts don&#8217;t care about either but only let you send the thing over the net. By representing the &#8220;File&#8221; as an object, that object must have <b>all properties</b> that are relevant to <b>any part</b> of the application. It must be openable, lockable and sendable and whatnot. This yields bloated objects and unnecessary, sometimes daunting dependencies. Inside the object all those different use cases it is involved in can not be separated!</p>
<p>With <b>roles</b> objectivity is replaced by a disciplined form of <b>subjectivity</b>: each part of the application will see the object with exactly those properties it needs, mediated by a specific role. New parts can add new properties to existing objects &#8212; but not in the unsafe style of dynamic languages, but strictly typed and checked. What does it mean for practical design challenges? E.g, direct support for feature oriented designs - the direct path to painless product lines etc.</p>
<p>Just like the dot, objectivity seems to be hardcoded into OOP. While null annotations make the dot safe(r), the roles and teams of OT/J add a new dimension to OOP where perspectives can be used directly in the implementation. Maybe it does make sense, to have both capabilities in one language <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> although one of them cleans up what should have been sorted out many decades ago while the other opens new doors towards the future of sustainable software designs.</p>
<h3>The road ahead</h3>
<p>The work on null annotations goes on. What we have in M4 is usable and I can only encourage adopters to start using it right now, but we still have an ambitious goal: eventually, the null analysis shall not only find <em>some</em> NPEs in your program, but eventually the absense of null related errors and warnings shall give the developer the guarantee that this piece of code <b>will never throw NPE at runtime</b>.</p>
<p>What&#8217;s missing towards that goal:</p>
<ol>
<li><b>Fields</b>: we don&#8217;t yet support <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649">null annotations for fields</a>. This is next on our plan, but one particular issue will require experimentation and feedback: how do we handle the initialization phase of an object, where fields start as being null? More on that soon.</li>
<li><b>Libraries</b>: we want to support <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=331651">null specifications for libraries</a> that have no null annotations in their source code.</li>
<li><b>JSR 308</b>: only with JSR 308 will we be able to annotate <b>all</b> occurrences of types, like, e.g., the element type of a collection (think of <code>List<@NonNull String></code>)</li>
</ol>
<p>Please stay tuned as the feature evolves. Feedback including bug reports is very welcome!</p>
<p>Ah, and one more thing in the future: I finally have the opportunity to work out a cool tutorial with a fellow JDT committer: <a href="http://www.eclipsecon.org/2012/sessions/how-train-jdt-dragon">How To Train the JDT Dragon</a> with Ayushman. Hope to see y&#8217;all in Reston!</p>
<p><a href='http://blog.objectteams.org/wp-uploads/2011/12/130x100_speaking_ecna12.gif'><img src="http://blog.objectteams.org/wp-uploads/2011/12/130x100_speaking_ecna12.gif" alt="" title="130x100_speaking_ecna12" width="130" height="100" class="alignnone size-full wp-image-127" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2011/12/object-teams-with-null-annotations/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Essence of Object Teams</title>
		<link>http://blog.objectteams.org/2011/09/the-essence-of-object-teams/</link>
		<comments>http://blog.objectteams.org/2011/09/the-essence-of-object-teams/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 14:39:14 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[Examples]]></category>

		<category><![CDATA[Object Teams]]></category>

		<category><![CDATA[dimensions]]></category>

		<category><![CDATA[modularity]]></category>

		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=125</guid>
		<description><![CDATA[When I write about Object Teams and OT/J I easily get carried away indulging in cool technical details. Recently in the Object Teams forum we were asked about the essence of OT/J which made me realize that I had neglected the high-level picture for a while. Plus: this picture looks a bit different every time [...]]]></description>
			<content:encoded><![CDATA[<p>When I write about Object Teams and OT/J I easily get carried away indulging in cool technical details. Recently in the <a href="http://www.eclipse.org/forums/index.php/f/157/">Object Teams forum</a> we were asked about the essence of OT/J which made me realize that I had neglected the high-level picture for a while. Plus: this picture looks a bit different every time I look at it, so here is today&#8217;s answer in two steps: short and extended.</p>
<p><u>Short version:</u></p>
<div style="margin:15px;margin-bottom:10px;text-align:center;background-color:#def4fe;border: 2px solid #c4c295;padding:5px;">
<strong>OT/J adds to OO the capability to define a program in terms of multiple <em>perspectives</em>.<br />
</strong></div>
<p><u>Extended version:</u></p>
<p>In software design, e.g., we are used to describing a system from multiple perspectives or views, like: structural vs. behavioral views, architectural vs. implementation views, views focusing on distribution vs. business logic, or just: one perspective per use case.<br />
<img src="http://upload.wikimedia.org/wikipedia/commons/8/81/UML_Diagrams.jpg"/><br />
A collage of UML diagrams</br><br />
&copy; 2009, <a href="http://en.wikipedia.org/wiki/User:Kishorekumar_62">Kishorekumar 62</a>, licensed under the <a href="http://en.wikipedia.org/wiki/en:Creative_Commons">Creative Commons</a> <a href="http://creativecommons.org/licenses/by-sa/3.0/deed.en">Attribution-Share Alike 3.0 Unported</a> license.</p>
<p>In regular OO programming this is not well supported, an object is defined by exactly one class and no matter from which perspective you look at it, it always has the exact same properties. The best we can do here is controlling the visibility of methods by means of interfaces.</p>
<div align=center>
<a href='http://blog.objectteams.org/wp-uploads/2011/09/oneclass2.png'><img src="http://blog.objectteams.org/wp-uploads/2011/09/oneclass2.png" alt="" title="one class" class="aligncenter size-full wp-image-121" /></a></p>
<div style="margin-top:-15px; margin-bottom:15px;">
A person is a person is a person!?
</div>
</div>
<p>By contrast, in OT/J you start with a set of lean base objects and then you may attach specific roles for each perspective. Different use cases and their scenarios can be implemented by different roles. Visualization in the UI may be implemented by another independent set of roles, etc.</p>
<div align=center>
<a href='http://blog.objectteams.org/wp-uploads/2011/09/basewithroles2.png'><img src="http://blog.objectteams.org/wp-uploads/2011/09/basewithroles2.png" alt="" title="base with roles" class="alignnone size-full wp-image-122" /></a></p>
<div style="margin-top:-15px; margin-bottom:15px;">
A base seen from multiple perspectives via roles.
</div>
</div>
<h3>Code-level comparison?</h3>
<p>I&#8217;ve been asked to compare standard OO and OT/J by direct comparison of code examples, but I&#8217;m not sure if it is a good idea to do, because OT/J is not intended to just provide a nicer syntax for things you can do in the same way using OO. OT/J - as any serious new programming language should do IMHO - wants you to <strong>think</strong> differently about your design. For example, we can give an educational implementation of the <a href="http://wiki.eclipse.org/OTExample_Observer">Observer pattern using OT/J</a>, but once you &#8220;think Object Teams&#8221; you may not be interested in the Observer pattern any more, because you can achieve basically the same effect using a single callin binding as shown in our <a href="http://wiki.eclipse.org/OTExample_Stopwatch">Stopwatch example</a>.</p>
<p>So, positively speaking, OT/J wants you to think in terms of perspectives and make the perspectives you would naturally use for describing the system explicit by means of roles.</p>
<p>OTOH, a new language is of course only worth the effort if you have a <strong>problem</strong> with existing approaches. The problems OT/J addresses are inherently difficult to discuss in small examples, because they are:</p>
<ol>
<li><strong>software complexity</strong>, e.g., with standard OO finding a suitable decomposition where different concerns are not badly tangled with each other becomes notoriously difficult.</li>
<li><strong>software evolution</strong>, e.g., the initial design will be challenged with change requests that no-one can foresee up-front.</li>
</ol>
<p>(<em>Plus all the other <a href="http://blog.objectteams.org/2011/03/combination-of-concerns/">concerns addressed</a></em>)</p>
<p>Both, theory and experience, tell me that OT/J excels in both fields. If anyone wants to challenge this claim using your own example, please do so and post your findings, or lets discuss possible designs together.</p>
<h3>One more essential concept</h3>
<p>I should also mention the second essence in OT/J: after slicing elements of your program into roles and base objects we also support to <strong>re-group</strong> the pieces in a meaningful way: as <strong>roles are contained in teams</strong>, those teams enable you to raise the level of abstraction such that each user-relevant feature, e.g., can be captured in exactly one team, hiding all the details inside. As a result, for a high-level design view you no longer have to look at diagrams of hundreds of classes but maybe just a few tens of teams.</p>
<p>Hope this helps seeing the big picture. Enough hand-waving for today, back to the code! <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2011/09/the-essence-of-object-teams/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Builds are like real software - or even more so</title>
		<link>http://blog.objectteams.org/2011/09/builds-are-like-real-software-or-even-more-so/</link>
		<comments>http://blog.objectteams.org/2011/09/builds-are-like-real-software-or-even-more-so/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 14:28:25 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[OTDT]]></category>

		<category><![CDATA[build]]></category>

		<category><![CDATA[error]]></category>

		<category><![CDATA[p2]]></category>

		<category><![CDATA[pde]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=120</guid>
		<description><![CDATA[Being a part-time release engineer for the Object Teams project I can only agree with every word Kim writes about the job, I wish I could hire her for our project  
She writes: 
&#8220;Nobody in needs to understand how the build works, they just need to push a button.  That&#8217;s great. Until the [...]]]></description>
			<content:encoded><![CDATA[<p>Being a part-time release engineer for the Object Teams project I can only agree with every word <a href="http://relengofthenerds.blogspot.com/2011/09/busting-build-myths.html">Kim</a> writes about the job, I wish I could hire her for our project <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>She writes: </p>
<blockquote><p>&#8220;Nobody in needs to understand how the build works, they just need to push a button.  That&#8217;s great. Until the day before a release when your build fails with a cryptic message about unresolved dependencies.  And you have no idea how to fix it.  And neither does anyone else on the team.&#8221;</p></blockquote>
<p>That puts a sad smile on my face and I&#8217;d like to add a little quality metric that seems cruel for today&#8217;s build systems, but might actually be useful for any software:</p>
<div style="margin:15px;margin-bottom:10px;text-align:center;background-color:#def4fe;border: 2px solid #c4c295;padding:5px;">
<strong>No software can be better than its worst error message.<br />
</strong></div>
<p>One extreme I experienced was in a PDE/Build-ant-build which I had to set to verbose to get any useful answer but then I had to find the relevant error message deeply buried in literally tens of megabytes of log output. Takes ages to browse that log file. Other tools rank towards the other end of the spectrum saying basically &#8220;it didn&#8217;t work&#8221;.</p>
<p>Why is the worst error message relevant? When you hit that worst message it&#8217;s close to saying &#8220;game over&#8221;. Especially when working on a build I&#8217;ve come to the point time and again where all my creativity and productivity came to a grinding halt and for days or weeks I simply made zero progress because I had no idea why that system didn&#8217;t work and what it expected me to do to fix the thing. Knock-out.</p>
<p>Obviously I hate that state when I make no progress towards my goal. And typically that state is reached by poor communication from some framework back to me.</p>
<h3>Real coolness</h3>
<p>I know people usually don&#8217;t like to work on improving error messages, but please, don&#8217;t think good error messages are any bit less cool than running your software on mars. On the one hand we try to build tools that improve developers&#8217; productivity by a few percent and than the tool will give answers that bring that very productivity down to zero. That&#8217;s - inconsistent.</p>
<p>I&#8217;m tempted to repeat the p2 story here. Many will remember the merciless dump of data from the sat solver that p2 gave in its early days. Some will consider the problem solved by now. Judge for yourself: what&#8217;s the worst-case time a regular Eclipse user will need to understand what p2 is telling him/her by one of its error messages.</p>
<p>The intention of this post is not to blame any particular technology. The list would be quite long anyway. It&#8217;s about general awareness (big words, sorry <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).</p>
<h3>Consider the worst case</h3>
<p>Again, why worst case? Because the worst case will happen. And it&#8217;s enough if it hits you once to easily compensate all the time savings the tool otherwise brought to you.</p>
<h3>Communicate!</h3>
<p>Framework developers, tool smiths: let your software communicate with the user and let it be especially helpful when the user is in dire need of help.</p>
<p>One small contribution in this field I&#8217;d like to share with you: in the <a href="http://wiki.eclipse.org/Object_Teams_Development_Tooling">OTDT</a> every error/warning raised by the compiler not only tries to precisely describe what&#8217;s wrong but it is directly <a href="http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.objectteams.otdt.doc%2Fguide%2Fcompilation.html">linked to the corresponding paragraph in the language definition</a> that is violated by the current code. At least this should completely explain <em>why</em> the current code is <em>wrong</em>. It&#8217;s a small step, but I feel a strong need for linking specific help to every error message.</p>
<p>But first, the software has to anticipate every single error that will occur in order to produce useful messages. That&#8217;s the real reason why creating complex software is so challenging. Be it a build system or the &#8220;real&#8221; software.</p>
<p>Be cool, give superb error messages!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2011/09/builds-are-like-real-software-or-even-more-so/feed/</wfw:commentRss>
		</item>
		<item>
		<title>&#8220;OT/J 7&#8243;</title>
		<link>http://blog.objectteams.org/2011/08/otj-7/</link>
		<comments>http://blog.objectteams.org/2011/08/otj-7/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 17:32:25 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[Object Teams]]></category>

		<category><![CDATA[analysis]]></category>

		<category><![CDATA[context]]></category>

		<category><![CDATA[intent]]></category>

		<category><![CDATA[Java7]]></category>

		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=119</guid>
		<description><![CDATA[In my previous post I wrote about the challenge of maintaining 12 variants of the JDT/Core to support any combination of Java 6 vs. 7, Java vs. OT/J, with or without support for null annotations at versions Indigo GA, SR1 and Juno M1.
Meanwhile I played a bit with the combination of OT/J with Java 7. [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post I wrote about the challenge of maintaining 12 variants of the JDT/Core to support any combination of Java 6 vs. 7, Java vs. OT/J, with or without support for null annotations at versions Indigo GA, SR1 and Juno M1.</p>
<p><strong>Meanwhile I played a bit with the combination of OT/J with Java 7. While I&#8217;m not that excited about Java 7 I found a way to combine the two that I found quite cute.</strong></p>
<h3>The typical OT/J foo-bar story</h3>
<p>Consider the following classes:</p>

<div class="wp_syntax"><div class="code"><pre class="otj" style="font-family:monospace;"><span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">class</span> Foo <span style="color: #000000;">&#123;</span>
    <span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">void</span> foo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000; font-weight: normal">System</span>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><span style="color: #2A00ff;">&quot;foo&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">team</span> <span style="color: #7F0055; font-weight: bold;">class</span> MyTeam <span style="color: #000000;">&#123;</span>
    <span style="color: #7F0055; font-weight: bold;">protected</span> <span style="color: #7F0055; font-weight: bold;">class</span> R <span style="color: #7F0055; font-weight: bold;">playedBy</span> Foo <span style="color: #000000;">&#123;</span>
        <span style="color: #7F0055; font-weight: bold;">callin</span> <span style="color: #7F0055; font-weight: bold;">void</span> bar<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000; font-weight: normal">System</span>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><span style="color: #2A00ff;">&quot;bar&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> <span style="color: #000000;">&#125;</span>
        bar <span style="color: #7F0055;font-weight:bold;">&lt;-</span> <span style="color: #7F0055; font-weight: bold;">replace</span> foo<span style="color: #000000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>So, we can use the team to replace the output &#8220;foo&#8221; by the output &#8220;bar&#8221;.<br />
Now, a client calls <code>f.foo()</code> every now and then and may want to use the team to turn just one of the foos into bar. He may try this:</p>

<div class="wp_syntax"><div class="code"><pre class="otj" style="font-family:monospace;">    <span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">String</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        Foo f <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> Foo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
        f.<span style="color: #000000;">foo</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
        test<span style="color: #000000;">&#40;</span>f<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
        f.<span style="color: #000000;">foo</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> test<span style="color: #000000;">&#40;</span>Foo f<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        MyTeam aTeam <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> MyTeam<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
        aTeam.<span style="color: #000000;">activate</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
        f.<span style="color: #000000;">foo</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
    <span style="color: #000000;">&#125;</span></pre></div></div>

<p>He may expect this output:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">foo
bar
foo</pre></div></div>

<p>BUT, that&#8217;s not what he gets: the team remains active and we&#8217;ll see</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">foo
bar
bar</pre></div></div>

<p><strong>BUMMER.</strong></p>
<h3>What is a resource?</h3>
<p>I kind-of like the new try-with-resources construct, so what can we actually use it for, is it just for FileReaders and things like that?</p>
<p>Since a resource is anything that is a subtype of <code>AutoCloseable</code> we can use the concept for anything that has an open-close lifecycle. So, what about &#8212; teams? Well, teams don&#8217;t have <code>open()</code> and <code>close()</code> methods, but isn&#8217;t team activation related? Activation opens a context and deactivation closes the context, no?</p>
<p>Let&#8217;s turn the team into an <code>AutoCloseable</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="otj" style="font-family:monospace;"><span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">team</span> <span style="color: #7F0055; font-weight: bold;">class</span> MyTeam <span style="color: #7F0055; font-weight: bold;">implements</span> AutoCloseable <span style="color: #000000;">&#123;</span>
    <span style="color: #3F7F5F; font-style: italic;">// role R as before ...</span>
&nbsp;
    <span style="color: #3F5FBF;">/** Just a simple factory method for active teams. */</span>
    <span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> MyTeam createActiveTeam<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        MyTeam t <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> MyTeam<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
        t.<span style="color: #000000;">activate</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
        <span style="color: #7F0055; font-weight: bold;">return</span> t<span style="color: #000000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">void</span> close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #3F7F5F; font-style: italic;">// please don't throw anything here, it spoils the whole story!</span>
        deactivate<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<h3>Compiler-guided development</h3>
<p>Before jumping at the solution, let me show you, what the new warning from <a title="[1.7] new warning for missing try-with-resources" href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=349326">Bug 349326</a> will tell you:<br />
<a href='http://blog.objectteams.org/wp-uploads/2011/08/unclosedteam1.png'><img src="http://blog.objectteams.org/wp-uploads/2011/08/unclosedteam1.png" alt="" title="Warning: Leaking resource"  class="aligncenter size-full wp-image-113" /></a></p>
<p>Ah, this is when our developer wakes up: <em>&#8220;I might have to close that thing, good, I&#8217;m smart enough to do that&#8221;</em>. Unfortunately, our developer is too smart, relying on some magic of the hashCode of his Foo:<br />
<a href='http://blog.objectteams.org/wp-uploads/2011/08/unclosedteam2.png'><img src="http://blog.objectteams.org/wp-uploads/2011/08/unclosedteam2.png" alt="" title="Potential resource leak"  class="aligncenter size-full wp-image-114" /></a></p>
<p>You imagine, that now the full power of the compiler&#8217;s flow analysis will watch whether the thing is really closed <em>on every path</em>!</p>
<p>But even when the dev stops trying to outsmart the compiler, the compiler isn&#8217;t 100% happy:<br />
<a href='http://blog.objectteams.org/wp-uploads/2011/08/closedteam1.png'><img src="http://blog.objectteams.org/wp-uploads/2011/08/closedteam1.png" alt="" title="Closed but still not optimal"  class="aligncenter size-full wp-image-115" /></a><br />
We see the desired output now, but the method can and probably should still be improved: tell us what you mean: are these just three independent method calls? No, lines 1 and 3 are intended as a bracket for line 2: only within this context should <code>aTeam</code> affect the behavior of <code>f</code>.</p>
<p>Here&#8217;s our brave new OT/J 7 world:<br />
<a href='http://blog.objectteams.org/wp-uploads/2011/08/closedteam2a.png'><img src="http://blog.objectteams.org/wp-uploads/2011/08/closedteam2a.png" alt="" title="Try with team" class="aligncenter size-full wp-image-116" /></a></p>
<p>Method <code>test2()</code> <em>normally</em> behaves identical to <code>test1()</code>, but we have two important differences:</p>
<ul>
<li><code>test2()</code> is <strong>safe</strong> against exceptions, the team will <em>always</em> be deactivated
<li><code>test2()</code> makes the <strong>intention explicit</strong>: the <code>try () { }</code> construct is not only a lexical block, but also a well defined semantic context: telling us that only inside this context <code>aTeam</code> is open/active, and outside it&#8217;s not. We don&#8217;t need to sequentially read the statements of the method to learn this.
</ul>
<h3>An essential extension</h3>
<p>Following my argumentation, OT/J must have been waiting for this language extension for a long time, no? Well, not exactly waiting. In fact, here&#8217;s something we had from the very beginning almost a decade ago:</p>
<p><a href='http://blog.objectteams.org/wp-uploads/2011/08/closedteam3.png'><img src="http://blog.objectteams.org/wp-uploads/2011/08/closedteam3.png" alt="" title="\&quot;Within\&quot; block activation" class="aligncenter size-full wp-image-117" /></a></p>
<p>But still, it&#8217;s nice to see that now every developer can achieve the same effect for different applications, beyond input streams and teams <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here&#8217;s an exercise for the reader: the <strong>within</strong> construct in OT/J activates the team <em>only for the current thread</em>. With try-with-resources you can easily setup a context for <em>global</em> team activation and deactivation. </p>
<p>Happy hacking!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2011/08/otj-7/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Mix-n-match language support</title>
		<link>http://blog.objectteams.org/2011/08/mix-n-match-language-support/</link>
		<comments>http://blog.objectteams.org/2011/08/mix-n-match-language-support/#comments</comments>
		<pubDate>Fri, 19 Aug 2011 16:22:28 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[OTDT]]></category>

		<category><![CDATA[OTEquinox]]></category>

		<category><![CDATA[Object Teams]]></category>

		<category><![CDATA[analysis]]></category>

		<category><![CDATA[EclipseCon]]></category>

		<category><![CDATA[JDT]]></category>

		<category><![CDATA[null]]></category>

		<category><![CDATA[product line]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=112</guid>
		<description><![CDATA[I&#8217;ve been involved in the release of different versions of the JDT lately, supporting different flavors of Java.
Classical release management
At the core we have the plain JDT, of which we published the 3.7.0 release in June and right now first release candidates are being prepared towards the 3.7.1 service release, which will be the first [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been involved in the release of different versions of the JDT lately, supporting different flavors of Java.</p>
<h2>Classical release management</h2>
<p>At the core we have the plain JDT, of which we published the <strong>3.7.0 release</strong> in June and right now first release candidates are being prepared towards the <strong>3.7.1 service release</strong>, which will be the first official release to support <strong><font color="green">Java 7</font></strong>. At the same time the first <strong>milestones towards 3.8</strong> are being built. OK, this is almost normal business &mdash; with the exception of the service release differs more than usual from its base release, due to the unhappy timing of the release of Java 7 vs. Eclipse 3.7.</p>
<div style="margin:15px;margin-bottom:10px;text-align:center;background-color:#def4fe;border: 2px solid #c4c295;padding:5px;">
So that&#8217;s 3 versions in 2 month&#8217;s time.
</div>
<h2>First variant: Object Teams</h2>
<p>The same release plan is mirrored by the Object Teams releases 2.0.0, 2.0.1RC1, 2.1.0M1. Merging the delta from JDT 3.7 to 3.7.1 into the OTDT was a challenge, given that this delta contained the full implementation of all that&#8217;s new in Java 7. Still with the experience of regularly merging JDT/Core changes into the OT variant, the pure merging was less than one day plus a couple more days until all 50000+ tests were green again. The nice thing about the architecture of the OTDT: after merging the JDT/Core, I was done. Since all other adaptations of the JDT are implemented using OT/Equinox adopting, e.g., all the new quick assists for Java 7 required a total of zero minutes integration time.</p>
<p>I took the liberty of branching 2.0.x and 2.1 only after integrating the Java 7 support, which also means that 2.1 M1 has only a small number of OT-specific improvements that did not already go into 2.0.1.</p>
<div style="margin:15px;margin-bottom:10px;text-align:center;background-color:#def4fe;border: 2px solid #c4c295;padding:5px;">
This gives 6 versions of the JDT in 2 month&#8217;s time.
</div>
<h2>Prototyping annotation based null analysis</h2>
<p>As I wrote <a href="http://blog.objectteams.org/2011/03/null-annotations-prototyping-without-the-pain/">before</a>, I&#8217;m preparing a comprehensive new feature for the JDT/Core: static analysis for potential NullPointerException based on annotations in the code. The latest patch attached to <a href="http://bugs.eclipse.org/186342">the bug</a> had almost 3000 lines. Recent discussions at <a href="http://2011.ecoop.org">ECOOP</a> made me change my mind in a few questions, so I changed some implementation strategies. Luckily the code is well modularized due to the use of OT/Equinox.</p>
<p>Now came the big question: against which version of the JDT should I build the null-annotation add-on? I mean, which of the 6 versions I have been involved in during the last 2 months?</p>
<p>As I like a fair challenge every now and then I decided: <strong>all six</strong>, i.e., I wanted to support adding the new static analysis to all six JDT versions mentioned before.</p>
<h3>Integration details</h3>
<p>Anybody who has worked on a Java compiler will confirm: if you change one feature of the compiler chances are that any other feature can be broken by the change (I&#8217;m just paraphrasing: &#8220;it&#8217;s complex&#8221;). And indeed, applying the nullity plug-in to the OTDT caused some headache at first, because both variants of the compiler make specific assumptions about the order in which specific information is available during the compilation process. It turned out that two of these assumptions where simply incompatible, so I had to make some changes (here I made the null analysis more robust).</p>
<p>At the point where I thought I was done, I tripped over an ugly problem that&#8217;s intrinsic to Java.<br />
The nullity plug-in adapts a method in the JDT/Core which contains the following switch statement:</p>

<div class="wp_syntax"><div class="code"><pre class="otj" style="font-family:monospace;">	<span style="color: #7F0055; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>token <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">this</span>.<span style="color: #000000;">scanner</span>.<span style="color: #000000;">getNextToken</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">!=</span> TerminalTokens.<span style="color: #000000;">TokenNameEOF</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		IExtendedModifier modifier <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">null</span><span style="color: #000000;">;</span>
		<span style="color: #7F0055; font-weight: bold;">switch</span><span style="color: #000000;">&#40;</span>token<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #7F0055; font-weight: bold;">case</span> TerminalTokens.<span style="color: #000000;">TokenNameabstract</span><span style="color: #000000;">:</span>
				modifier <span style="color: #000000;">=</span> createModifier<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">Modifier</span>.<span style="color: #000000;">ModifierKeyword</span>.<span style="color: #000000;">ABSTRACT_KEYWORD</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
				<span style="color: #7F0055; font-weight: bold;">break</span><span style="color: #000000;">;</span>
			<span style="color: #7F0055; font-weight: bold;">case</span> TerminalTokens.<span style="color: #000000;">TokenNamepublic</span><span style="color: #000000;">:</span>
				modifier <span style="color: #000000;">=</span> createModifier<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">Modifier</span>.<span style="color: #000000;">ModifierKeyword</span>.<span style="color: #000000;">PUBLIC_KEYWORD</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
				<span style="color: #7F0055; font-weight: bold;">break</span><span style="color: #000000;">;</span>
			<span style="color: #3F7F5F; font-style: italic;">// more cases</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I have a copy of this method where I only added a few lines to one of the case blocks.<br />
Compiles fine against any version of the JDT. <strong>But Eclipse hangs</strong> when I install this plugin on top of a wrong JDT version. What&#8217;s wrong?</p>
<p>The problem lies in the (internal) interface TerminalTokens. The required constants TokenNameabstract etc. are of course present in all versions of this interface, <strong>however</strong> the values of these constants change every time the parser is generated anew. If constants were really abstractions that encapsulate their implementation values, all would be fine, but the Java byte code knows nothing about such an abstraction, all constant values are inlined during compilation. In other words: the meaning of a constant depends solely on the definitions which the compiler sees during compilation. Thus compiling the above switch statement hardcodes a dependency on one particular version of the interface TerminalTokens. <strong>BAD</strong>.</p>
<p>After recognizing the problem, I had to copy some different versions of the interface into my plug-in, implement some logic to translate between the different encodings and that problem was solved.</p>
<p>What&#8217;s next?</p>
<p>Nothing is next. At this point I could apply the nullity plug-in to all six versions of the JDT and all are  behaving well.</p>
<div style="margin:15px;margin-bottom:10px;text-align:center;background-color:#def4fe;border: 2px solid #c4c295;padding:5px;">
We indeed have 12 versions of the JDT in 2 month&#8217;s time.
</div>
<h2>Mix-n-match</h2>
<p>Would you like Java with our without the version 7 enhancements (stable release or milestone)? May I add some role and team classes? How about a dash more static analysis? It turns out we have more than just one product, we have a full little product line with features to pick or opt-out:</p>
<p><center></p>
<table border="1">
<tr>
<th colspan="2" rowspan="2">&nbsp;
<th>Java 6
<th colspan="2">Java 7</tr>
<tr>
<th>Indigo
<th>Indigo SR1
<th>Juno M1</tr>
<tr>
<td rowspan="2"  align="right">no null annotations
<td>Plain JDT
<td style="background-color:#def4fe;">&nbsp;
<td style="background-color:#bed4de;">&nbsp;
<td style="background-color:#def4fe;">&nbsp;</tr>
<tr>
<td align="right">OTDT
<td style="background-color:#bed4de;">&nbsp;
<td style="background-color:#def4fe;">&nbsp;
<td style="background-color:#bed4de;">&nbsp;</tr>
<tr>
<td rowspan="2">with null annotations
<td>Plain JDT
<td style="background-color:#def4fe;">&nbsp;
<td style="background-color:#bed4de;">&nbsp;
<td style="background-color:#def4fe;">&nbsp;</tr>
<tr>
<td align="right">OTDT
<td style="background-color:#bed4de;">&nbsp;
<td style="background-color:#def4fe;">&nbsp;
<td style="background-color:#bed4de;">&nbsp;</tr>
</table>
<p></center></p>
<ul>
<li><b>OTDT:</b> <a href="http://www.eclipse.org/objectteams/download.php">http://www.eclipse.org/objectteams/download.php</a>
<li><b>Null ananlysis:</b> <a href="http://wiki.eclipse.org/JDT_Core/Null_Analysis">http://wiki.eclipse.org/JDT_Core/Null_Analysis</a>
</ul>
<p>Just make your choice <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Happy hacking with null annotations and try-with-resources in OT/J.</p>
<table border="0">
<tr>
<td><a href="http://eclipsecon.org/europe2011/"><img alt="EclipseCon Europe 2011" src="http://eclipsecon.org/europe2011/sites/all/themes/themes/europe2011/images/logo.png"></a></td>
<td style="width:20px;">&nbsp;</p>
<td>BTW: if you want to hear a bit more about the work on null annotations, you should really come to EclipseCon Europe &mdash; why not drop a comment at this <a href="http://eclipsecon.org/europe2011/sessions/bye-bye-npe">submission</a> <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2011/08/mix-n-match-language-support/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A use case for Java 7</title>
		<link>http://blog.objectteams.org/2011/06/a-use-case-for-java-7/</link>
		<comments>http://blog.objectteams.org/2011/06/a-use-case-for-java-7/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 16:11:01 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[bug]]></category>

		<category><![CDATA[Java7]]></category>

		<category><![CDATA[quickfix]]></category>

		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=111</guid>
		<description><![CDATA[Recent stress tests have revealed a few issues in the Eclipse platform where leaking file handles could cause &#8220;Too many open files&#8221;-style failures.
Until now that kind of issue was notoriously difficult to analyze, and a lot of luck was involved when I spotted one of those bugs by mere code inspection.
However, chances are that this [...]]]></description>
			<content:encoded><![CDATA[<p>Recent stress tests have revealed a few issues in the Eclipse platform where leaking file handles could cause &#8220;Too many open files&#8221;-style failures.</p>
<p>Until now that kind of issue was notoriously difficult to analyze, and a lot of luck was involved when I spotted <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=349121">one of those bugs</a> by mere code inspection.</p>
<p>However, chances are that this particular kind of bug will soon be a curiosity from the past. How? Java 7 brings a new feature that should be used in exactly this kind of situation: by the new <strong><a href="http://www.baptiste-wicht.com/2010/08/java-7-try-with-resources-statement/">try-with-resources</a></strong> construct leaking of any resources can be safely avoided.</p>
<p>Now, current code certainly doesn&#8217;t use try-with-resources, how can we efficiently migrate existing code to using this new feature? As one step I just filed this <a title="Bug 349326 - [1.7] new warning for missing try-with-resources" href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=349326">RFE</a> for a new warning where try-with-resources should probably be used but is not. At this point I can&#8217;t promise that we&#8217;ll be able to implement the new warning in a useful way, i.e., without too many false positives, but it sounds like a promising task, doesn&#8217;t it?</p>
<p>Here&#8217;s a <strong>mockup</strong> of what I&#8217;m thinking of:</p>
<p><a href='http://blog.objectteams.org/wp-uploads/2011/06/readintoarray-withwarning.png'><img src="http://blog.objectteams.org/wp-uploads/2011/06/readintoarray-withwarning.png" alt="Warning: potential resource leak" title="Warning: potential resource leak" class="aligncenter size-full wp-image-109" /></a></p>
<p>And this is what the quickfix <strong>would</strong> create:<br />
<a href='http://blog.objectteams.org/wp-uploads/2011/06/quickfixedtrywithresources.png'><img src="http://blog.objectteams.org/wp-uploads/2011/06/quickfixedtrywithresources.png" alt="After applying the quickfix" title="After applying the quickfix"  class="aligncenter size-full wp-image-110" /></a></p>
<p>Sounds cool?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2011/06/a-use-case-for-java-7/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Between the Times</title>
		<link>http://blog.objectteams.org/2011/06/between-the-times/</link>
		<comments>http://blog.objectteams.org/2011/06/between-the-times/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 13:56:18 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[Object Teams]]></category>

		<category><![CDATA[build]]></category>

		<category><![CDATA[Indigo]]></category>

		<category><![CDATA[install]]></category>

		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=108</guid>
		<description><![CDATA[This week is (supposed to be) &#8220;quiet week&#8221; at Eclipse: Release Candidate 4 is in place and more testing is being done before the final Indigo Release. Time to speak of s.t. that the Object Teams project has neglected a bit in the past: compiling / building with Maven.
Compiling OT/J with Maven
In the days of [...]]]></description>
			<content:encoded><![CDATA[<p>This week is (<a href="https://bugs.eclipse.org/349267">supposed to be</a>) &#8220;quiet week&#8221; at Eclipse: Release Candidate 4 is in place and more testing is being done before the final <a href="http://www.eclipse.org/indigo">Indigo Release</a>. Time to speak of s.t. that the Object Teams project has neglected a bit in the past: compiling / building with Maven.</p>
<h2>Compiling OT/J with Maven</h2>
<p>In the days of Maven2, pluging-in a non-standard compiler required fiddling with the nexus compiler plugin, which was buggy and all that. With the recent development around Maven3 and Tycho things became easier. The following pom-snippet is all you need to tell Maven to use the OT/J compiler:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pluginManagement<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #808080; font-style: italic;">&lt;!-- Use compiler plugin with tycho as the adapter to the OT/J compiler. --&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-compiler-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.6<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.6<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;compilerId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jdt<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/compilerId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		    <span style="color: #808080; font-style: italic;">&lt;!-- This dependency provides the implementation of compiler &quot;jdt&quot;: --&gt;</span>
		    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.sonatype.tycho<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>tycho-compiler-jdt<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${tycho.version}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exclusions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			    <span style="color: #808080; font-style: italic;">&lt;!-- Exclude the original JDT/Core to be replaced by the OT/J variant: --&gt;</span>
			    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exclusion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.sonatype.tycho<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse.jdt.core<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exclusion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exclusions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #808080; font-style: italic;">&lt;!-- plug the OT/J compiler into the tycho-compiler-jdt plug-in: --&gt;</span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>objectteams-otj-compiler<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${otj.version}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pluginManagement<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This relies on the fact, that the OT/J compiler is compatible with the JDT compiler, good.</p>
<p>To make things go smooth in various build phases a few more bits are required:</p>
<ul>
<li>provide the OT/J runtime jar and its dependency (bcel)</li>
<li>tell surefire about required command line arguments for running OT/J programs</li>
</ul>
<p>These basics are collected in a parent pom so that all you need are these two snippets:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;repositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ObjectTeamsRepository<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Object Teams Repository<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://download.eclipse.org/objectteams/maven/3/repository<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/repositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>objectteams-parent-pom<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.0.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/parent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This converts any Java project into an OT/J project, simply enough, huh?</p>
<p>At least compiling and testing works out-of-the box. Let me know what additional sophistication you need and if adjustments to other build phases are needed.</p>
<h2>OT/J over m2e</h2>
<p>Well, I&#8217;m not much of a Maven expert, but I&#8217;m an Eclipse enthusiast, so, how can we use the above inside the IDE?</p>
<p>The bad news: the m2e plug-in has hardcoded its support for the compiler plugin to use &#8220;javac&#8221; as the compiler. Naive attempts to use <code>tycho-compiler-jdt</code> have failed with the infamous <a href="http://wiki.eclipse.org/M2E_plugin_execution_not_covered"><code>"Plugin execution not covered by lifecycle configuration"</code></a>.</p>
<p>The good news: By writing a tiny <a href="http://wiki.eclipse.org/Category:OTEquinox">OT/Equinox</a> plug-in I was able to remedy those issues. If you have the m2e plug-in installed (Indigo version), the normal &#8220;Update Project Configuration&#8221; action will suffice:<br />
<a href='http://blog.objectteams.org/wp-uploads/2011/06/mavenconfigureproject.png'><img src="http://blog.objectteams.org/wp-uploads/2011/06/mavenconfigureproject.png" alt="Update Project Configuration" title="Update Project Configuration" width="710" class="aligncenter size-medium wp-image-104" /></a></p>
<p>After that, the project is recognized as an OT/J project, both by the IDE &#8230;<br />
<a href='http://blog.objectteams.org/wp-uploads/2011/06/mavenotjproject.png'><img src="http://blog.objectteams.org/wp-uploads/2011/06/mavenotjproject.png" alt="" title="OT/J Project" width="333" height="567" class="aligncenter size-full wp-image-105" /></a><br />
&#8230; and also by maven &#8230;<br />
<a href='http://blog.objectteams.org/wp-uploads/2011/06/maventestotjproject.png'><img src="http://blog.objectteams.org/wp-uploads/2011/06/maventestotjproject.png" alt="Running mvn test" title="Running mvn test" class="aligncenter size-full wp-image-106" /></a></p>
<h2>Where to get it?</h2>
<p>The mentioned plug-in is brand-new and as such it is not part of the regular <a href="http://www.eclipse.org/objectteams/download.php">OTDT distribution</a>. OTOH, the plug-in is so simple, I don&#8217;t expect a lot of changes needed. So, if you have an Indigo-ish Eclipse just add this update site:</p>
<ul>
<li><a href="http://download.eclipse.org/objectteams/updates/contrib">http://download.eclipse.org/objectteams/updates/contrib</a></li>
</ul>
<p>Then install &#8220;Maven Integration for Object Teams (Early Access)&#8221;:<br />
<a href='http://blog.objectteams.org/wp-uploads/2011/06/mavenintegrationinstall.png'><img src="http://blog.objectteams.org/wp-uploads/2011/06/mavenintegrationinstall.png" alt="Install the Maven Integration for Object Teams" title="Install the Maven Integration for Object Teams" class="aligncenter size-full wp-image-107" /></a></p>
<p>Don&#8217;t forget the <code>&lt;repository&gt;</code> and <code>&lt;parent&gt;</code> definitions from above and you should be ready to go! Yesss, sometimes it pays off that OT/J is a kind of Java, a lot of the tooling can just piggy-back on what&#8217;s already there for Java <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2011/06/between-the-times/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Follow-up: Object Teams Tutorial at EclipseCon 2011</title>
		<link>http://blog.objectteams.org/2011/04/follow-up-object-teams-tutorial-at-eclipsecon-2011/</link>
		<comments>http://blog.objectteams.org/2011/04/follow-up-object-teams-tutorial-at-eclipsecon-2011/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 20:14:28 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[Examples]]></category>

		<category><![CDATA[OTEquinox]]></category>

		<category><![CDATA[Object Teams]]></category>

		<category><![CDATA[design]]></category>

		<category><![CDATA[EclipseCon]]></category>

		<category><![CDATA[JDT]]></category>

		<category><![CDATA[presentation]]></category>

		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=103</guid>
		<description><![CDATA[At our EclipseCon tutorial we mentioned a bonus excercise, for which we didn&#8217;t have the time at the tutorial.
Now it&#8217;s time to reveal the solution. 
Task
&#8220;Implement the following demo-mode for the JDT:

&#8226; When creating a Java project let the user select:
&#10066; Project is for demo purpose only
&#8226; When creating a class in a Demo project:
insert [...]]]></description>
			<content:encoded><![CDATA[<p>At our <a href="http://www.eclipsecon.org/2011/sessions/?page=sessions&#038;id=2302">EclipseCon tutorial</a> we mentioned a <strong>bonus excercise</strong>, for which we didn&#8217;t have the time at the tutorial.</p>
<p>Now it&#8217;s time to reveal the solution. </p>
<h3>Task</h3>
<blockquote><p>&#8220;<b>Implement the following demo-mode for the JDT:</b></p>
<dl>
<dt>&bull; When creating a Java project let the user select:</dt>
<dd style="margin-left:35px;">&#10066; Project is for demo purpose only</dd>
<dt>&bull; When creating a class in a Demo project:</dt>
<dd style="margin-left:35px;">insert class name as “Foo1”, “Foo2” …&#8221;</dd>
</dl>
</blockquote>
<p>So creating classes in demo mode is much easier, and you&#8217;ll use the names &#8220;Foo1&#8243;&#8230; anyway <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
(See also our <a href="http://download.eclipse.org/objectteams/OTEclipseConTutorial/Slides.pdf">slides (#39)</a>).</p>
<p>Granted, this is a toy example, yet it combines a few properties that I frequently find in real life and which cause significant pains without OT/J:</p>
<ul>
<li>The added behavior must <strong>tightly integrate</strong> with existing behavior.</li>
<li>The added behavior affects code at <strong>distant locations</strong>,<br/>here two plug-ins are affected: <code>org.eclipse.jdt.ui</code> and <code>org.eclipse.jdt.core</code>.</li>
<li>The added behavior affects execution at <strong>different points in time</strong>,<br/>here creation of a project plus creation of a class inside a project.</li>
<li>The added behavior requires to maintain <strong>more state</strong> at existing objects,<br/>here a JavaProject must remember if it is a demo project.</li>
</ul>
<p>Despite these characteristics the task can be easily described in a few English sentences. So the solution should be similarly concise and delivered as a single coherent piece.</p>
<h3>Strategy</h3>
<p>With a little knowledge about the JDT the solution can be outlined as this</p>
<ul>
<li>Add a checkbox to the New Java Project wizard</li>
<li>When the wizard creates the project mark it as a demo project if the box is checked.</li>
<li>Let the project also count the names of <code>Foo.. </code> classes it has created.</li>
<li>When the new class wizard creates a class inside a demo project pre-set the generated class name and make the name field unselectable.</li>
</ul>
<p>From this we conclude the need to define 4 roles, playedBy these existing types:</p>
<ul>
<li><code>org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPageOne.NameGroup</code>:<br/> the wizard page section where the project name is entered and where we want to add the checkbox.</li>
<li><code>org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPageTwo</code>:<br/>the part of the wizard that triggers setup of the JavaProject.</li>
<li><code>org.eclipse.jdt.core.IJavaProject</code>:<br/>this is where we need to add more state (isDemoProject and numFooClasses).</li>
<li><code>org.eclipse.jdt.ui.wizards.NewTypeWizardPage</code>:<br/>this is where the user normally specifies the name for a new class to be created.</li>
</ul>
<p>Note, that 3 classes in this list resided in <code>org.eclipse.jdt.ui</code>, but IJavaProject is from <code>org.eclipse.jdt.core</code>, which leads us to the next step:</p>
<h3>Plug-in configuration</h3>
<p>Our solution is developed as an <a href="http://wiki.eclipse.org/Category:OTEquinox">OT/Equinox</a> plug-in, with the following architecture level connections:<br />
<a href='http://blog.objectteams.org/wp-uploads/2011/04/demohelperaspectbindings1.png'><img src="http://blog.objectteams.org/wp-uploads/2011/04/demohelperaspectbindings1.png" alt="" title="Aspect Bindings" class="alignnone size-full wp-image-96" /></a></p>
<p>This simply says that the same team <code>demohelper.ProjectAdaptor</code> is entitled to bind roles to classes from both <code>org.eclipse.jdt.ui</code> and <code>org.eclipse.jdt.core</code>.<br />
One more detail in these extensions shouldn&#8217;t go unmentioned: Don&#8217;t forget to set &#8220;activation: ALL_THREADS&#8221; for the team (otherwise you won&#8217;t see any effect &#8230;).</p>
<p>Now we&#8217;re ready to do the coding.</p>
<h3>Implementing the roles</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="otj" style="font-family:monospace;"><span style="color: #7F0055; font-weight: bold;">protected</span> <span style="color: #7F0055; font-weight: bold;">class</span> DialogExtender <span style="color: #7F0055; font-weight: bold;">playedBy</span> NameGroup <span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #7F0055; font-weight: bold;">protected</span> SelectionButtonDialogField isDemoField<span style="color: #000000;">;</span>
&nbsp;
	<span style="color: #7F0055; font-weight: bold;">void</span> createControl<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">Composite</span> parent<span style="color: #000000;">&#41;</span> <span style="color: #7F0055;font-weight:bold;">&lt;-</span> <span style="color: #7F0055; font-weight: bold;">after</span> <span style="color: #000000; font-weight: normal">Control</span> createControl<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">Composite</span> composite<span style="color: #000000;">&#41;</span>
		<span style="color: #7F0055; font-weight: bold;">with</span> <span style="color: #000000;">&#123;</span> parent <span style="color: #7F0055;font-weight:bold;">&lt;-</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">Composite</span><span style="color: #000000;">&#41;</span> <span style="color: #7F0055; font-weight: bold;">result</span> <span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #7F0055; font-weight: bold;">private</span> <span style="color: #7F0055; font-weight: bold;">void</span> createControl<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">Composite</span> parent<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		isDemoField<span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> SelectionButtonDialogField<span style="color: #000000;">&#40;</span>SWT.<span style="color: #000000;">CHECK</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		isDemoField.<span style="color: #000000;">setLabelText</span><span style="color: #000000;">&#40;</span><span style="color: #2A00ff;">&quot;Project is for demo purpose only&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		isDemoField.<span style="color: #000000;">setSelection</span><span style="color: #000000;">&#40;</span><span style="color: #7F0055; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		isDemoField.<span style="color: #000000;">doFillIntoGrid</span><span style="color: #000000;">&#40;</span>parent, <span style="color: #000000;">4</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Our first role adds the checkbox. The implementation of <code>createControl</code> is straight-forward UI business. Lines 22,23 hook our role method into the one from the bound base class <code>NameGroup</code>. After the <code style="color:#7F0055;font-weight:bold;">with</code> keyword, we are piping the result from the base method into the parameter <code>parent</code> of the role method (with a cast). This construct is a <a href="http://www.objectteams.org/def/1.3/s4.html#s4.4">parameter mapping</a>. </p>
<p>Here&#8217;s the result:<br />
<a href='http://blog.objectteams.org/wp-uploads/2011/04/demoprojectcheckbox.png'><img src="http://blog.objectteams.org/wp-uploads/2011/04/demoprojectcheckbox.png" alt="" title="New Check Box" class="alignnone size-full wp-image-98" /></a></p>
<p>Next we want to store the demo-flag to instances of <code>IJavaProject</code>, so we write this role:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>52
53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="otj" style="font-family:monospace;"><span style="color: #7F0055; font-weight: bold;">protected</span> <span style="color: #7F0055; font-weight: bold;">class</span> EnhancedJavaProject <span style="color: #7F0055; font-weight: bold;">playedBy</span> IJavaProject <span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #7F0055; font-weight: bold;">protected</span> <span style="color: #7F0055; font-weight: bold;">boolean</span> isDemoProject<span style="color: #000000;">;</span>
	<span style="color: #7F0055; font-weight: bold;">private</span> <span style="color: #7F0055; font-weight: bold;">int</span> numFooClasses <span style="color: #000000;">=</span> <span style="color: #000000;">1</span><span style="color: #000000;">;</span>
&nbsp;
	<span style="color: #7F0055; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: normal">String</span> getTypeName<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #7F0055; font-weight: bold;">return</span> <span style="color: #2A00ff;">&quot;Foo&quot;</span><span style="color: #000000;">+</span><span style="color: #000000;">&#40;</span>numFooClasses<span style="color: #000000;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>		
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Great, now any <code>IJavaProject</code> can play the role <code>EnhancedJavaProject</code> which holds the two additional fields, and we can automatically serve an arbitrary number of class names Foo1 &#8230;<br />
In the IDE you will actually see a warning, telling you that binding a role to a base <em>interface</em> currently imposes a few <a href="http://www.objectteams.org/def/1.3/s2.html#s2.1.1">restrictions</a>, but these don&#8217;t affect us in this example.</p>
<p>Next comes a typical question: how to transfer the flag from role <code>DialogExtender</code> to role <code>EnhancedJavaProject</code>?? The roles don&#8217;t know about each other nor do the bound base classes. The answer is: use a chain of references.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
</pre></td><td class="code"><pre class="otj" style="font-family:monospace;"><span style="color: #7F0055; font-weight: bold;">protected</span> <span style="color: #7F0055; font-weight: bold;">class</span> FirstPage <span style="color: #7F0055; font-weight: bold;">playedBy</span> NewJavaProjectWizardPageOne <span style="color: #000000;">&#123;</span>
&nbsp;
	DialogExtender getFNameGroup<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #7F0055;font-weight:bold;">-&gt;</span> <span style="color: #7F0055; font-weight: bold;">get</span> NameGroup fNameGroup<span style="color: #000000;">;</span>
&nbsp;
	<span style="color: #7F0055; font-weight: bold;">protected</span> <span style="color: #7F0055; font-weight: bold;">boolean</span> isDemoProject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #7F0055; font-weight: bold;">return</span> getFNameGroup<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">isDemoField</span>.<span style="color: #000000;">isSelected</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>		
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #7F0055; font-weight: bold;">protected</span> <span style="color: #7F0055; font-weight: bold;">class</span> WizardExtender <span style="color: #7F0055; font-weight: bold;">playedBy</span> NewJavaProjectWizardPageTwo <span style="color: #000000;">&#123;</span>
&nbsp;
	FirstPage getFFirstPage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #7F0055;font-weight:bold;">-&gt;</span> <span style="color: #7F0055; font-weight: bold;">get</span> NewJavaProjectWizardPageOne fFirstPage<span style="color: #000000;">;</span>
&nbsp;
	markDemoProject <span style="color: #7F0055;font-weight:bold;">&lt;-</span> <span style="color: #7F0055; font-weight: bold;">after</span> initializeBuildPath<span style="color: #000000;">;</span>
	<span style="color: #7F0055; font-weight: bold;">private</span> <span style="color: #7F0055; font-weight: bold;">void</span> markDemoProject<span style="color: #000000;">&#40;</span>EnhancedJavaProject javaProject<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #7F0055; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>getFFirstPage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">isDemoProject</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
			javaProject.<span style="color: #000000;">isDemoProject</span> <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">true</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Role <code>WizardExtender</code> intercepts the event when the wizard initializes the <code>IJavaProject</code> (line 46). Method <code>initializedBuildPath</code> receives a parameter of type <code>IJavaProject</code> but the OT/J runtime transparently translates this into an instance of type <code>EnhancedJavaProject</code> (this - statically type safe - operation is called <a href="http://www.objectteams.org/def/1.3/s2.html#s2.3">lifting</a>). Another indirection is needed to access the checkbox: The base objects are linked like this:</p>
<div style="margin:7px;">NewJavaProjectWizardPageTwo &mdash;fFirstPage&mdash;&gt; NewJavaProjectWizardPageOne &mdash;fNameGroup&mdash;&gt; NameGroup</div>
<p>This link structure is lifted to the role level by the <a href="http://www.objectteams.org/def/1.3/s3.html">callout bindings</a> in lines 35 and 44.</p>
<p>We&#8217;re ready for our last role:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>62
63
64
65
66
67
68
69
70
71
72
73
</pre></td><td class="code"><pre class="otj" style="font-family:monospace;"><span style="color: #7F0055; font-weight: bold;">protected</span> <span style="color: #7F0055; font-weight: bold;">class</span> NewTypeExtender <span style="color: #7F0055; font-weight: bold;">playedBy</span> NewTypeWizardPage <span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #7F0055; font-weight: bold;">void</span> setTypeName<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">String</span> name, <span style="color: #7F0055; font-weight: bold;">boolean</span> canBeModified<span style="color: #000000;">&#41;</span> <span style="color: #7F0055;font-weight:bold;">-&gt;</span> <span style="color: #7F0055; font-weight: bold;">void</span> setTypeName<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">String</span> name, <span style="color: #7F0055; font-weight: bold;">boolean</span> canBeModified<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
	<span style="color: #7F0055; font-weight: bold;">void</span> initTypePage<span style="color: #000000;">&#40;</span>EnhancedJavaProject prj<span style="color: #000000;">&#41;</span> <span style="color: #7F0055;font-weight:bold;">&lt;-</span> <span style="color: #7F0055; font-weight: bold;">after</span> <span style="color: #7F0055; font-weight: bold;">void</span> initTypePage<span style="color: #000000;">&#40;</span>IJavaElement element<span style="color: #000000;">&#41;</span>
		<span style="color: #7F0055; font-weight: bold;">with</span> <span style="color: #000000;">&#123;</span> prj <span style="color: #7F0055;font-weight:bold;">&lt;-</span> element.<span style="color: #000000;">getJavaProject</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #7F0055; font-weight: bold;">private</span> <span style="color: #7F0055; font-weight: bold;">void</span> initTypePage<span style="color: #000000;">&#40;</span>EnhancedJavaProject prj<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #7F0055; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>prj.<span style="color: #000000;">isDemoProject</span><span style="color: #000000;">&#41;</span>
			setTypeName<span style="color: #000000;">&#40;</span>prj.<span style="color: #000000;">getTypeName</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #7F0055; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Here we intercept the initialization of the type page of a New Java Project wizard (lines 66,67). Another parameter mapping is used to perform two adjustments in one go: fetch the <code>IJavaProject</code> from the enclosing <code>element</code> and <em>lift</em> it to its <code>EnhancedJavaProject</code> role. This follows the rule-of-thumb that base-type operations (like navigating from <code>IJavaElement</code> to <code>IJavaProject</code>) should happen at the right hand side, so that we are ready to lift the <code>IJavaProject</code> to <code>EnhancedJavaProject</code> when the data flow enters the team.</p>
<p>The <code>EnhancedJavaProject</code> can now be asked for its stored flag (<code>isDemoProject</code>) and it can be asked for a generated class name (<code>getTypeName()</code>). The generated class name is then inserted into the dialog using the callout binding in line 64. Looks like this:<br />
<a href='http://blog.objectteams.org/wp-uploads/2011/04/demoprojectcreatefoo1.png'><img src="http://blog.objectteams.org/wp-uploads/2011/04/demoprojectcreatefoo1.png" alt="" title="Creating a Foo class" class="alignnone size-full wp-image-99" /></a><br />
See this? No need to think of a good class name <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Wrap-up</h3>
<p>So that&#8217;s it. All these roles are collected in one team class and here is the fully expanded outline:<br />
<a href='http://blog.objectteams.org/wp-uploads/2011/04/projectadaptoroutline.png'><img src="http://blog.objectteams.org/wp-uploads/2011/04/projectadaptoroutline.png" alt="" title="Outline" class="alignnone size-full wp-image-100" /></a></p>
<p>All this is indeed one concise and coherent module. In the tutorial I promised to do this no more than 80 LOC, and indeed the team class has 74 lines including imports and white space.</p>
<p>Or, if you are interested just in how this module connects to the existing implementation, you may use the &#8220;binding editor&#8221; in which you see all playedBy, callout and callin bindings:<br />
<a href='http://blog.objectteams.org/wp-uploads/2011/04/projectadaptorconnector.png'><img src="http://blog.objectteams.org/wp-uploads/2011/04/projectadaptorconnector.png" alt="" title="Bindings" class="alignnone size-full wp-image-101" /></a></p>
<p>The full sources are also available for <a href="http://www.objectteams.org/examples/demohelper.zip">download</a>.</p>
<p>have fun</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2011/04/follow-up-object-teams-tutorial-at-eclipsecon-2011/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

