tag:blogger.com,1999:blog-242482062024-02-19T16:33:02.684+01:00sven efftinge's blogAnonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comBlogger156125tag:blogger.com,1999:blog-24248206.post-3492832113020789272016-02-10T12:14:00.000+01:002016-11-30T09:04:39.556+01:00TypeFoxAs many of you already noticed, we had to find a company name without 'Xtext' in it. Longer story short, we finally decided for <b>TypeFox </b>(it still has an 'x', ey? ;-)). We are still all about Xtext and Xtend, of course.<br />
<br />
The <a href="http://typefox.io/" target="_blank">website</a> is online now and reveals some additional details about what we do. Also we are having a blog there, which will be updated with useful content around Xtext and Xtend and more general about language engineering, code generators and so on on a regular basis. If you want to get notified about the content, there is a monthly newsletter. It will contain information about the latest blog post, upcoming Xtext and Xtend releases and upcoming events. The sign-up form is on the <a href="http://typefox.io/blog" target="_blank">blog</a> page.<br />
<br />
Also <a href="http://koehnlein.blogspot.de/2016/02/founding-typefox.html" target="_blank">Jan</a> joined this month as a co-founder and there will be five more friends (Xtext committers) joining TypeFox in the coming weeks.<br />
<br />
Finally I wanted to say <b>thank you</b>, for all the good wishes and the trust of our partners who already do business with us. It starts all very well and I am very thankful for that.<br />
<br />
How do you like our logo?<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLucetH81f1q8IS3K9-JeoSzdMLMojyAzea9g-QJYnCk-aii84F0-Y8sAYhC9yvMOAssAVtK9WEynUG6d6O7LAsHuNDFVx6hnvnlvBvbyTWm7Mj5p30Kz_QGtaEcrAtC7bmUs5VQ/s1600/1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="247" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLucetH81f1q8IS3K9-JeoSzdMLMojyAzea9g-QJYnCk-aii84F0-Y8sAYhC9yvMOAssAVtK9WEynUG6d6O7LAsHuNDFVx6hnvnlvBvbyTWm7Mj5p30Kz_QGtaEcrAtC7bmUs5VQ/s320/1.jpg" width="320" /></a></div>
<br />
<div>
<br /></div>
<br />
<br />Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-68879855090896116832016-01-05T09:41:00.003+01:002016-01-05T14:29:54.787+01:00Founding An Xtext StartupFirst of all, I wish all of you a Happy New Year! In addition I'd like to update you about some decisions I made recently.<br />
<br />
Since January 1st I no longer work with itemis. Instead I am founding a startup together with my friends from the Xtext team. The new company will be all about <i><b>Xtext</b></i>, and as such 100% dedicated to language engineering and tool development.<br />
<br />
We want to make sure to run a healthy and sustainable open-source business. The huge success of Xtext in the past few years has shown that there is a significant market for special tool and language development and that this is even growing. We really enjoy working with so many different customers around the world and it always is a pleasure to see them getting excited about the power of Xtext. Just in case it is not clear, <b>we will for sure invest significantly into the further development of the open-source framework</b>.<br />
<br />
We start by offering the classical support packages, trainings, and general consulting. That is everything you need to make sure you get the best possible results with Xtext. In future we might have some ideas for additional services and products as well. The new website will be up in a couple of days and will contain more detailed information. Stay tuned!<br />
<br />
If you have questions, just want to chat, or want to work with us - this is my private email:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmXlFmhhDV7YIQQ1DrorlZhdseAzR-sgNNYU5gFpi6t-QaklbEOIUlGEHodnykQ_QVAoSae6kzyydbGhouB5xRKLLtaobweX5slBWleYqXit9jbQPv5w58df_3SsxdCLIClwgYqg/s1600/Screen+Shot+2016-01-05+at+14.01.42.png" imageanchor="1"><img border="0" height="88" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmXlFmhhDV7YIQQ1DrorlZhdseAzR-sgNNYU5gFpi6t-QaklbEOIUlGEHodnykQ_QVAoSae6kzyydbGhouB5xRKLLtaobweX5slBWleYqXit9jbQPv5w58df_3SsxdCLIClwgYqg/s320/Screen+Shot+2016-01-05+at+14.01.42.png" width="320" /></a></div>
<br />
Edit: We really would like to use something with Xtext in the name (like XtextSource), but this unfortunately conflicts with the guidelines at Eclipse.org. This may come to you as a surprise, as there are companies like EclipseSource, but this is a special case as they were founded before 2005. We will come up with another good name soon. :)Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-91297972566656525152015-10-13T22:23:00.001+01:002015-11-10T17:14:34.757+01:00Xtend: Active Annotation Processing in IntelliJ IDEAThis is a short screencast showing the use of <b>@Accessors</b>, <b>@EqualsHashCode</b> and <b>@Data</b> within IntelliJ IDEA 15.
<br/><br/>
See how getters, setters and other boiler plate gets eliminated in <a href="http://xtend-lang.org">Xtend</a>.
<br/><br/>
<b>Note, that unlike case classes in Scala or data in Kotlin, in Xtend <a href="https://www.eclipse.org/xtend/documentation/204_activeannotations.html">these annotations are just library</a>. You can easily build your own!</b>
<br/><br/>
<iframe src="https://player.vimeo.com/video/142307257" width="500" height="375" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-5662955438971703492015-10-02T19:41:00.000+01:002015-10-02T19:44:05.437+01:00Xtext for IntelliJ IDEA - PreviewToday we've released a preview version for the upcoming IntelliJ IDEA support of <a href="https://www.eclipse.org/Xtext">Xtext</a>. With this it is now possible to <b>develop Xtext languages entirely in IDEA</b> and due to the cool Gradle support in any other environment, too.
<br/><br/>
The preview plugins for IntelliJ IDEA can be installed from the following repository location:
<br/><br/>
<a href="http://download.eclipse.org/modeling/tmf/xtext/idea/2.9.0.beta5/updatePlugins.xml">http://download.eclipse.org/modeling/tmf/xtext/idea/2.9.0.beta5/updatePlugins.xml</a>
<br/><br/>
Note that Xtext requires the latest <a href="https://www.jetbrains.com/idea/nextversion/">IDEA 15 Preview</a> build.
<br/><br/>
I've recorded a small screencast that shows what Xtext in IntellijJ IDEA looks like:
<iframe src="https://player.vimeo.com/video/141201249" width="500" height="375" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-78273713293493153912015-09-11T12:39:00.003+01:002015-09-11T12:41:32.213+01:00What I learned at JavaZone 2015This week I was lucky to go to Oslo to attend <a href="https://javazone.no/" target="_blank">JavaZone</a>, which is what they say "<i>the largest community-driven developer conference in the world</i>".<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://test.2014.javazone.no/assets/img/logos/javazone@2x-luft.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://test.2014.javazone.no/assets/img/logos/javazone@2x-luft.png" height="300" width="320" /></a></div>
No matter that's true or not it is for sure one of the coolest conferences I have ever been to. It is generally extremely well organized and on top of that they have some really cool features like:<br />
<br />
<ul>
<li> an overflow area, where you can watch all sessions on a split screen and switch audio using a headset!</li>
<li> different food stations, that open in the morning and serve delicious food all day!</li>
<li> recordings of all sessions, uploaded to vimeo and made available in a couple of hours!</li>
<li> ... many more cool things (e.g. I got a Raspberry Pi as a Sopeaker's present :-))</li>
</ul>
<br />
But that such a conference is all about the people and the content, which was equally great:<br />
<br />
<h2>
Wednesday</h2>
<br />
The first day I started with a talk about <a href="http://2015.javazone.no/details.html?talk=3b2c46f15ec292bfbed82adb2984ef17e2c47748768167f9060b263a74e37659" target="_blank">alternative implementations for collections</a>. The speaker maintains a library with something he called a gap list, that had some clever techniques to make positional insertion cheaper (compared to ArrayList). It made sense to me and the measurements looked good, although there's a last bit of sceptic on my side, as he did the measurements "on his own".<br />
<br />
The next session was the one about <a href="http://2015.javazone.no/details.html?talk=aa838a632866ef3f5a61c41cb72936ad793a9321bef2fd6c318b008b586a0e37" target="_blank">Neo4J by Michael Hunger</a>. I already knew Neo4J a bit as did some examples using Xtend some time ago, but it was still very interesting. He showed a cool demo, where he imported data from twitter, github and stackoverflow and joined it together in the database. Also I didn't know the cool web frontend he used, that lets you enter some Cipher code (the Neo4J query language) and shows the results as dynamic diagrams. Cipher btw. is implemented using Scala's parboiled. They really should consider reimplementing it with Xtext, so they get proper editors for free ;-)<br />
<br />
Next up was <a href="http://2015.javazone.no/details.html?talk=bbf8706a9a82ae8d986f44e7a80597b748f1456abd1e618d2a56691043b1eb46" target="_blank">Rafael Winterhalter, talking about his open-source library "Byte Buddy"</a>. <a href="http://bytebuddy.net/#/" target="_blank">Byte Buddy</a> is a bytecode library, that comes with builder APIs and some hooks for agents to make it easier to do byte code generation at runtime. The talk was well presented and very interesting. I especially liked the style of his slides, which were very reduced and calm (I'm kind of sick of stockimage-heavy slide decks - I know I use them myself too much :-))<br />
<br />
The fourth talk was <a href="http://2015.javazone.no/details.html?talk=7e0cbcd0e5c7e63c21fd3b90188b6ea8879870a601282b3cc47a3360ab66617d" target="_blank">"How to make your code sustainable"</a> by Christin Gorman. The room was very crowded and it seems like most people enjoyed that talk very much, as she was very enthusiastic. For me it was a bit too superficial and the enthusiasm was tiring me at some point. (nitpicking on)Also there were strange code examples that just wouldn't compile (nitpicking off).<br />
<br />
<a href="http://2015.javazone.no/details.html?talk=66b7ea199bfbda4a3aedd2f3f9746d447ffed7f30d53d7cb0d65fdcd8b8141eb" target="_blank">"The Rule of Three"</a> with Kevlin Henney came next. I went to the room, and of course it was overflown. It's Kevlin Henney after all. So I got to try the overflow area for the first time, and it worked flawlessly (as everything else at this conference). The talk was cool, it's always a pleasure listening to him, although he was doing jokes on IDEs :-). I didn't learn many new things (maybe some quotes I have forgotten about now already) but it was super entertaining.<br />
<br />
Next up it was my turn to give an introduction to <a href="http://xtext.org/" target="_blank">Xtext</a>. The talk went well I think, there were at least some very excited attendees approaching me after the session. As always most of the talk is a demo. It has been recorded and you can <a href="https://vimeo.com/album/3556815/video/138873446" target="_blank">watch it here</a> (find all the other talks in the same album).<br />
<br />
After that talk I went to the hotel to watch the silly Apple Event (what a waste of time!) and were too tired to get up and go back to the #AweZone party. Oh my, I'm getting old!<br />
<br />
On the bright side, I was able to get some work done in the evening and wouldn't have a hangover on ...<br />
<br />
<h2>
Thursday</h2>
<br />
I took the time to get in touch with some people and also get more work done. Also I found some cozy places on the conference site and enjoyed the great coffee, food, and ice cream along with some coding.<br />
<br />
The only talk I attended was Neal Ford's take on "<a href="http://2015.javazone.no/details.html?talk=61cae85a4fe2cfceef4e3ee0ab2c2a0b3a07c6fbed10f56b44d7ef93cd157e6f" target="_blank">Microservices</a>". As you might know microservices are the thing, these days and there were very many talks on this topic at JavaZone. I was reading up on microservices from time to time in the past months to understand what that hype is all about and I was still somehow skeptical. But Neil managed to explain the benfits so that I finally understood how, why and when such an architecture might be helpful. At the same time I also figured how much stupid stuff you can read about this topic on the internet. But maybe that's the case with every heavily hyped topic.<br />
<br />
After that talk it was time for me to get to the airport and catch my plane to Hamburg. Everything went well and I was already sitting in front of the gate, when Germanwings sent me a note that my flight got canceled (40 mins before boarding). As I knew I couldn't do anything about it I rebooked for the next flight Friday 12:15 and booked a hotel room.<br />
<br />
<h2>
Friday</h2>
<br />
Breakfast, some work, and then to the airport. On my way I wanted to check the boarding time once more: 20:15. Huh? WTF! They silently canceled that second flight, too, and rebooked my for an even later flight! Fun times.<br />
<br />
So now I'm sitting here in front of Oslo Airport writing this and wait for the next possible flight to go out tonight. I hope they won't cancel it again.<br />
<br />
<h2>
Summary</h2>
<br />
JavaZone was a blast. Thanks for having me I hope I can come back next year.<br />
Also: Germanwings I hate you!Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-63153448577380380482015-05-28T14:18:00.002+01:002015-05-28T14:20:14.612+01:00The Future of Xtext<p>this is a write up of a presentation I gave together with Sebastian last week at XtextCON. It is about our future plans of Xtext. But before we talk about the future I would like to start with a quick summary of ...</p>
<h2>The Status Quo</h2>
<p>Xtext is in development for seven years now. We have always been between 6 and 10 active developers, currently being 9. With a total <b>LOC of 5.747.523</b> our code base is huge. However you have to take into account that we not only check in generated code (it sometimes helps us to spot problems) but have many, many tests. All in all there is <b>27.539 usages of @Test</b> which are executed in many different scenarios and against different platforms. All together we count <b>over 180k unit tests</b>.</p>
<p>This kind of test coverage together with a passion for code quality is key keep a software system maintainable and extensible after years.</p>
<h2>Xtext 2.8.x</h2>
<p>In the coming week we will release 2.8.3, a bugfix version of the 2.8.x stream that <a href="https://www.eclipse.org/Xtext/releasenotes.html">introduced many cool new features</a>. With version 2.8.3 we have fixed over 120 bugs and improved quality furthermore. This is also the release that will be part of Eclipse Mars.</p>
<b>Error Reporting</b>
<p>Not sure if you have noticed, but with Mars also comes the new error reporting tool, an initiative by the developers behind Eclipse Code Recommenders. It basically asks you to automatically send in error reports for all kinds of exceptions and UI freezes you experience when working with Eclipse. Although it is not yet included in the Luna SR2 packages we already got many helpful tickets through that feature from the milestone builds. <b>Please, turn this feature on and provide as much information as possible. It really helps!</b></p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC17Hi0BjYL6j0rUW7GC2lFdlWAeTVpdrPZZo0NpRcZuUP46eEgr872yVZYh-vtw9LMPQgfeZPgJX9EkXV7F0M8oTtH7djobjyGpP2CNDcy7PLxoCSRVURuq8oct-m2Nf7R0KLnA/s1600/Screen+Shot+2015-05-28+at+14.44.21.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC17Hi0BjYL6j0rUW7GC2lFdlWAeTVpdrPZZo0NpRcZuUP46eEgr872yVZYh-vtw9LMPQgfeZPgJX9EkXV7F0M8oTtH7djobjyGpP2CNDcy7PLxoCSRVURuq8oct-m2Nf7R0KLnA/s320/Screen+Shot+2015-05-28+at+14.44.21.png" /></a></div>
<h2>What about future releases?</h2>
<p>To figure our what the community demands, we did a survey. Thanks for everyone who attended! The survey was targeted at Xtext users, and besides some more demographic questions, the most important question was:
<h2>"What should be changed or improved?"</h2>
<p>The answers included a lot of valuable feedback. Most of them could be assigned to one of the following four themes.
I put some of the original answers and comments from the survey on the slides.</p>
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUxbGoJHduFTLz9Pn6Xiskkd-rQ8dr86kL8qkK3KJBEJeASF6ZnNvfhlgL-4ppiSL_Bbn3Iojg0AawIbLbojBkrN3roIGyBpdvEuMDYBOuSOGkdT9f2Ib7F-QimhRA-zsep5KOOg/s400/Screen+Shot+2015-05-28+at+14.44.29.png" />
<p>People asked for more documentation, specifically around Xbase and in the code (i.e. JavaDoc). Also many asked for an overview chapter where a bird's eye view of the architecture and life cycles is explained. We agree that these parts should be added and enhanced and have put it on our agenda. Fortunately the documentation is <a href="http://blog.efftinge.de/2015/03/xtext-moved-to-github.html">now written in markdown</a> and change is only one pull-request away (for everyone ;-)).</p>
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLa-oVclxNdtno5eF4YuTh3obyE1PHhpVKxwXPlA-rwaU_NyKFl3WsIAVir8kg96gASO9JI5FNyccg9gVIrtvbBDmE8bdIWDWGKTyTqQL6LRN5SlnEzC1ZmIaCO7XFCHgZYejnsA/s400/Screen+Shot+2015-05-28+at+14.44.37.png" />
<p>Performance has always been high on our list and for every release we spend a lot of time on profiling and optimization. If you suffer from performance problems, first make sure, that you are on the latest version. Performance makes huge steps from release to release.</p>
<p>Here is some of the improvements we have been working on lately:</p>
<ul>
<li><b>Do nothing in UI thread</b> - computations of any UI services have been moved to background jobs, such that nothing blocks the user.
<li><b>Cancel everything</b> - all UI services, such as outline, mark occurences, semantic highlighting, etc. get canceled on change (i.e. as you type). Since the state is outdated we can stop waste CPU cycles on it.
<li><b>Cancelable builds</b> - also incremental builds now get automatically canceled, when another change comes in.
<li><b>Storaged Resources</b> - Xtext can write fully resolved and computed resources to disk in a binary format, so it can later be loaded again quickly
<li><b>Incremental standalone compilation (new in 2.9)</b> - The eclipse builder has always been incremental. Now Xtext also has an incremental standalone compiler, that together with a running demon ensures super slick incremental compilation of changed files.
</ul>
<p>Of course, improving performance is never done!</p>
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj59ut10wxM9Rhti6k0oII3DEyAsOFZxTlhQ9IrasW7GpMnS8CR391o9yOIDRI24fSdXQg_MVi8MHNc8h2EyrlQ46WQoGz82pswxbyFMC2Pl9epJC1Mdyg70ydXDOiUfvG-_DsUQw/s400/Screen+Shot+2015-05-28+at+14.44.50.png" />
<p>Continuous integration with Xtext and Xtext-based languages has traditionally been a bit of a pain. This is mostly because we started out as an Eclipse only project, and building Eclipse plug-ins is "different". The Xtext project has had a continuous integration build for years, but our build infrastructure is not exactly simple. Targeting different platforms requires a bit of a zoo of build technologies on our side, which should not be necessary for clients. Since almost two years now, there is Maven support, including a plug-in to run your language in an arbitrary maven build. The same has been added for Gradle as well.</p>
<p>The next step is to allow for different project layouts, i.e. Eclipse vs. Maven/Gradle layout and allow for developing Xtext languages without any kind of Eclipse dependency. Which brings us to the last theme.</p>
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPItD3TwF0QS6hKJoaw0k0yEGDnD1D9m5MdCs8b9q1CJTHMMI6uYnA9sLTdcDEduKqhytN4CaI5LIDgpgETnN9iOaUqA5jIizz0IhlWogS4GuiNvCRGsw4qxKIxwnaGHIHcdSl-g/s400/Screen+Shot+2015-05-28+at+14.44.59.png" />
<p>Xtext is a language framework that has significantly lowered the barrier to develop programming languages and external domain-specific languages. One of the sweet things is the cool Eclipse support you get. However even if you only need a compiler for a language without any Eclipse tooling the Xtext framework provides you with rich abstractions for scoping, indexing, incremental compilation and more. With the next release (version 2.9) it should be possible to create a runtime project only, without any Eclipse dependencies and without the necessity to deal with OSGi or eclipse plug-in mechanism. Our goal is to allow for vanilla Java projects with a normal Gradle or Maven build.</p>
<p>For the IDE part, we are working on supporting <a href="http://spoenemann.blogspot.de/2015/05/editing-dsls-in-web-browser.html">web editors</a> and <a href="https://oehme.github.io/2015/05/22/xtext-intellij-beta.html">IntelliJ IDEA</a> specifically at the moment. But maybe even more important in the long run, is the general extraction of the IDE services from Eclipse dependencies, such that they can be reused on other platforms easily. Tom Schindl for instance already uses <a href="http://tomsondev.bestsolution.at/2015/05/20/code-editors-in-general-with-javafx/">Xtext in JavaFX applications</a> and we are in contact with a group that has ported Xtext to Visual Studio through IKVM.</p>
<p><b>Just to be clear: The Eclipse support stays important and will be a first class citizen for the Xtext framework in the future, too!</b></p>
<h2>Summary</h2>
<p>As you can see, the direction is a mixture of improving quality and performance, making accessibility easier but also reaching out to new platforms. I hope you find this direction as exciting as we do. We plan to release <b>Xtext 2.9 in the last quarter of 2015</b>. In case you want to try the current state of the web or intelliJ IDEA support, go ahead and <a href="https://www.eclipse.org/Xtext/news.html">download the recently released beta version</a>. More betas will be released in the coming weeks / months.<br/>
So long, have fun and remember your feedback is helpful and very welcome!</p>
<script async class="speakerdeck-embed" data-slide="2" data-id="d866500b7d344e99b80a26727c513a8c" data-ratio="1.33333333333333" src="//speakerdeck.com/assets/embed.js"></script>
Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-11011261939999000662015-03-16T10:14:00.001+01:002015-03-16T10:14:11.698+01:00Xtext moved to GithubI'm just back from EclipseCon and XtextDay in San Francisco, where we announced the new <a href="https://www.eclipse.org/Xtext/download.html" target="_blank">2.8.0 release</a> of Xtext and Xtend among <a href="http://survey.xtext.org/" target="_blank">some</a> <a href="http://xtextcon.org/" target="_blank">other</a> <a href="http://www.slideshare.net/sefftinge/future-of-xtext/24" target="_blank">interesting</a> developments. One of those is our...<br />
<h3>
Move to Github</h3>
In order to simplify the contributor's story, Xtext is taking part in the "<a href="https://mmilinkov.wordpress.com/2013/06/20/embracing-social-coding-at-eclipse/" target="_blank">social coding initiative</a>" of the eclipse foundation, and the primary git repository has been moved over to github. As a consequence we will no longer use gerrit for code reviews but github pull requests. Also it now makes more sense to fork, watch and star <a href="https://github.com/eclipse/xtext" target="_blank">our repository</a>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEik2sVAfWWXKU82fKMIWqTYVDnnU_fCbXqLne7JKTVOWM0eCkhbMGOIlF7MpjlJYvq-4UxYO5jYmAB9ZTNCUuXA6U6rw8BOLM8R6HRWubAFegPjqKunWqXSwfJ9mr0xw_7OgPJnOA/s1600/Screen+Shot+2015-03-16+at+04.40.04.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEik2sVAfWWXKU82fKMIWqTYVDnnU_fCbXqLne7JKTVOWM0eCkhbMGOIlF7MpjlJYvq-4UxYO5jYmAB9ZTNCUuXA6U6rw8BOLM8R6HRWubAFegPjqKunWqXSwfJ9mr0xw_7OgPJnOA/s1600/Screen+Shot+2015-03-16+at+04.40.04.png" height="202" width="640" /></a></div>
<br />
<br />
Xtext is of course still an Eclipse project!<br />
<br />
<h3>
Changing documentation in two clicks</h3>
The website has been reimplemented in <a href="http://jekyllrb.com/" target="_blank">jekyll</a> and the entire documentation is now written in github-flavored markdown. A link on every page that says '<b>edit on github</b>' will open up a markdown editor on github, where anybody can do changes and propose them in form of a pull-request with a second click. This allows for wiki-style turnarounds but with a review and CLA check in it.<br />
Just go try it out :-)<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFyKOrKMX6lPs2sxyN2HNeP7gBAeSd37NqjTiGfWGc3_BnONuRyZDE1MSmeI8HQExUlH8Xcp_-cYrQY0odqmvxLNJOrkWkbMEV4xBy-yLgrs9QptXQpqgbuxuS0p9OlgVCdpZXcg/s1600/contribute-documentation.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFyKOrKMX6lPs2sxyN2HNeP7gBAeSd37NqjTiGfWGc3_BnONuRyZDE1MSmeI8HQExUlH8Xcp_-cYrQY0odqmvxLNJOrkWkbMEV4xBy-yLgrs9QptXQpqgbuxuS0p9OlgVCdpZXcg/s1600/contribute-documentation.jpg" height="320" width="640" /></a></div>
<h3>
Automated setup</h3>
While documentation and website improvements can be made in the browser, you usually want to run some of our over 30.000 unit tests when you did code changes, or be able to compile and debug code. With a big project like Xtext that targets multiple platforms, the setup of a workspace and the corresponding tools is unfortunately not exactly simple. But fear not, this is all automated, thanks to an oomph setup. So even here it is only a couple of clicks until you have a fully working setup, that includes an IDE, the workspace, correct target platform, the team's workspace preferences and so on. Just everything you need and everything like we committer have it.<br />
<br />
<h3>
Code contributions</h3>
The team has many active committers that are very happy to review your high-quality pull-requests. If you want to start working on something it would be best if you pick up one of the <a href="https://bugs.eclipse.org/bugs/buglist.cgi?bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&f0=OP&f1=OP&f3=CP&f4=CP&j1=OR&list_id=11307568&query_format=advanced&status_whiteboard=v2.9&status_whiteboard_type=allwordssubstr" target="_blank">bugzillas flagged with 'v2.9'</a> or whatever the upcoming release is in case you read this post at a later point in time. This is how we schedule the things we agreed on working on.Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-3199776023424346372015-01-29T15:14:00.001+01:002015-01-29T15:14:57.319+01:00Auto-GWT - Boilerplate Free GWT Programming<p>Maybe not especially new for everybody, but: <b>GWT is NOT dead! </b></p>
<p>
I've been at the GWT.create conference yesterday, a two-day conference on GWT only that took place in San Jose last week and this week in Munich. With over 400 attendees it was sold out. If that is not enough evidence of the liveliness of the project, you may have missed that Google runs huge projects on GWT. The latest one is Google Inbox. Add all the nice improvements (like increased compile speed) the latest releases have to offer and you will conclude that GWT is the best way to write browser apps in Java or any JVM language. The generated JavaScript code is highly optimized and runs even much faster than typical hand-written JavaScript code.</p>
<p>
I had the pleasure to present the new Auto-GWT library we have built for GWT together with my colleague <a href="https://twitter.com/akosyakov">Anton</a>. Thanks to all the attendees for the great questions and the overwhelmingly positive feedback. As a kind of wrap up after the conference I have uploaded the slides, the demo and the Auto-GWT project.</p>
<p>You can find all necessary information on the project's website : <b><a href="http://www.auto-gwt.org">auto-gwt.org</a></b><br/> Forks and pull requests are very welcome!</p>
<p>Auto-GWT in action:</p>
<iframe src="//player.vimeo.com/video/118124940" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<p>Slides from GWT.create:</p>
<iframe src="//www.slideshare.net/slideshow/embed_code/44027952" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC; border-width:1px; margin-bottom:5px; max-width: 100%;" allowfullscreen> </iframe>Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-50027598199069665702015-01-23T12:56:00.000+01:002015-01-23T13:01:18.276+01:00XtextDay and EclipseCon San Francisco 2015<p>
In case you've missed it, we are organizing a so called <a href="www.xtextday.org">XtextDay</a> co-located with EclipseCon 2015. The program is already online for a couple of weeks:
</p>
<p>
Sebastian and I will start the day talking about the newest developments (e.g. Intellij IDEA support, web editor support, incremental standalone builders, etc.). After that we will hear how Xtext languages are used to design REST APIs. In the afternoon we have in-depth sessions on Xbase, performance and scoping, and after the coffee break we will learn how a silicon valley company use Xtext to build a commercial product for designing systems on a chip (IoT). The full program details can be found <a href="http://xtextday.org/#program">here</a>. But that's not all..
</p>
<h3>Additional Xtext content at EclipseCon</h3>
<p>Although it's possible to register only for the XtextDay, I recommend to book the whole EclipseCon conference as it is not only an awesome community event where you will find many new friends, but in addition to the XtextDay, there is some Xtext-related content there as well. It starts with <a href="https://www.eclipsecon.org/na2015/session/xtext-beginners">a beginner's tutorial</a> on Monday, which is a good preparation for the technically deeper talks following. In addition to the XtextDay and the tutorial we have:
<ul>
<li><a href="https://www.eclipsecon.org/na2015/session/building-ide-apache-cassandra-eclipse-rcp-e4-and-xtext">Building an IDE for Apache Cassandra with Eclipse RCP, e4 and Xtext</a> by Michael Figuiere of DataStax. Datastax is the company behind the Cassandra database, and he's going to talk about the product they've built with Xtext.
<li><a href="https://www.eclipsecon.org/na2015/session/diagrams-xtext-and-ux">Diagrams, Xtext and UX</a> by Jan Koehnlein. Jan is an Xtext committer and he will show a lightweight opeen-source diagram viewer framework based on JavaFX.
<li><a href="https://www.eclipsecon.org/na2015/session/generating-business-applications-executable-models-using-xtend-and-eclipse-uml2">Generating Business Applications from Executable Models Using Xtend and Eclipse UML2</a> by Raphael Chaves. Not strictly Xtext related, but a talk about a code generator built with <a href="www.xtend-lang.org">Xtend</a>.
<li><a href="https://www.eclipsecon.org/na2015/session/model-your-business-processes-youre-2015">Model Your Business Like You're In 2015</a> by Adrian Mos. Shows a domain-specific approach to business process modelling using lots of Eclipse technologies, including Xtext.
<li><a href="https://www.eclipsecon.org/na2015/session/sirius-xtext-♥">Sirius + Xtext = ♥</a> by Maxime Porhel. As the title already suggests, this talks is about integrating the graphical modelling technology Sirius with Xtext.
<li><a href="https://www.eclipsecon.org/na2015/session/system-testing-scientific-software">System testing scientific software</a> by Torkild U. Resheim. In this presentation Torkild will show how they used Xtext at the Norwegian Marine Research Institue (MARINTEK) to describe tests for marine operation simulations.
<li><a href="https://www.eclipsecon.org/na2015/session/making-xrobots">The Making of XRobots</a> by Jan Koehnlein and Miro Spoenemann. Jan and Miro (who is btw. a new committer to Xtext) are going to show how our XRobots game was built. You will see it's a really nerdy mash-up of strange technologies :-). <b>Of course we will have the <a href="https://www.youtube.com/watch?v=BkZKTHNsaYs">XRobots</a> at our booth for the whole conference, let's see who will come up with the winner robot this time!</b>
</ul>
<p>So quite some content in addition to XtextDay. If you consider using Xtext for something or you are already using it, then you should definitely come and join the sessions, discussions and party! :-)</p>
<div class="separator" style="clear: both; text-align: center;"><a href="http://www.xtextday.org" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg783TDVBb3eGFkP8JfGRAEQ1odzVttZY-vxP6qx36aTPn8t5Oatoh4WzybalHmnXMoshoJ4xJip3izbaV_wVyPMJaqjRzaf-kmEUDiaz4gZTM2mMvC4Q_htDmjqrRRf9AZp2nOmw/s640/Screen+Shot+2014-11-14+at+08.19.20.png" /></a></div>Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-91662833843468939142014-10-09T08:53:00.001+01:002014-10-09T08:53:33.139+01:00Eclipse Xtext goes IntelliJ IDEA<p>The <a href="http://www.eclipse.org/Xtext">Xtext framework</a> has been in development for six years now. With a team size between five and nine people (we are now at nine) plus many contributors working on it, it has become a successful framework for development of domain specific languages and programming languages in general. From parsers, linkers and compilers to interpreters, type-checkers and full IDE-support, the framework covers everything a grown up language infrastructure needs. So far however, the IDE part has been Eclipse-only. This will change now.
</p><p>
The Eclipse based IDE support of Xtext is very mature. We will further improve robustness and performance and might add one or the other feature in the future, but the Eclipse-support really has come to a state where not much is missing. Personally I like Eclipse as a code base as well as a tool, but the reduced activity in the platform itself has resulted in a noticeable decline of excitement and we see more and more devs preferring IntelliJ IDEA for their Java development. Also there are many shops where the IDE is not set, so developers can choose. Those teams with mixed IDEs suffer from lacking DSL tool support for their non-Eclipse IDEs, of course.
</p><p>
Long story short, this summer we started working on support for IntelliJ IDEA. It shall work without requiring duplicate implementation for the main aspects. So as an Xtext user you can still work against the core Xtext APIs and any existing Xtext language is going to work in IDEA without further ado. A thin layer translates the information to IntelliJ’s concepts (PSI, etc.). Of course everything is composed with dependency injection, such that IntelliJ-specific optimisations and customisations are still possible. The work is coming along nicely and we hope that a first public beta version can be released early next year. Of course this includes IntelliJ IDEA support for <a href="http://www.eclipse.org/xtend">Xtend</a> as well!
</p><p>
Here’s a short screencast showing a bit what’s already working.
</p>
<iframe src="//player.vimeo.com/video/108446109" width="500" height="326" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p><a href="http://vimeo.com/108446109">Xtext on IntelliJ IDEA</a> from <a href="http://vimeo.com/user2817486">Xtext Team</a> on <a href="https://vimeo.com">Vimeo</a>.</p>
<h3>More platforms to come</h3>
<p>
Although the current focus is IntelliJ (and Eclipse of course) we think in the long term it is important for the Xtext framework to support other platforms as well. Next up will be serious support for web browsers, which is especially interesting for the many DSLs targeting non-developers (i.e. “business DSLs”).</p>Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-29140913300590403962014-04-15T20:12:00.000+01:002014-04-15T20:14:12.000+01:00XtextCON UpdateXtextCON 2014 is still 40 days away, but I have to announce that ...<br />
<br />
<h2>
We are sold out</h2>
<div>
Initially I planned for 80 attendees. It turned out that was much too small, so we have added 30 more tickets as the event and venue can handle 110 people without problems. Today we have 112 registrations and since I want to make sure that everyone has an excellent time at this first XtextCON we closed registration today. I'm really sorry if you haven't booked yet but wanted to do so. We'll likely do an XtextCON next year again. </div>
<br />
<h2>
New Sessions</h2>
<div>
We have added some really cool new sessions. All in all XtextCON will feature 18 Speakers and 28 sessions in two tracks. The added sessions are:</div>
<div>
- <b>Xtext + Sirius : <3 </b> (Cedric Brun)</div>
<div>
- <b>Xtext + CDO - Does it blend?</b> (Stefan Winkler)</div>
<div>
- <b>Oomph - Automatically Provision a Project-Specifc IDE</b> (Eike Stepper, Ed Merks)</div>
<div>
- <b>3D Modeling with Xtext</b> (Martin Nilsson, Esa Ryhänen)</div>
<div>
- <b>Handle Based Models for Xtext with Handly</b> (Vladimir Piskarev)</div>
<div>
<br /></div>
<div>
Checkout the <a href="http://www.xtextcon.org/#program" target="_blank">updated program</a><span id="goog_2004628833"></span><span id="goog_2004628834"></span><a href="https://www.blogger.com/"></a>.</div>
Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-33976825877694872952014-02-13T13:57:00.000+01:002014-02-13T13:57:27.080+01:00Announcing XtextCON 2014I'm super stoked to announce the first edition of XtextCON, an annual conference on Eclipse Xtext.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigZEqiSRONOw_dlbejnEjBDNkNts_JvtH2Jaibuh6VogAp8pdgRbP29zfFNoExGhfJXqjKrOELTVb1pNLsrGf-87Ez2TnLcTgTyE2NE2DfgXbii3o7Pysh9Un_8_dhZgvGr28hjw/s1600/Xtext-Con-Logo-rot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigZEqiSRONOw_dlbejnEjBDNkNts_JvtH2Jaibuh6VogAp8pdgRbP29zfFNoExGhfJXqjKrOELTVb1pNLsrGf-87Ez2TnLcTgTyE2NE2DfgXbii3o7Pysh9Un_8_dhZgvGr28hjw/s1600/Xtext-Con-Logo-rot.png" height="75" width="320" /></a></div>
<br />
With close to 6000 newsgroup items per year the Xtext community is one of the largest and most active at Eclipse.org. Although conferences such as EclipseCON <a href="http://blog.efftinge.de/2012/02/eclipsecon-2012-and-xtext.html">feature many talks on Xtext</a>, they usually cannot go into much detail as those conferences are targeting many different technologies. XtextCON should be an event where we can dive deeper. It is a community event and is meant to help users solving technical problems, get feedback on design ideas and learn about advanced topics.<br />
XextCON is targeting beginners as well as advanced users. Beginners get the opportunity to attend a one-day workshop before the conference. So they get up to speed for the deeper talks at the main conference while those who are experienced with Xtext but feel like there knowledge is a bit outdated will get a quicker heads-up in the morning of day one.<br />
The program covers many different aspects such as scoping, linking, how the index works, how to build type system, and many more. Also we have talks on graphical editing or generally how to improve the performance of your languages, code generators and IDEs. Btw: Thanks to the many attendees of <a href="http://blog.efftinge.de/2014/01/quick-survey-about-xtextcon.html">the survey</a>, it helped a lot to put the program together.<br />
<h1>
Xtext Clinic</h1>
In addition to the two main tracks, we will run a special Xtext-clinic on both days, where attendees get the opportunity to discuss their individual Xtext-related issues with committers and experts.<br />
<h1>
The Location</h1>
The event takes place in Kiel at the ATLANTIC hotel, which sits directly at the beautiful harbour of Kiel face to face with our office. Kiel is a small city in northern Germany at the baltic sea and May is the best time to visit it. The area around it is one of the most beautiful places at this time.<br />
It could be a good idea to bring your family and spend the weekend here as well.<br />
So, check out <a href="http://www.xtextcon.org/" target="_blank">more details on the website</a> and make sure to make a reservation early. Tickets are limited!
Looking forward to see you there!<br />
<br />
<div style="text-align: center;">
<b>Check out <a href="http://www.xtextcon.org/">http://www.xtextcon.org</a></b></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjz41lw9FoDRFMjiX40gIqMYguwicgiUiEOP3VWxQQWjrIiUtxQcqS7D7X9C0u7fS6GDFBJYZT17TIPORIrn8nu4WsALPuGQQ4Z5y470Pi3TTwHJcDQk4cTzb8az4iW8DAc_Ua9tQ/s1600/Strand_Schilksee.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjz41lw9FoDRFMjiX40gIqMYguwicgiUiEOP3VWxQQWjrIiUtxQcqS7D7X9C0u7fS6GDFBJYZT17TIPORIrn8nu4WsALPuGQQ4Z5y470Pi3TTwHJcDQk4cTzb8az4iW8DAc_Ua9tQ/s1600/Strand_Schilksee.jpg" height="408" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<br />
Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-14446576456118138222014-01-27T11:07:00.000+01:002014-01-27T11:45:03.192+01:00Quick Survey about XtextCON Dear Xtext-Community!<br />
<br />
we think it's time for an annual meet-up / conference ... what ever, solely on <a href="http://www.xtext.org/" target="_blank">Xtext</a>. The first one is planned to take place on May 26 and 27 and I'm in the process of building a website including the program. For that I need your help :-)<br />
<br />
I have compiled a list of Xtext-related topics, and would like to ask you to give feedback about which you find interesting, and also which are missing. So, in case consider attending XtextCon, please take the survey below (it's just one question). Also please forward to you colleagues. the more feedback we have the better the program can be.<br />
<br />
<div style="text-align: center;">
<a href="https://de.surveymonkey.com/s/77WTZLD" target="_blank">Survey: What topics would you like to see at XtextCON?</a> </div>
<br />
Also: If you are interested in presenting at XtextCON, please drop me a mail (xtextcon at itemis dot com). Thanks! :-)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtGgO82PT-vdEDMmaAj6M7NFvplfdKTYrV-bFaP4dVHLSfwPptRUD_ObrCPA7-rFahTpYy8JuC2YQwFNMXrKxIeth6WTxw4w5Er-mD_dLQJFN56IqvnWUklxX_reTVaeyc9PgS0Q/s1600/Screen+Shot+2014-01-27+at+10.51.15.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtGgO82PT-vdEDMmaAj6M7NFvplfdKTYrV-bFaP4dVHLSfwPptRUD_ObrCPA7-rFahTpYy8JuC2YQwFNMXrKxIeth6WTxw4w5Er-mD_dLQJFN56IqvnWUklxX_reTVaeyc9PgS0Q/s1600/Screen+Shot+2014-01-27+at+10.51.15.png" height="181" width="320" /></a></div>
Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-7853616132930519762013-10-16T08:40:00.000+01:002013-10-16T08:40:44.727+01:00Xtend & Android - Sneak Preview
<p>In preparation of upcoming presentations for <a href="http://www.eclipsecon.org/europe2013/rapid-android-development-xtend">EclipseCon</a> and <a href="http://jax.de/wjax2013/node/593">W-JAX</a> on that matter, I dived deeper into Android development and worked improving common programming idioms in that area. I'm contributing to Toby Kurien's <a href="https://github.com/tobykurien/Xtendroid">Xtendroid</a> and in this post I want to give you an idea of how Xtend can help developing Android applications.</p>
<h2>Binding Android Layouts to Code</h2>
<p>In Android user interfaces are mostly developed using Android's XML format for layouts. You can program them using Java but that's not what people do most of the time for various reasons. One of course being the verbosity of Java, but also the tools around the layout XML are quite helpful, especially when you have to deal with internationalization and need to support a wide range of devices.</p>
<p>Of course XML alone doesn't cut it which is why you have to bind the stuff declared in XML to Java code somehow in order to add listeners and other dynamic functionality. By default this is quite cumbersome as you have to deal with untyped code (cast) and a lot of integer constants. Some thirdparty frameworks try to reduce this problem by "injecting" the needed views reflectively, but that doesn't really help much. It's still not type safe and therefore error prone and you'll have to redeclare (i.e. duplicate) what you have declared in XML already.</p>
<p>With Xtend you can use an active annotation, which just points to the xml layout file. An active annoation is a macro annotation, which allows for participating in the compilation. This one will look into the referenced layout XML and declare local fields for any elements attributed with an '@id'. It also will derive an interface with all <code>onclick</code> methods declared in XML and make the current class implement it. As a result there is zero duplication and 100% type safety. The best is that the IDE knows about the changes and provides you with respective compilation problems, quick fixes, content assist and also the outline shows what has been derived from the XML layout file.</p>
<p>This is best shown in a small demo:</p>
<iframe src="//player.vimeo.com/video/77024959" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p><a href="http://vimeo.com/77024959">Xtend and Android - Binding XML Layout and Code</a> from <a href="http://vimeo.com/user2817486">Xtext Team</a> on <a href="https://vimeo.com">Vimeo</a>.</p>Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-71959214879583835702013-09-04T10:35:00.002+01:002013-09-04T10:43:00.130+01:00Better I18n in Java<p>Internationalization is not the most loved topic for Java developers. This is merely because it makes code less readable and introduces the need to work with property files and constants. As a result there is no static typing in that area and we are in need to get supported by tools, such as IDEs. In this blog post I want to show how this can be elegantly solved with <a href="http://www.eclipse.org/xtend">Xtend</a>.</p>
<h3>I18n - The JDK Way</h3>
<p>The JDK offers well working facilities for externalizing messages and formatting values such as dates and currencies in a proper localized way. For externalizing messages the class <code>ResourceBundle</code> is your friend, as it not only reads and parses property files but also supports flexible way of how property values are looked up based on Locales. The other interesting bit is the <code>MessageFormat</code> hierarchy which contains strategies to turn data types into localized strings. </p>
<p>The provided functionality is very powerful but enforces a cumbersome programming model. The standard way is to have a bunch of property files and whenever you need to get the contained values you use a <code>ResourceBundle</code> which has to be created like this:</p>
<pre class="prettyprint lang-java">
ResourceBundle messages = ResourceBundle.getBundle("MyMessages", localeToUse);
</pre>
<p>Now you obtain the messages using the property keys, which are just strings. To minimize very likely spelling problems and it is good practice to have a declaring all the keys as constants. Then you only have to declare them once in the code and once for each property file.</p>
<pre class="prettyprint lang-java">
public class MyMessagesKeys {
public final static GREETING = "greeting";
...
}
</pre>
<p>Clients can access the values using the constants :</p>
<pre class="prettyprint lang-java">
messages.getString(MyMessagesKeys.MY_KEY);
</pre>
<p>A common requirement and feature is to have variables in the messages which should provided by the program. These arguments can even be of different types, where the <code>MessageFormat</code> types come in. But again the Java compiler doesn't know if there are any arguments, nor how many and of which types they are. So you are back in untyped land and will learn about your errors only at runtime.</p>
<p>Let's see how we can improve the API for the JDK classes, such that we get rid of all the duplication and weakly typed access.</p>
<h3>DRY With Xtend</h3>
<p>Xtend is not a language which is meant to be used instead of Java, but is an extension to Java. You should use it in places where Java just doesn't cut it, like in this example.</p>
<p>In the following we're going to built a statically typed API to be used from Java by means of an active annotation. The basic idea is, that we make the compiler turn a constant containing a message into a Java facade and a corresponding properties file. Consider the following declaration of messages:</p>
<pre class="prettyprint lang-xtend">
@Externalized class MyMessages {
val GREETING = "Hello {0}!"
val DATE_AND_LOCATION = "Today is {0,date} and you are in {1}"
}
</pre>
<p>This is all the developer should need to declare. Now we implement an active annotation, that turns the field declarations into static methods. It even adds typed arguments for the placeholders in the messages. That is the generated Java provides the following sigatures:</p>
<pre class="prettyprint lang-java">
// Generated Java signatures
/**
* Hello {0}!
*/
public static String GREETING(String arg0) { ... }
/**
* Today is {0,date} and you are in {1}
*/
public static String DATE_AND_LOCATION(Date arg0, String arg1) { ... }
</pre>
<p>The actual values are written to a <code>*.properties</code> file and the implementation of the static methods use a <code>ResourceBundler</code> to look them up. So in case you need a locale-specific translation, you only need to add an additional *.properties file. Even that could be easily validated for miss-spelled or non declared keys. But I'll leave this feature as an exercise for other people :-).</p>
<p>Java clients can now access the messages in a statically typed way, and if you are working within Eclipse you even get the default message displayed when hovering over a property.</p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDf2xY2JfZAVnRDhwEf2XB0uOuCwcIiFkveYNQY8u1mlLqEwxk5933Ufh1vYKkxQsPFzdRfsWAbxm_8NLZPp4GQe_SwzGPmBQo-0JQ9GafiCyeHXPtSpf40qE2hWEu_j2oBApmmA/s1600/Screen+Shot+2013-09-03+at+9.59.00+AM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDf2xY2JfZAVnRDhwEf2XB0uOuCwcIiFkveYNQY8u1mlLqEwxk5933Ufh1vYKkxQsPFzdRfsWAbxm_8NLZPp4GQe_SwzGPmBQo-0JQ9GafiCyeHXPtSpf40qE2hWEu_j2oBApmmA/s1600/Screen+Shot+2013-09-03+at+9.59.00+AM.png" /></a></div>
<h3>Building The @Externalized Annotation</h3>
<p>Developing the active annotation is relatively easy. First you need to create a separate Java project. Although an active annotation is just library, it has to sit in an upstream project or jar, i.e. cannot be used within the same project. We would run into chicken 'n egg problems during compilation if that was allowed.</p>
<p>In that project create a new Xtend file and name it <code>Externalized.xtend</code>. We first declare the annotation and annotate it with <code>@Active</code> so the compiler is aware of it being an active annotation. We also have to provide a processor class which is executed by the compiler:</p>
<pre class="prettyprint lang-xtend">
@Active(ExternalizedProcessor) annotation Externalized {}
class ExternalizedProcessor extends AbstractClassProcessor {
override doTransform(MutableClassDeclaration clazz, extension TransformationContext ctx) {
// To be implemented ...
}
override doGenerateCode(ClassDeclaration clazz, extension CodeGenerationContext ctx) {
// To be implemented ...
}
}
</pre>
<p>As you can see two callback methods have been overridden, which correspond to certain phases in the compiler. The first phase we participate in is <code>doTransform</code> in which the annotated classes can be mutated. The second phase <code>doGenerateCode</code> allows us to write to the file system. We will later write the properties files during this phase. The <code>doGenerateCode</code> phase has been introduced in version 2.4.3, so make sure you have <a href="http://www.xtendlang.org">updated</a> accordingly if you want to use this.</p>
<h4>Step 1: Transforming The Fields Into Methods</h4>
<p>We want to turn all field declarations into static methods, so we first iterate over the declared fields of the given class.</p>
<pre class="prettyprint lang-xtend">
override doTransform(MutableClassDeclaration clazz, extension TransformationContext ctx) {
for (field : clazz.declaredFields) {
// get the actual value of the field
val initializer = field.initializerAsString
// create a message format object for that value
val msgFormat = try {
new MessageFormat(initializer)
} catch(IllegalArgumentException e) {
field.initializer.addError("invalid format : " + e.message)
new MessageFormat("")
}
// check the syntax and report back in case of problems
val formats = msgFormat.formatsByArgumentIndex
if(msgFormat.formats.length != formats.length) {
field.initializer.addWarning('Unused placeholders. They should start at index 0.')
}
// add a method using the field's name
clazz.addMethod(field.simpleName) [
// return type is always string and the method is static
returnType = string
static = true
// add parameters for the given arguments in the message format object
formats.forEach [ format, idx |
addParameter("arg" + idx,
switch format {
NumberFormat: primitiveInt
DateFormat: Date.newTypeReference()
default: string
})
]
// add the value as a comment, for documentation purpose
docComment = initializer
// add the actual body. It's generated Java code.
val params = parameters
body = [
'''
try {
String msg = RESOURCE_BUNDLE.getString("«field.simpleName»");
«IF formats.length > 0»
msg = «toJavaCode(MessageFormat.newTypeReference)»
.format(msg,«params.map[simpleName].join(",")»);
«ENDIF»
return msg;
} catch («toJavaCode(MissingResourceException.newTypeReference)» e) {
// TODO error logging
return "«initializer»";
}
''']
]
}
// now that we have the methods we can just remove the fields,
// as they are no longer needed
clazz.declaredFields.forEach[remove]
// add a static ResourceBundle to be used from the methods we just created.
clazz.addField("RESOURCE_BUNDLE") [
static = true
final = true
type = ResourceBundle.newTypeReference
initializer = ['''ResourceBundle.getBundle("«clazz.qualifiedName»")''']
]
}
</pre>
<p>Now we have successfully transformed an <code>@Externalized</code> class written in Xtend into a Java class containing corresponding static methods.</p>
<h4>Step 2: Generating The Properties File</h4>
<p>The last thing we need to do now is to write the values of the fields into the properties file. For this we participate in the code generation phase by overriding <code>doGenerateCode</code>. While during <code>doTransform</code> we got a mutable Java representation of the original sources, in this phase we get the unmodifiable original source passed in.</p>
<pre class="prettyprint lang-xtend">
override doGenerateCode(ClassDeclaration clazz, extension CodeGenerationContext ctx) {
// obtain the target folder for the given compilation unit
val targetFolder = clazz.compilationUnit.filePath.targetFolder
// compute the path for the properties file
val file = targetFolder.append(clazz.qualifiedName.replace('.', '/') + ".properties")
// write the contents to the file
file.contents = '''
«FOR field : clazz.declaredFields»
«field.simpleName» = «field.initializerAsString»
«ENDFOR»
'''
}
</pre>
<h3>Check Out The New Release</h3>
<p>The described example is included in the "active annotations examples" coming with <a href="http://www.xtend-lang.org">latest release</a>.</p>Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comKiel, Germany54.3232927 10.12276520000000354.0270852 9.4773182000000027 54.619500200000004 10.768212200000004tag:blogger.com,1999:blog-24248206.post-82539245876848663762013-09-04T10:35:00.001+01:002013-09-04T10:35:29.528+01:00Xtend and Xtext 2.4.3 Is Out!<p>We have released version 2.4.3 of Xtext and Xtend. As you can see by the minor increment it's a fully backwards compatible bugfix release. For this release <a href="http://goo.gl/ODHAQB">more than 120 bugzillas</a> have been solved, among them some very important enhancements:</p>
<h3>Active Annotations : New Provisional File API</h3>
<p>The still provisional active annotations API has gotten a new compiler phase and API which allows users to interact with the file system during compilation. This on the one hand is useful to generate signatures based on configuration files or generally project resources and on the other hand allows to update or fully generate such resources based on code. I have written <a href="http://blog.efftinge.de/2013/09/better-i18n-in-java.html">a separate blog post</a> describing an example.</p>
<h3>Active Annotations : Polishing, Fixes and Constrain Enforcements</h3>
<p>The API has been further refined and polished. Many contracts already described in the JavaDoc are now enforced such that you get early feedback when violating them.</p>
<h3>Full Support For Unicode</h3>
<p>Xtend now fully supports Unicode in identifiers. When translated to Java unicode characters get escaped only when the target encoding cannot display them. The same mechanism is used for string literals. We haven't pulled this up to Xbase for now, because it would have required clients to regenerate their language infrastructure. This is planned for the next release (2.5).</p>
<h3>Content Assist</h3>
<p>There were some important context where content assist didn't work. That has been fixed. Also some performance optimizations have been made. That said it's still not where we want it to be. So stay tuned.</p>
<h3>Auto Edit</h3>
<p>Severe performance problems with large documents have been identified and solved.</p>
<h3>Rename Refactoring, Organize Imports, Formatting</h3>
<p>Various enhancements have been made and bugs have been fixed in this area.</p>
<h3>Xcore Support</h3>
<p>There were some URI-related problems with using Xcore, which in some situations were a real showstopper. They are fixed now.</p>
<h3>URI Handling</h3>
<p>A problem that was introduced with 2.4.2, which made the build fail with URI comparison exception, has been fixed.
As a result when generating an Xtext language the *.ecore and *.genmodel files are now generated to a different location.</p>
<h3>... and many more</h3>
<p>Check <a href="http://goo.gl/ODHAQB">the full list</a>.</p>Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-90860105272756068852013-06-19T09:43:00.000+01:002016-12-15T17:16:04.520+01:00Five good reasons to port your code generator to XtendIf you happen to have an existing code generator written in Xpand or some other (template) language, here are five good reasons why you should migrate to Xtend.<br />
<h4>
Xtend is fast</h4>
Code generation adds to the development turn around time. We all know it : tools can slow us down. They take their share of CPU cycles during the daily development and all that automation is not worth it, if you have to wait for your machine all day long. Many template languages are interpreted and are therefore rather slow as they cannot benefit from optimizations done during compilation. Code generators written in these languages suffer from that of course, and if you don't care you can easily multiply the time your build takes with a slow code generator.<br />
Xtend code is translated to readable and idomatic Java code. It runs as fast as Java, which is *very* fast and there's no additional overhead nor dependencies at runtime. Rough measures have shown that code generators implemented with Xtend are up to ten times faster then the equivalent Xpand version.<br />
<h4>
Xtend is debuggable</h4>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQjh67z4I0CpflCXJhiW2m8WREMJsc_2zPP2CJZToMsn5s1kwOjYtfKU0LC6b7I0KxUm_md6ZSOH85LessEjtFyuyooP_2Ijv4SBGdafWVzYwnXCK0_ax6bE5My_hYcdmPspcukg/s1600/Screen+Shot+2013-06-18+at+3.52.47+PM.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQjh67z4I0CpflCXJhiW2m8WREMJsc_2zPP2CJZToMsn5s1kwOjYtfKU0LC6b7I0KxUm_md6ZSOH85LessEjtFyuyooP_2Ijv4SBGdafWVzYwnXCK0_ax6bE5My_hYcdmPspcukg/s400/Screen+Shot+2013-06-18+at+3.52.47+PM.png" /></a></div>
Code generators, just like any other software system, have a tendency to get a bit complex over time. It's not so funny to find and fix a bug in a real world code generator without any debugging support. Unfortunately that's the situation with most template languages : They don't have any good debugging support.<br />
As Xtend code is translated to readable Java code you can always use the advanced Java debugging tools you are used to. Additionally the Eclipse debugger lets you choose whether you want to debug through the Xtend source code or the generated Java code. You can even switch back and forth during the same debug session (see the screenshot).<br />
<h4>
Better IDE Support</h4>
Xtend's Eclipse support is propably the most advanced after Java. The integration between Xtend and Java is seamless : Navigation, Call Hierarchies and even cross language refactorings just work. And Xtend features the whole Java type system and gives you errors and warnings as you type.<br />
<h4>
Template Expressions and Grey-Space Support</h4>
In contrast to typical template languages such as Xpand, templates in Xtend are expressions which yield some value. This allows for composing multiple templates and lets you pass the results around and process them.<br />
A unique feature to Xtend is the greyspace support. It solves the conflict between pretty printing a template and pretty printing the to-be-generated output. Common template languages cannot distinguish between indentation meant for the template and indentation meant for the output. Xtend can. Here's an example (note the different coloring of whitespace):<br />
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhF027cGG04YzrFCQW5cdoHicOCZicRjK8HIb4CSRENY0SVdf_CITkVNNsbRqZW8e_MlUMudeGr7bDiBwBGbd-CgxrkxcYBfsLkcWSZ3o3Xmapc27x8K5aiseGKQtm7ehYasEePCQ/s1600/Xtend_template_coloring.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhF027cGG04YzrFCQW5cdoHicOCZicRjK8HIb4CSRENY0SVdf_CITkVNNsbRqZW8e_MlUMudeGr7bDiBwBGbd-CgxrkxcYBfsLkcWSZ3o3Xmapc27x8K5aiseGKQtm7ehYasEePCQ/s1600/Xtend_template_coloring.png" /></a></div>
<h4>
Better Extendability</h4>
In order to reuse a code generator and adapt it to the needs of a particular project, you need to be able to hook into it and change certain implementation details. In Xpand this was supported through AOP: You could hook into any template invocation and do what seems fit.<br />
Although very flexible, this approach is also very fragile. The original code generator cannot be evolved, since clients might hook into any template call and you break them easily. Even worse you don't get any compile-time feedback about the broken extension hook.<br />
With Xtend you can use dependency injection together with <a href="http://blog.efftinge.de/2013/06/xtends-extension-providers.html">extension providers</a>. No AOP anymore and the solutions is even faster and statically typed. If you need to exchange some implementation, just reconfigure your dependency injection configuration and your are good.<br />
<h4>
Summary</h4>
There are many more advantages and cool features in Xtend, but I hope the five listed here are convincing enough. <iframe allowfullscreen="" frameborder="0" height="356" marginheight="0" marginwidth="0" mozallowfullscreen="" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/23184478" style="border-width: 1px 1px 0; border: 1px solid #ccc; margin-bottom: 5px;" webkitallowfullscreen="" width="427"> </iframe> <br />
<div style="margin-bottom: 5px;">
<strong> <a href="http://www.slideshare.net/sefftinge/codegeneration-with-xtend" target="_blank" title="Codegeneration With Xtend">Codegeneration With Xtend</a> </strong> from <strong><a href="http://www.slideshare.net/sefftinge" target="_blank">Sven Efftinge</a></strong> </div>
Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-7807366382289800872013-06-18T12:56:00.000+01:002013-06-18T12:58:57.277+01:00Xtend's Extension Providers<p>Xtend supports extension methods very similar to how they are supported by C#. The basic idea is to
make static methods available as instance method on the first argument's type. Example :</p>
<pre class="prettyprint lang-xtend">
import static extension java.util.Collections.*
...
// we can use static methods from Collections like this
val maxValue = myCollection.max // calls Collections.max(myCollection)
val minValue = myCollection.min // calls Collections.min(myCollection)
...
</pre>
<p>
This makes code much more readable as you don't have to read inside out, but can read from left to right. Also the discoverabilty of available features via content assist works much better.</p>
<p>But of course using static methods all over the place is problematic, as you bind your code to the implementation which makes it hard to test and to reconfigure for different situations (e.g. use a different database system).</p>
<h3>Enter Extension Providers!</h3>
<p>In Xtend you can put the extension keyword to a local field or a parameter. This will make its <b>instance</b> methods available on the first parameter's type.<p>
<p>I'll explain that with an example using JPA and Java EE.</p>
<pre class="prettyprint lang-java">
// Java code
@PersistenceContext
EntityManager em
public LineItem createLineItem(Order order, Product product, int quantity) {
LineItem li = new LineItem(order, product, quantity);
order.getLineItems().add(li);
em.persist(li);
return li;
}
public void removeOrder(Integer orderId) {
Order order = em.find(Order.class, orderId);
em.remove(order);
}
</pre>
<p>If you add the keyword <b>extension</b> to the field declaration, the instance methods of the PersistenceManager get projected onto the entities. So you no longer have to write <i>em.persist(li)</i> but can just write <i>li.persist</i>:</p>
<pre class="prettyprint lang-xtend">
@PersistenceContext extension EntityManager
def createLineItem(Order order, Product product, int quantity) {
val li = new LineItem(order, product, quantity)
order.lineItems += li
li.persist
return li
}
def removeOrder(Integer orderId) {
val order = Order.find(orderId)
order.remove
}
</pre>
<p>Extension provider allow for adding layer specific functionality to any classes in a non-invasive way. And you don't have to use static methods for that.</p>
<h3>Better APIs with Extension Providers</h3>
<p>When designing an API, you can make it very easy for the clients to have the right extension providers on the scope.</p>
<p>One possibility is to provide an abstract base class which contains visibly extension fields:</p>
<pre class="prettyprint lang-xtend">
abstract class AbstractDao {
@PersistenceContext
protected extension EntityManager em;
}
class Concrete extends AbstractDao {
// use extension methods from EntityManager
}
</pre>
<p>If you don't like inheritance that much, another approach is to mark a parameter of an abstract method with the extension keyword.</p>
<pre class="prettyprint lang-xtend">
interface JPACallBack {
def void doStuff(extension EntityManager em)
}
</pre>
<p>When implementing that method, the IDE will automatically add the extension keword for you. The <a href="http://www.eclipse.org/xtend/documentation.html#active_annotations_validation">active annotations API</a> uses that idiom.</p>
<p>Note that in case you define the abstract class or the interface in Java, you can add the @Extension annotation instead of the keyword.</p>
<h3>IDE Support</h3>
<p>Sometimes the reader might be a bit unsure where a certain member has been declared. Of course the hover as well as navigation always shows the correct declaration. In addition the semantic coloring highlights extension methods ... </p>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjm6bbw9N2WH7RbplYnOTmGGEIsTQqrfkV56V5VEPHpVkRckSXH3gdKKkVtTPV9xmno9KJDbuT3993iUGpdPpnHOTG3aJrU662na0-ssxjaTMid-vnnhTtKeD8O92bDYLzF5H_YPA/s1600/Screen+Shot+2013-06-18+at+1.24.26+PM.png" imageanchor="1" style="clear: left;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjm6bbw9N2WH7RbplYnOTmGGEIsTQqrfkV56V5VEPHpVkRckSXH3gdKKkVtTPV9xmno9KJDbuT3993iUGpdPpnHOTG3aJrU662na0-ssxjaTMid-vnnhTtKeD8O92bDYLzF5H_YPA/s1600/Screen+Shot+2013-06-18+at+1.24.26+PM.png" /></a></div>
<p> ...and you can even inspect the desugared version of an expression in the hover : </p>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9l5-CHZGeCQdJkN5EVCLQ4ReLLd37SdyLw0vWdvElawcCh3YSgKAj_02DlUqrIpVUtCj3VqmqFpYwPAvi0_NYG7-2wc70l_t6vj93i7QAN7OjgQ-lvnbREqsxJ-1B8I88AeQwbg/s1600/Screen+Shot+2013-06-18+at+1.25.11+PM.png" imageanchor="1" style="clear: left;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9l5-CHZGeCQdJkN5EVCLQ4ReLLd37SdyLw0vWdvElawcCh3YSgKAj_02DlUqrIpVUtCj3VqmqFpYwPAvi0_NYG7-2wc70l_t6vj93i7QAN7OjgQ-lvnbREqsxJ-1B8I88AeQwbg/s1600/Screen+Shot+2013-06-18+at+1.25.11+PM.png" /></a></div>
Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-6350883514461369412013-03-22T11:04:00.000+01:002013-06-10T15:11:51.422+01:00Working With JSON Data From Java<i>UPDATE : I have uploaded the example to github : <a href="https://github.com/svenefftinge/jsonized">JSONized@Github</a>.</i>
<br/><br/>
I am preparing excercises for the Xtend tutorial Sebastian and I will be giving on Monday at EclipseCon.
For one excercise we parse an itunes music library in JSON format in order to execute different queries on that data.
Of course the data is well structured, so why not adding a thin typed facade over the generic JSON objects?
I've built a little <a href="http://www.eclipse.org/xtend/documentation.html#activeAnnotations">active annotation</a> which let's you do the following:
<h3>Step 1: Find some Data</h3>
<p>Let’s take <a href="http://developer.yahoo.com/yql/console/?_uiFocus=music#h=select%20*%20from%20music.release.popular">data from Yahoo</a> as an example.
The data contains the most popular new album releases. Here's the first album:</p>
<pre class="prettyprint xml">
{
"query": {
"count": 24,
"created": "2013-03-21T20:13:42Z",
"lang": "en-US",
"results": {
"Release": [
{
"UPC": "602527291567",
"explicit": "0",
"flags": "2",
"id": "218641405",
"label": "Streamline/Interscope/Kon Live",
"rating": "-1",
"releaseDate": "2009-11-23T08:00:00Z",
"releaseYear": "2009",
"rights": "160",
"title": "The Fame Monster",
"typeID": "2",
"url": "http://new.music.yahoo.com/lady-gaga/albums/fame-monster--218641405",
"Artist": {
"catzillaID": "0",
"flags": "115202",
"hotzillaID": "1810013384",
"id": "58959115",
"name": "Lady Gaga",
"rating": "-1",
"trackCount": "172",
"url": "http://new.music.yahoo.com/lady-gaga/",
"website": "http://www.ladygaga.com/"
},
"ItemInfo": {
"ChartPosition": {
"last": "1",
"this": "1"
}
}
},
....
}
</pre>
<h3>Step 2: Copy the example data into a <code>@Jsonized</code> annotation:</h3>
<pre class="prettyprint lang-xtend">
@Jsonized('{
"query": {
"count": 24,
"created": "2013-03-21T20:13:42Z",
"lang": "en-US",
"results": {
"Release": [
{
"UPC": "602527291567",
"explicit": "0",
"flags": "2",
"id": "218641405",
"label": "Streamline/Interscope/Kon Live",
"rating": "-1",
"releaseDate": "2009-11-23T08:00:00Z",
"releaseYear": "2009",
"rights": "160",
"title": "The Fame Monster",
"typeID": "2",
"url": "http://new.music.yahoo.com/lady-gaga/albums/fame-monster--218641405",
"Artist": {
"catzillaID": "0",
"flags": "115202",
"hotzillaID": "1810013384",
"id": "58959115",
"name": "Lady Gaga",
"rating": "-1",
"trackCount": "172",
"url": "http://new.music.yahoo.com/lady-gaga/",
"website": "http://www.ladygaga.com/"
},
"ItemInfo": {
"ChartPosition": {
"last": "1",
"now": "1"
}
}
}]
}
}
}')
class MusicReleases {
// empty
}
</pre>
<h3>Step 3: Enjoy statically-typed accessor methods!</h3>
<p>The annotation will create getters and setters derived from the example data. It's just a super thin layer and you have full access to the underlying <code>JsonObject</code> if you want to go more dynamic. If you want to learn how to do such things, you should come to our tutorial. It's going to be fun!</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmr1n7ay_Cwu0jCg6k3LgpvX32IPEP8XbMM6D-nZNEzrUjtStCDwx4baapIdNrssjYqAgSR56esR1kmYinU2aUFZjz4sBL1hfHQ9WLuhR2FDgS0fQH-CaDYWjZgNjtvR_qim0xQg/s1600/Screen+Shot+2013-03-21+at+9.24.03+PM.png" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmr1n7ay_Cwu0jCg6k3LgpvX32IPEP8XbMM6D-nZNEzrUjtStCDwx4baapIdNrssjYqAgSR56esR1kmYinU2aUFZjz4sBL1hfHQ9WLuhR2FDgS0fQH-CaDYWjZgNjtvR_qim0xQg/s800/Screen+Shot+2013-03-21+at+9.24.03+PM.png" /></a>Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-40191511091396410602013-03-20T12:35:00.000+01:002013-03-21T08:56:20.819+01:00Xtend 2.4 now available!<p>The committer team behind <a href="www.eclipse.org/xtend">Eclipse Xtend</a> is proud to announce the availability of <a href="http://www.eclipse.org/xtend/releasenotes_2_4.html">Version 2.4</a>. The new release has over <a href="https://bugs.eclipse.org/bugs/buglist.cgi?o5=anywordssubstr&f1=OP&f0=OP&resolution=FIXED&classification=Modeling&classification=Tools&f4=CP&v5=kepler&query_format=advanced&j1=OR&f3=CP&bug_status=RESOLVED&bug_status=VERIFIED&f5=flagtypes.name&component=Backlog&component=Common&component=Core&component=Releng&component=Website&component=Xtext&component=Xtext%20Backlog&product=TMF&product=Xtend&list_id=4768360">300 bug fixes</a>. The most important enhancements are:</p>
<h3>Active Annotations</h3>
<p>They are Lisp-like macros for Java (or Xtend). You declare an annotation and explain to the compiler how annotated elements should be translated to Java source code. The compiler will find those annotations on the classpath and execute them during compilation. The IDE and the compiler are fully aware of how annotations contribute to the compilation process, such that content assist, navigation, linking and error messages all reflect the changes appropriately.<br/> You have to see it in action, it is code generation like it should be! <a href="http://www.eclipse.org/xtend/documentation.html#activeAnnotations">Read More</a></p>
<h3>New Type System</h3>
<p>Xtend 2.4 has gotten a <a href="http://blog.efftinge.de/2013/03/xtends-new-type-system.html">whole new type system implementation</a>, which not only improves the compilation performance but fixes many many outstanding typing issues. Also the type inference algorithm has become much smarter and even takes the control flow into account for type inference. Xtend can even infer types where other languages such as Scala fail.</p>
<h3>Android Support</h3>
<p>Xtend is a perfect match for Android development as it relies on the JDK and comes with very little extra dependencies. The new version has special support for debugging Android emulators and some other goodies.</p>
<h3>New Language Features</h3>
<p>Xtend 2.4 allows to turn local variables and parameters into <a href="http://www.eclipse.org/xtend/documentation.html#Extension_Provider">extension providers</a>, comes with a neat literal syntax for immutable collections, many new operators and some other enhancements.</p>
<h3>New IDE Features</h3>
<p>The Eclipse plug-in now supports formatting, more quick fixes, more refactorings, better content assist and more little gems which let you get into a smoeeth development flow.</p>
<p>Read the <a href="http://www.eclipse.org/xtend/releasenotes_2_4.html">full release notes</a> and <a href="http://www.eclipse.org/xtend/download.html">get the release</a></p>
<h3>Many Thanks</h3>
<p>... to all the committers and contributors who have put this together: Sebastian Zarnekow, Jan Köhnlein, Dennis Hübner, Moritz Eysholdt, Holger Schill, Sebastian Benz, Knut Wannheden, Natalia Ossipova, Anton Kosyakov, Christian Hülsmeier, Stefan Oehme, Ed Merks, Benjamin Schwertfeger, Lieven Lemiengre, Hendrik Eeckhaut, Christoph Kulla, and many more!</p>Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-85798800216364028982013-03-16T10:03:00.000+01:002013-03-17T20:35:37.845+01:00Fun With Active Annotations: My Little REST-Server API<p>
These days I've been playing around a lot with Xtend's new language feature addition, called Active Annotations. It's so exciting want kind of things you can do with them. Today I prototyped a nice little REST-API (<a href="https://github.com/svenefftinge/jettyxtension">code can be found at github</a>):
</p>
<pre class="prettyprint lang-xtend">
@HttpHandler class HelloXtend {
@Get('/sayHello/:name') def sayHello() '''
<html>
<title>Hello «name»!</title>
<body>
<h1>Hello «name»!</h1>
</body>
</html>
'''
@Get('/sayHello/:firstName/:LastName') def sayHello() '''
<html>
<title>Hello «firstName» «LastName»!</title>
<body>
<h1>Hello «firstName» «LastName»!</h1>
</body>
</html>
'''
def static void main(String[] args) throws Exception {
new Server(4711) => [
handler = new HelloXtend
start
join
]
}
}
</pre>
<p>
This is a single class with no further framework directly running an embedded Jetty server. The interesting part here is, that you don't have to redeclare the parameters, as the active <code>HttpHandler</code> annotation will automatically add them to the method. See the method is overloaded but both declare zero parameters? That's usually a compiler error, but here they actually have five resp. six parameters, because my annotation adds the parameters from the pattern in the <code>@Get</code> annotation as well as the original parameters from Jetty's handle method signature. Just so you can use them when needed.</p>
<p>
Not only the compiler is aware of the changes caused by the annotation, but so is the IDE. Content assist, navigation, outline views etc. just work as expected.</p>
<img width="100%" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJcH8hcfBWKIXvlNx2V5QZRjHaUbCA0PJa_iGXRh29oGE88xqy5otNq7VmQ4uSVSSbbBDfxlQ7cVPQwSdEGCTbZyNTkKIPHiAS1hJESd20343XjGJsCIEiPGnPColi88TTxgjZqQ/s1600/Screen+Shot+2013-03-14+at+8.48.45+PM.png" />
<h3>This is how it works</h3>
<p>
The <code>HttpHandler</code> implements <code>org.eclipse.jetty.server.handler.AbstractHandler</code> and adds a synthetic implementation of the method <code>handle()</code>. The effective code it adds to the class we've seen above is :
</p>
<pre class="prettyprint lang-xtend">
// generated, synthetic Java code
public void handle(final String target
, final Request baseRequest
, final HttpServletRequest request
, final HttpServletResponse response) throws IOException, ServletException {
{
Matcher sayHelloMatcher = Pattern.compile("\\/sayHello\\/(\\w+)").matcher(target);
if (sayHelloMatcher.matches()) {
String name = sayHelloMatcher.group(1);
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(sayHello(name, target, baseRequest, request, response));
baseRequest.setHandled(true);
}
}
{
Matcher sayHelloMatcher = Pattern.compile("\\/sayHello\\/(\\w+)\\/(\\w+)").matcher(target);
if (sayHelloMatcher.matches()) {
String firstName = sayHelloMatcher.group(1);
String LastName = sayHelloMatcher.group(2);
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(
sayHello(firstName, LastName, target, baseRequest, request, response));
baseRequest.setHandled(true);
}
}
}
</pre>
<p>Of course there's some room for optimizations :-) but I hope you get the idea. The implementation of the <code>@HttpHandler</code> and its processor is added below :
<pre class="prettyprint lang-xtend">
@Active(typeof(HttpHandlerProcessor))
annotation HttpHandler {
}
annotation Get {
String value
}
class HttpHandlerProcessor implements TransformationParticipant<MutableClassDeclaration> {
override doTransform(List<? extends MutableClassDeclaration> annotatedTargetElements,
extension TransformationContext context) {
val httpGet = typeof(Get).findTypeGlobally
for (clazz : annotatedTargetElements) {
clazz.extendedClass = typeof(AbstractHandler).newTypeReference
val annotatedMethods =
clazz.declaredMethods.filter[findAnnotation(httpGet)?.getValue('value')!=null]
// add and implement the Jetty's handle method
clazz.addMethod('handle') [
returnType = primitiveVoid
addParameter('target', string)
addParameter('baseRequest', typeof(Request).newTypeReference)
addParameter('request', typeof(HttpServletRequest).newTypeReference)
addParameter('response', typeof(HttpServletResponse).newTypeReference)
setExceptions(typeof(IOException).newTypeReference
, typeof(ServletException).newTypeReference)
body = ['''
«FOR m : annotatedMethods»
{
«toJavaCode(typeof(Matcher).newTypeReference)» matcher =
«toJavaCode(typeof(Pattern).newTypeReference)»
.compile("«m.getPattern(httpGet)»").matcher(target);
if (matcher.matches()) {
«var i = 0»
«FOR v : m.getVariables(httpGet)»
String «v» = matcher.group(«i=i+1»);
«ENDFOR»
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(
«m.simpleName»(«m.getVariables(httpGet).map[it+', ']
.join»target, baseRequest, request, response));
baseRequest.setHandled(true);
}
}
«ENDFOR»
''']
]
// enhance the handler methods
for (m : annotatedMethods) {
for (variable : m.getVariables(httpGet)) {
m.addParameter(variable, string)
}
m.addParameter('target', string)
m.addParameter('baseRequest', typeof(Request).newTypeReference)
m.addParameter('request', typeof(HttpServletRequest).newTypeReference)
m.addParameter('response', typeof(HttpServletResponse).newTypeReference)
}
}
}
private def getVariables(MutableMethodDeclaration m, Type annotationType) {
// parses the pattern in @Get and returns the variable names
}
private def getPattern(MutableMethodDeclaration m, Type annotationType) {
// replaces the variables in the pattern with (\\w+) groups, so we can use it as a regex pattern.
}
}
</pre>Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-26633687929803769092013-03-01T10:57:00.002+01:002013-03-01T10:57:58.805+01:00Xtend's New Type System<p>
<blockquote cite="http://dev.eclipse.org/mhonarc/lists/jdt-core-dev/msg02263.html"><h2><i>"We are almost at a stage where only
double PhDs in math & comp.sc can qualify for Java compiler writers !"</i></h2><small><i>(Srikanth S. Adayapalam (from Eclipse JDT) on the complexity of type inference in Java 8)</i></small></blockquote>
</p>
<p>
As <a href="http://www.eclipse.org/xtend">Xtend</a> implements Java's typesystem, we have to deal with exactly the same amount of complexity ... oh wait it's even better as Xtend has
<ul>
<li>advanced type inference,
<li>sugared feature calls for properties,
<li>operator overloading,
<li>an implicit 'it' and
<li>extension methods (which are not only static as in C#)
<li>etc.
</ul>
So you better add a couple more PhDs to the mix.
</p>
<h3>Write once, run ...</h3>
<p>
We are used to writing key parts of our software twice (at least!). The old type system did its job in the beginning but as we added more and more corner cases and complex type inference scenarios with lambdas and such it started to become too slow and too complex to be further enhanced. Good we have a solid test suite so we actually noticed the point at which even harmless looking changes broke existing tests... To make a long story short: Last year in April we decided to rewrite it from scratch.
</p>
<h3>The Lonesome Hero</h3>
<img style="float:right;" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7o3I3Dfj4rlGWPsSmV_UsZUb_xCyc3t3EmSAcoceoqYWaOR5NjAEswxR3gmWW-s6Sxm1aaa5FxEg_vWwT-KwjVGDbdaPqGFEM6-uA-Y7WOnelUXPJLyDsaW0enVzeW85TlQkNoQ/s320/13303_1414069070014_8158505_n.jpg" />
<p><a href="http://zarnekow.blogspot.de">Sebastian</a> had some very promising ideas around a completely different architecture which would not only improve performance but also would allow everyone to better understand and debug the code again. We couldn't afford stopping all other developments and maintenance so one team member had to take the journey while the others were working on cool new features. Almost a year ago Sebastian started work on a complete rewrite. We discussed language semantics from time to time and such things but I rarely looked at the actual code. Most of the semantics were clear as it is based on the Java Language Specification and could be proved with the different Java compilers. So he was climbing this huge mountain all alone.<br/>
I know it was super risky and that it's not a good idea to rely such an important part of a project on just one person. If he had failed we had wasted a year. But I knew he would do it (And if he couldn't I don't know who else could).
</p>
<p>It has been a long time and we even had to postpone the release which was initially planned for December. Finally by the end of January the new type system implementation was in a state that it could be activated and replace the old one. The switch was super smooth. It just worked. </p>
<p><a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=376037">Here is the corresponding bugzilla</a>, which has been closed just yesterday. It blocked <b>95 downstream bugs</b>! Most of them are now fixed, we just had to go through them and test, verify and close them. Not only that, the performance was already as good as the old one in the beginning without any further profiling and improvements. With just a little optimisation we were already able to improve the performance by 25%.<p/>
<p>Also worth noting is, that the whole team was able to start working in the new code base after just two days of introduction. The code definitely is much easier to grasp and to debug yet covers much more of the <a href="http://en.wikipedia.org/wiki/Essential_complexity">essential complexity</a>. Also we have an even more comprehensive test suite now. With over 20.000 unit tests you can confident that you don't accidentally break something. <a href="https://extern.itemis.de/jenkins/job/xtext-head/">All tests run</a> against the lower version bounds as well as the upper version bounds of our dependencies. There's no way software like this can be maintained and evolved without such a test suite.</p>
<p>The new type system is an incredible piece of engineering and a huge success. It's the basis for an awesome upcoming release of Xtend with many cool new features and enhancements.<br/>
Sebastian, I owe you one and so does the growing Xtend community!</p>Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-21625479295016016822012-12-17T21:04:00.005+01:002012-12-18T05:29:22.373+01:00Java 8 vs. Xtend<p>As you might know Java 8 will finally bring an important new feature to the Java programming language : <br><a href="http://openjdk.java.net/projects/lambda/">Lambda Expressions</a>, a feature already supported by many other languages, such as <a href="http://www.xtend-lang.org">Xtend</a></p>
<p>
<a href="http://www.xtend-lang.org">Xtend is a statically typed JVM language</a> that translates to readable Java source code. It's very different to other JVM languages in the sense that aims to be a better Java by better supporting existing Java idioms and fully supporting the existing ecoystem. Xtend doesn't force you to rewrite your existing Java apps or drop your beloved and well-proven frameworks, but instead allows for using existing Java APIs in a much nicer way without any interoperability issues. In contrast to e.g. Scala or Clojure it is more like an extension to Java than a replacement.
</p>
<p>
Identifying and supporting existing Java idioms is not too hard given the huge existing code base but what about the future? Will Xtend also be a better match for the upcoming Java 8 libraries which were explicitly defined for the new Java 8 lambda syntax?
</p>
<p>
To find out I simply looked at Brian Goetz’s latest version of <a href="http://cr.openjdk.java.net/~briangoetz/lambda/sotc3.html">State of the Lambda : Libraries Edition</a> and translated the contained Java code examples to Xtend.
</p>
<p>
In the following you see the code for Java as written by Brian and the translation to Xtend. Both are using the exact same Java 8 APIs and contain the same amount of static type information!
</p>
<h3>Example 1</h3>
<table>
<tr>
<td>Java 8:</td>
<td>
<pre class="prettyprint lang-java">
shapes.forEach(s -> { s.setColor(RED); });
</pre>
</td>
</tr>
<tr>
<td>Xtend:</td>
<td width="100%">
<pre class="prettyprint lang-xtend">
shapes.forEach[color = RED]
</pre>
</td>
</tr>
</table>
<p>
This first example already reveals most of the important differences.
</p><p>
First the general syntax for a lambda expression in Java is using an arrow (<code>-></code>), while <a href="http://www.eclipse.org/xtend/documentation.html#lambdas">Xtend uses squared brackets</a> (like smalltalk). Also in Xtend a lambda expression doesn't need to be passed using braces. Although you could write <code>shapes.forEach([color = RED])</code> you don't need to.
</p><p>
In Java 8 the body of a lambda is either a block or a single expression. So whenever you need to use a statement you have to add the curly braces and semicolons. In Xtend everything is an expression and the lambda itself is already a block expression.
</p><p>
In Xtend you can omit the declaration of a parameter name. In that case the parameter is called '<code>it</code>' and is implicit (similarly to '<code>this</code>'). If you want to give it a name you do it like this : <code>shapes.forEach[ s| s.color = RED]</code>
</p><p>
Unrelated to Lambdas but interesting in this case: Xtend allows to use assignments to call setter methods.
</p>
<h3>Example 2</h3>
<table>
<tr>
<td>Java 8:</td>
<td>
<pre class="prettyprint lang-java">
shapes.stream()
.filter(s -> s.getColor() == BLUE)
.forEach(s -> { s.setColor(RED); });
</pre>
</td>
</tr>
<tr>
<td>Xtend:</td>
<td width="100%">
<pre class="prettyprint lang-xtend">
shapes.stream
.filter[color == BLUE]
.forEach[color = RED]
</pre>
</td>
</tr>
</table>
<p>
Not too much new stuff in here. Xtend lets you omit empty parenthesis and you can call a getter using the property's name.
</p>
<h3>Example 3</h3>
<table>
<tr>
<td>Java 8:</td>
<td>
<pre class="prettyprint lang-java">
List<Shape> blue =
shapes.stream()
.filter(s -> s.getColor() == BLUE)
.into(new ArrayList<>());
</pre>
</td>
</tr>
<tr>
<td>Xtend:</td>
<td width="100%">
<pre class="prettyprint lang-xtend">
val blue =
shapes.stream
.filter[color == BLUE]
.into(new ArrayList)
</pre>
</td>
</tr>
</table>
<p>
Here we see type inference in action. While you can use the diamond operator in Java, you can leave it out in Xtend. Also the variable doesn't need to be explicitly typed as the type can be fully inferred from the right hand side.
</p>
<h3>Example 4</h3>
<table>
<tr>
<td>Java 8:</td>
<td>
<pre class="prettyprint lang-java">
Set<Box> hasBlueShape =
shapes.stream()
.filter(s -> s.getColor() == BLUE)
.map(s -> s.getContainingBox())
.into(new HashSet<>());
</pre>
</td>
</tr>
<tr>
<td>Xtend:</td>
<td width="100%">
<pre class="prettyprint lang-xtend">
val hasBlueShape =
shapes.stream
.filter[color == BLUE]
.map[containingBox]
.into(new HashSet)
</pre>
</td>
</tr>
</table>
<p>
Note how readable the lambdas get when you can leave out all the cryptic clutter. Let's compare a last example from a later section of the document:
</p>
<h3>Example 5</h3>
<table>
<tr>
<td>Java 8:</td>
<td>
<pre class="prettyprint lang-java">
List<Album> sortedFavs =
albums.stream()
.filter(a -> a.tracks.anyMatch(t -> (t.rating >= 4)))
.sorted(comparing(a -> a.name))
.into(new ArrayList<>());
</pre>
</td>
</tr>
<tr>
<td>Xtend:</td>
<td width="100%">
<pre class="prettyprint lang-xtend">
val sortedFavs =
albums.stream
.filter[tracks.anyMatch[rating >= 4]]
.sorted(comparing[name])
.into(new ArrayList)
</pre>
</td>
</tr>
</table>
<p>
Although the libraries as well as the examples have been written for Java 8, the Xtend code is still much less cluttered with symbols and therefore significantly more readable. Yet the type information is exactly the same! Xtend is just a bit smarter with type inference and is syntactically less rigid.
</p>
<p>
Besides that and the fact the Xtend compiles to readable Java 5 code, it has <a href="http://blog.efftinge.de/2012/11/active-annotations-explained-javafx.html">many</a> <a href="http://www.eclipse.org/xtend/documentation.html#templates">other</a> <a href="http://www.eclipse.org/xtend/documentation.html#extensionMethods">important</a> <a href="http://www.eclipse.org/xtend/documentation.html#switchExpression">features</a>
<a href="http://www.eclipse.org/xtend/documentation.html">to offer</a>.
</p>Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-55968583264975820022012-11-15T11:52:00.000+01:002012-12-19T09:14:13.962+01:00Active Annotations Explained - JavaFX Properties<p>
Today I'd like to give a more detailed example of how <a href="http://blog.efftinge.de/2012/10/introducing-active-annotations.html">active annotations</a> can be used to solve real world problems. Active annotations are an upcoming language feature for <a href="http://xtend-lang.org">Eclipse Xtend</a>, which allow you to participate in the translation step from Xtend code to Java using annotations.
</p>
<h3>JavaFX Properties</h3>
<p>
JavaFX comes with a very nice binding and properties framework, which allows for easy connection of
model properties and widgets. It even has support for expressions, like String concatenations, which are reevaluated automatically, when a property changes.
</p><p>
I have used it in a login screen, such that the welcome message get's updated when you type in the user name.
</p>
<div class="separator" style="clear: both; text-align: center;">
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDGgzL7v4GOaBpHwUf7gduml9fztUBgXak8rhlLuSatUhSASaxTxxiYt_AAovq2Kh03Z0RPxA4u7KZRkdrkNUOFl-qtNgzD2hvfJ1ZCXHGxBeBNWhSSR-rbiI03nhmP_M9eR1DSw/s400/Screen+Shot+2012-11-15+at+11.09.32+AM.png" /></div>
<p>
Unfortunately defining JavaFX beans is not so nice, as it requires a lot of boilerplate. Michael Heinrichs, technical lead of JavaFX Properties, recommends the following <a href="http://blog.netopyr.com/2011/05/19/creating-javafx-properties/">pattern in his blog</a>:
</p>
<pre class="prettyprint lang-java">
// Java boilerplate
public class Login {
private String userName = "";
private SimpleStringProperty userNameProperty;
public String getUserName() {
return (this.userNameProperty != null)? this.userNameProperty.get() : this.userName;
}
public void setUserName(final String userName) {
if (userNameProperty != null) {
this.userNameProperty.set(userName);
} else {
this.userName = userName;
}
}
public SimpleStringProperty userNameProperty() {
if (this.userNameProperty == null) {
this.userNameProperty = new SimpleStringProperty(this, "userName", this.userName);
}
return this.userNameProperty;
}
// ... same pattern for the password goes here
}
</pre>
That's a lot of code. Given that we usually have to map a lot of properties to the UI, you don't want to write and maintain that.
</p>
<h3>Code generation to the rescue?</h3>
<p>
The typical solution in those scenarios is to come up with a little DSL and a code generator. In Java land we really know how to do that and there is <a href="http://xtext.org">easy to use technology</a> available to build ... yet another entity DSL. And it's definitely a much better approach than maintaining above's code by hand, but ...
</p>
<p>
The big advantage of frameworks such as Xtext is the flexibility they provide. You can build all kind of tooling and choose the right syntax for the problem. No compromises. However, there are certain classes of DSLs which really don't need or use the syntactic flexibility since they are close to class-like structures : Entities, Services, etc.</p><p>
In addition building an external DSL introduces a bit of an extra complexity in the development turnarounds: You'll have to maintain an Eclipse Plug-In and deploy it synchronously with the rest of your framework to all developers in your team. And just like everything else in your project, the DSL and the code generation evolve over time. So you have to keep everything in sync and deploy and install new Eclipse plug-ins every time your DSL enhances.
</p>
<p>
Don't get me wrong <a href="http://www.eclipse.org/Xtext/7languages.html">there</a> <a href="http://jnario.org">are</a> <a href="http://code.google.com/p/protobuf-dt/">many</a> <a href="http://www.onewind.de/OneModelica.html">situations</a> where the additional flexibility of Xtext is extremely useful, but for a certain class of DSLs you are better off with active annotations.
</p>
<h3>JavaFX Beans with Active Annotations</h3>
<p>
So let's see how we can replace JavaFX beans like the one shown above with a
more readable and maintainable variant.
</p>
<p>
First we replace the Java class with the following Xtend class:
<pre class="prettyprint lang-xtend">
@FXBean class Login {
String userName
String password
}
</pre>
</p>
<p>
Next we define the referenced annotation, like so:</p>
<pre class="prettyprint lang-xtend">
@FXBean for class {
process each {
inDerivedJavaClass(it) [
for (f : declaredFields.toSet) {
//TODO create property field
//TODO create getter
//TODO create setter
//TODO create property accessor
}
]
}
}
</pre>
<p>
The syntax is a bit different from Java's since we are convinced that reusing the keyword <code class="prettyprint java-lang">interface</code> for an annotation, as Java does, is surprising at least.
Also the annotation target (<code class="prettyprint java-lang">class</code> in this case) is a first class syntax construct and is not encoded in another annotation.
</p>
<p>
The important part is the 'process'-hook, which will be called by the Xtend compiler, for every class that is annotated with <code>@FXBean</code>. Therein we state that we want to iterate over the <code>declaredFields</code> in the context of the derived Java class.
</p>
<p>
In the following we are going to replace the individual TODOs to make the compiler create a real JavaFX property from just a single field declaration.
</p>
<p>We start by declaring a couple of local variables we'll use in the following:</p>
<pre class="prettyprint lang-xtend">
process each {
inDerivedJavaClass(it) [
for (f : declaredFields.toSet) {
val fieldName = f.simpleName
val fieldType = f.type
val propName = f.simpleName+'Property'
val propType = f.type.toPropertyType(this)
]
}
</pre>
<p>The extension method <code class="prettyprint xtend-lang">toPropertyType()</code> is not shown here, but it's really just a small utility method I built, which will return the JavaFX property type for the field's type. E.g. when asked with the type <code class="prettyprint xtend-lang">String</code> the extension method returns the type <code class="prettyprint xtend-lang">SimpleStringProperty</code>. Such utility methods simply reside on the classpath just like the annotation itself.</p>
<p>Let's now create the field.</p>
<pre class="prettyprint lang-xtend">
process each {
inDerivedJavaClass(it) [
for (f : declaredFields.toSet) {
val fieldName = f.simpleName
val fieldType = f.type
val propName = f.simpleName+'Property'
val propType = f.type.toPropertyType(this)
// create a field for the JavaFX property type
field(propName, propType)
}
]
}
</pre>
<p>The method <code class="prettyprint xtend-lang">field(String, Type)</code> adds a field to the class in context using the given name and type. We could also change existing Java information here, like visibility and so on and also have an initializer or add annotations. You can even create new Java classes interfaces, etc.. Basically everything you can do in Java, can be done here.</p>
<p>Next up we create a 'getter'-method:</p>
<pre class="prettyprint lang-xtend">
process each {
inDerivedJavaClass(it) [
for (f : declaredFields.toSet) {
val fieldName = f.simpleName
val fieldType = f.type
val propName = f.simpleName+'Property'
val propType = f.type.toPropertyType(this)
// create a field for the JavaFX property type
field(propName, propType)
// getter
method ('get'+fieldName.toFirstUpper, fieldType) [
body =
'return (this.'+propName+' != null)?
this.'+ propName +'.get() : this.'+fieldName+';'
]
}
]
}
</pre>
<p>Nothing special here. The square brackets are a lambda expression wherein you can customize the created method. We assign a body in this case.</p>
<p>The other two methods are created similarly:</p>
<pre class="prettyprint lang-xtend">
@FXBean for class {
process each {
inDerivedJavaClass(it) [
for (f : declaredFields.toSet) {
val fieldName = f.simpleName
val fieldType = f.type
val propName = f.simpleName+'Property'
val propType = f.type.toPropertyType(this)
field(propName, propType)
// getter
method ('get'+fieldName.toFirstUpper, fieldType) [
body =
'return (this.'+propName+' != null)?
this.'+ propName +'.get() : this.'+fieldName+';'
]
// setter
method ('set'+fieldName.toFirstUpper, type('void')) [
param(fieldName, fieldType)
body =
'if ('+propName+' != null) {
this.'+propName+'.set('+fieldName+');
} else {
this.'+fieldName+' = '+fieldName+';
}'
]
// property accessor
method (fieldName+'Property', propType) [
body =
'if (this.'+propName+' == null) {
this.'+propName+' =
new '+propType.identifier+'(this,"'+fieldName+'",this.'+fieldName+');
}
return this.'+propName+';'
]
}
]
}
}
</pre>
<p>And that's it. What you can't see here, is that everything gets updated and recompiled instantaneously on safe. Also important to note, is that you don't need any additional compiler configuration. Just have your active annotation on the classpath (e.g. distributed via jar or in the some project) is enough to use it and have the compiler applying it. And this of course works wherever you compile Xtend code (Command Line, Eclipse, Ant, Maven, etc.).</p>
<p>Naturally the IDE and the compiler is aware of what you do in the processing so, you'll for instance get the expected content assist proposals, ca use the typical navigation features and see the synthetically derived methods and fields in the outline view.</p>
<div class="separator" style="clear: both; text-align: center;">
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNUu4t8lEX9iTQD3AdAROAWDrX9McOmWmkdA_KzsFanE5fw0p17HiC2o7ePKWnzx0A9giCD1ogLieKKakbDzxE90O4ATl3z2eNhlaCgWofas7oOiLa3BnL7vzbKtFiFRdZ7eh_VA/s1600/Screen+Shot+2012-11-15+at+11.43.29+AM.png" />
</div>
<p>The following screen cast shows everything in action:</p>
<div class="separator" style="clear: both; text-align: center;">
<iframe src="http://player.vimeo.com/video/53577174?badge=0" width="825" height="515" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> <p><a href="http://vimeo.com/53577174">Xtend Active Annotations Explained - JavaFX Properties</a> from <a href="http://vimeo.com/user2817486">Xtext Team</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
</div>Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.comtag:blogger.com,1999:blog-24248206.post-66774977112508530772012-10-23T16:06:00.000+01:002012-10-23T19:34:18.737+01:00Introducing : Active AnnotationsIn this article I'd like to introduce you to a new important language feature for Xtend. <a href="http://www.eclipse.org/xtend">Xtend</a> is a statically-typed language which compiles down to readable Java source code.<br /><br />
<h2>
Active Annotations in a Nutshell</h2>
Active Annotations allow for participating during the translation of Xtend code to Java source code. You basically declare an annotation and with it provide the processing instructions where you can
<ul>
<li><b>issue errors and warnings</b>,
<li><b>provide corresponding quickfixes</b>,
<li><b>apply all kind of changes and enhancements to the target Java classes</b>,
<li><b>introduce new Java types</b> or
<li>even <b>update or create ordinary text files (e.g. web.xml)</b>.
</ul><br />
To use such an annotation you just have to have it on your class path like any ordinary Java annotation.<br />
You could for instance want to have an annotation called <code>@Entity</code>, which turns simple classes with fields into data classes tailored for your project-specific context. You'd define and maintain the definition of what an entity is right in your project and would version and distribute it just like any other API. The IDE will be fully aware of the processing changes. Not only will errors, warnings and quickfixes be available in the IDE but also the scopes, type computation and content assistance will behave according to your processing instructions.<br /><br />
<h2>General Use Cases</h2>
Let's have a look at some use cases. Xtend already comes with two annotations, whose processing for now is hard coded into the compiler. We did so, to gain some experience with the general idea and will of course replace the hard coded version with 100% library-based annotations in a future release.<br />
One of these annotations is the <code>@Property</code> annotation, which translates a simple field into a Java-Bean property. That is given the following Xtend code <br />
<pre class="prettyprint xtend-lang"> // Xtend
@Property String name
</pre>
you'll get this Java code :<br />
<pre class="prettyprint java-lang"> // Java
private String name;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
</pre>
The other annotation Xtend already has is <code>@Data</code> which translates a class with fields into a value object á la domain-driven design, i.e. it creates an immutable class with a value-based <code>equals</code> and <code>hashcode</code> implementation and a nice <code>toString</code> implementation. We will likely support other generic use cases such as <code>@Delegate</code>, which generated delegate methods for an annotated field and <code>@Builder</code> which will automatically derive a builder API for a set of classes. <br /><br />
<h2>
Framework-specific Use Cases</h2>
You might have seen pre-built annotations which do participate in the compilation project with other technologies. The real coolness about active annotations in Xtend is that everybody can develop their own project specific ones easily. If you want to change the behavior, just navigate to the annotation and do your changes. You will instantly see the result, since every referencing Xtend file will be re compiled on change. And it is fully transparent since everything is translated to readable Java source code!<br />
With this simplicity to develop and deploy them people will be able to use them to remove tedious structural boilerplate in many Java APIs. We for instance built two active annotations for GWT. One for remote services, which automatically derives the required interfaces and adds the required super class. Another which automatically adds fields declared in a UI-Binder XML file. You can find <a href="http://www.slideshare.net/sefftinge/gwt-and-xtend">some slides</a> here and the <a href="https://github.com/DJCordhose/todomvc-xtend-gwt">source code is on github</a>.<br /><br />
<h2>
Outlook</h2>
Today we have a working prototype, which you can play around with if you are brave enough. But there's no documentation and the API changes on a daily bases, so better wait a bit. We will release a beta version of this new feature with the next release (planned for December/January), but this will still lack some important features and the API will be subject to change.<br /><br/>
I am very excited and think active annotations really solve a huge class of problems in a very nice way and am really curious with what kind of annotations people will come up in the future. <br /><br/>
Alan Kay once said about Lisp that it is not a language but a building material. Active annotations bring the power of Lisp Macros to the statically typed Java world.Anonymoushttp://www.blogger.com/profile/11751196715155150517noreply@blogger.com