Scoping with Xtext/TMF 0.8

29. Januar 2010

Usually I hate it when APIs break. TMF 0.8 introduces a different scoping API than Xtext 0.7. It took me a while to figure out. So I’ll show the changes below:

Component :
    "component" name = ID "{"
    (ports+=Port)*
    "}";

Port :
    "port" dir=Direction name=ID ":"  ref=[Interface|ID] ";"
    ;

enum Direction :
    IN="in" | OUT="out";

Instance:
    "instance" name=ID ":" type=[Component|ID] ";"
    ;

Connection:
    "connect" in=[Instance|ID]"."p=[Port|ID] "->" in2=[Instance|ID]"."p2=[Port|ID] ";"
    ;

The default code completion will traverse all defined Ports for the references p and p2 in the Connection rule. A better behaviour would be:

  • Show only the ports in the instances (in, in2)
  • For p, show only “OUT”-Ports, for p2, show only “IN”-ports.

To do this, we need to define methods in a class derived from AbstractDeclarativeScopeProvider. The method names follow the signature scope_<rule>_<element>, so the the old code fragment for was:

public class AutomotiveDSLScopeProvider extends AbstractDeclarativeScopeProvider {
    IScope scope_Connection_p2(Connection ctx, EReference ref)
    {
        if(ctx.getIn2() == null )
            return IScope.NULLSCOPE;
        else
            return new SimpleScope(IScope.NULLSCOPE, getRPorts(ctx.getIn2().getType()));
    }
    IScope scope_Connection_p(Connection ctx, EReference ref)
    {
        if(ctx.getIn() == null )
            return IScope.NULLSCOPE;
        else
            return new SimpleScope(IScope.NULLSCOPE, getPPorts(ctx.getIn().getType()));
    }
    private Iterable<IScopedElement> getPPorts(Component clazz) {
        List<IScopedElement> result = new ArrayList<IScopedElement>();
        for (Port f : clazz.getPorts())
            if (f instanceof Port && f.getDir() == Direction.OUT)
                result.add(ScopedElement.create(f.getName(), f,"("));
        return result;
    }
    private Iterable<IScopedElement> getRPorts(Component clazz) {
        List<IScopedElement> result = new ArrayList<IScopedElement>();
        for (Port f : clazz.getPorts())
            if (f instanceof Port && f.getDir() == Direction.IN)
                result.add(ScopedElement.create(f.getName(), f));
        return result;
    }
}

One of the important changes that I use different imports, because some are deprecated and some are generally nice to use. Newly introduced are:

import static org.eclipse.xtext.scoping.Scopes.*;

for helpful functions and

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.inject.Inject;

for working with lists. So the new code looks like this:

public class AutomotiveDSLScopeProvider extends AbstractDeclarativeScopeProvider {

	protected Predicate<Port> pPortPred = new Predicate<Port>(){
		public boolean  apply(Port input) { return input.getDir() == Direction.OUT ; }
	};

	protected Predicate<Port> rPortPred = new Predicate<Port>(){
		public boolean  apply(Port input) { return input.getDir() == Direction.IN ; }
	};

	public IScope scope_Connection_p2(Connection ctx, EReference eRef)
	{
		EList<Port> features = ctx.getIn2().getType().getPorts();
		return scopeFor(Iterables.filter(features,rPortPred));
	}

	public IScope scope_Connection_p(Connection ctx, EReference eRef)
	{
		EList<Port> features = ctx.getIn2().getType().getPorts();
		return scopeFor(Iterables.filter(features,pPortPred));
	}

}

Note that the scopeFor helper takes away the work of creating the newly introduced IEObjectDescription that I struggled with at first. Once you know how, migrating seems not too bad.


				

MDSD Screencasts

16. Dezember 2009

Some of the screencasts explaining an MDSD showcase have just been published on my youtube site.

The introductory screencast to our showcase:

This video was embedded using the YouTuber plugin by Roy Tanck. Adobe Flash Player is required to view the video.

The screencast explaining Xtext in our showcase (in 3 parts):

This video was embedded using the YouTuber plugin by Roy Tanck. Adobe Flash Player is required to view the video.

This video was embedded using the YouTuber plugin by Roy Tanck. Adobe Flash Player is required to view the video.

This video was embedded using the YouTuber plugin by Roy Tanck. Adobe Flash Player is required to view the video.

And in addition, Markus Völter’s screencast explaining Variants, Feature Modeling and Model Transformation:

This video was embedded using the YouTuber plugin by Roy Tanck. Adobe Flash Player is required to view the video.

Enjoy!

Troubleshooting Web’N'Walk

20. Oktober 2009

Letzte Woche hat mein Web’N'Walk Stick von t-mobile aufgehört zu arbeiten. Auf Grund irgendeiner anderen Software waren wohl die Treiber zerschossen. Leider konnte ich bei t-mobile keinen Download für neue Treiber finden.

Mit ein bisschen Recherche fand ich folgende Lösung: Treiber für meinen Stick gibt’s bei www.option.com. Neu installiert, jetzt  tut wieder alles.

UML, good or bad?

27. September 2009

Via Adriano Comai I stumbled upon Ivar Jacobson’s article  “Taking the temperature of UML” , an interesting view of one of UML founders on the UML.  One of the important quotes is:

Still, UML has become complex and clumsy. For 80% of all software only 20% of UML is needed. However, it is not easy to find the subset of UML which we would call the “Essential” UML. We must make UML smarter to use.

There is a strong point in UML being too big. I have been following UML since its inception, having worked 10 years on one of the first UML tools, Software Through Pictures. Over the time, I have more and more been favouring (textual) DSLs. One of the reasons are the intrinsic problems of graphical  modelling, so one of the quotes I cannot really agree to:

There are a number of good and easy to use tools.

The situation has gotten much better, but graphical modeling tools are very complex to get right and I’d support the statement on one of the speakers on the german Architektour podcast that there are few tools that I really like, only tools that I dislike less. However, in project settings, there might be some influencing factors that make  UML and UML tooling is the best solution. If you understand german, most of the arguments pro and con UML that I’d use are mentioned on the Architektour podcast.

I like Pedro J. Molina’s article in his post “Using the 20% of UML”.

So I don’t think an “Essential UML” would be the right way to go. Time is better invested to find the right DSL for your domain.

Eclipse Summit Europe: Lightweight Model-Driven Development for Embedded Systems

16. September 2009

I am happy that the talk that Markus Völter and I submitted for the Eclipse Summit Europe 2009 has been accepted.

Wednesday, 14:20, 40 minutes | Room 6
Model driven development and code generation is relatively widespread in the development of embedded systems. However, usually, large and expensive UML-based real-time modeling tools are used, typically in conjunction with their own runtime environment. To make this approach scale down to smaller, more agile environments, a more lightweight and flexible approach is needed. In this talk, we show how the Textual Modeling Framework, the Xpand code generation engine and a couple of utilities for managing product line variability in models can be used to develop embedded systems. Architects develop their own domain specific language and code generator, to make sure the abstractions and the generated code fit their needs on the target platform. The talk uses a minimum of slides and is based mostly on a realistic example, showing the DSL, the code generator and the way we’ve built it. — Note: the attached slides are based on a related talk. They will be adapted slightly to fit the proposed session better. But the provide a realistic estimate for style, amount and content.

http://www.eclipsecon.org/summiteurope2009/sessions?id=854

Setting up Conversion of Xtend and UML datatypes in Galileo

17. August 2009

I was just trying to set up a M2M transformation from a textual DSL to UML2 with the Galileo release. Obviously, a lot of paths have changed from oAW to Galileo, so this needs some work. However, I had an error, that annoyed me. In the editor, everything was fine, no errors, but when running the workflow, the transformation had errors like:

EvaluationException : Couldn't find operation 'setName(String)' for uml::Class.
    torcssim::common::m2uml.ext[438,20] on line 23 'this.setName(c.name)'
    torcssim::common::m2uml.ext[315,16] on line 13 'x.components.c()'   
    nofile[0,23] on line 1 'toModel(model,umlmodel)'

It could not cast from an Xtend String to an UML String. The solution is in adding the meta-model to the component:

 <component class="org.eclipse.xtend.XtendComponent">
     <metaModel id="mm" class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>
     <metaModel class="org.eclipse.xtend.typesystem.uml2.UML2MetaModel"/>
     <invoke value="torcssim::common::m2uml::toModel(model,umlmodel)"/>
     <outputSlot value="transformedUMLModel"/>
    </component>

Which is quite obvious when you have done it once, but if you try to set it up the first time, it can cost you quite some time. Especially, when everything looks good in the editor.

UML Diagram Style Guides

5. August 2009

The UML-Taiwan Blog has several posts containing a style guide for UML diagrams. It turns out hat the posts are a chinese summary of “The Elements of UML 2.0 Style” by Scott Ambler. You can find excerpts of the book on Google’s book search. It has been on the market for several years - and it still is a book that I would recommend for modellers / tool designers. It contains a lot of good points on modelling / diagramming. But some points are arguable.

  • (#1) Depict crossing lines as a jump
    Good idea. But usually the user is stuck with the lacking support of the design tools. Tool designers, consider this!
  • (#3) Avoid Diagonal or Curved Lines
    In state machines curved lines actually can increase readability. This basically related to the tool capabilities. Layout with curved lines can look pretty good (have a look at the graphs done by Graphviz e.g.).
  • (#8) Don’t Indicate Exploding Bubbles
    The author argues that the “rake” symbol for indicating additional information is not necessary because the user is smart enough to double click for information. However, in my experience, it is nice to have such indicators in the design phase to be able to know which elements actually have additional information. It interrupts the workflow when you click on elements only to find empty information.
  • (#9) Minimize number of Bubble Types
    This should probably read “Minimize the number of bubbles / symbols”.
  • (#60) Imply timing considerations by stacking use cases
    I have actually done that with several tools and it as a valid approach. But it needs a big caveat: Beware that your vertical ordering might be of no relevance to your tool. The order of model elements e.g. in a report probably will not be influenced by the graphical layout and you might not be able to access it by any other means. This might cost some tool customizaion in your project.
  • (#25) Prefer Naming Conventions over Stereotypes:
    An effective alternative to applying a stereotype is to apply a naming convention. For example, instgead of applying the stereotype <<getter>> on an operation, you could simply start all getters with the text get, as you can see in Figure 5 with the getSeminarsTaken() operation. This simplifies your diagrams and increases the consistency of your source ocde.

This suggestion conflicts with the basic approach of MDSD:

  • Create abstract models
  • Create semantically rich models

The example given is not very good. You should not model infrastructure aspects in your domain model. The getter/setter-stuff is to be kept out of the model and should be added by M2M or M2T-Transformation later on.  Usually, these operations do not add any information to the model. You don’t want that, unless your code generator generates 1:1 from the model - but in that case you are not modeling, you are programming in UML diagrams (actually the book has guideline (#99) Do not model scaffolding code, which says just that. But having such an example early in the book is misleading.

In addition, expressing semantics by naming conventions is error-prone. Using modelling techniques just like stereotypes are semantically better and can be processed by transformation steps much easier.

  • (#25) Consider Using Color in your Diagrams

Color is a difficult topic in User interface design. It’s best to use it extremely sparingly for visual indications. In fact, Scott Ambler writes in one of his other books: “Color should be used sparingly in your applications and, if you do use it, you must also use a secondary indicator. The problem is that some of your users may be color blind and if you are using color to highlight something on a screen, then you need to do something else to make it stand out if you want these people to notice it.

文本特定域语言的比赛

31. Juli 2009

itemis 刚才开始了一个文本特定域语言的比赛 . Xtext 是 Textual Modeling Framework(TMF)项目的一个子项目,也是 Galileo 的一个新项目. 只需使用 Xtext 的简单 EBNF 语法描述 DSL,生成器就将创建一个解析器、一个 AST 元模型(使用 EMF 实现)以及一个功能丰富的 Eclipse 文本编辑器。

Vortrag auf der Embedded Software Engineering Kongress 2009 in Sindelfingen

31. Juli 2009

Wir halten am 10.Dezember 2009 um 16:00 Uhr einen Vortrag über die Einführung von MDSD in einem Projekt auf dem Embedded Software Engineering Kongress 2009 in Sindelfingen:

Textuelle domänenspezifische Sprachen sind ein starker Trend in der Software-Entwicklung.  Welche Lessons-Learned macht ein mittelständisches Unternehmen bei der Einführung von modellbasierter Software-Entwicklung für  Embedded Systems? In diesem Talk werden an Hand eines realen Projekts die Lessons Learned und die Vorteile des Einsatzes von textuellen domänenspezifischen Modellen auf Basis von Open Source-Tools erörtert.

Gerade im Embedded Bereich wird Modellierung noch mit ineffizienter Implementierung in Verbindung gebracht.  Mit neuen Modellierungstechniken ist dies jedoch nicht der Fall.

Die Referenten werden darüber sprechen, wie sich die Einführung auf Anforderungsmanagement,  Projektplanung, Design und Implementierung auswirken. Somit wird modellgetriebene Software-Entwicklung nicht nur vom technischen Standpunkt
der Werkzeuge betrachtet, sondern aus einer gesamthaften Projektsicht.

Die Teilnehmer erhalten Informationen über den praktischen Einsatz von textuellen DSLs, die sie in die Bewertung ihres eigenen Entwicklungsprozesses einbringen können. Da es sich um ein typisches Embedded-System handelt, zeigen wir, dass sich der Einsatz auch in kleineren Projekten und Systemen mit beschränkten Ressourcen lohnt.

Tom de Marco, Software Engineering is dead und Musterbrecher

29. Juli 2009

Für viel Diskussion in den Blogger-Welt sorgt ein Artikel von Tom de Marco, in dem er angeblich Software Engineering für tot erklärt:

http://www2.computer.org/cms/Computer.org/ComputingNow/homepage/2009/0709/rW_SO_Viewpoints.pdf

Dabei ist dieser Artikel im wesentlichen die englische Variante eines älteren deutschen Artikels:

http://www.sigs.de/publications/os/2008/06/interview_DeMarco_OS_06_08.pdf

Die Diskussion in den Blogs geht dabei m.M. nach oft an der Aussage des Artikels vorbei. Interessant ist jedoch zu sehen, wie divers doch die Ansichten auf die Software-Entwicklung noch sind: von wildem Hacken bis zu rigiden Prozessen.

Für mich ist das interessante Tom de Marco’s Reflexion über den “Missbrauch” seiner Konzepte. Es ist aus meiner Sicht immer wieder notwendig bekannte Muster zu überdenken und gegebenenfalls zu durchbrechen.

Interessant finde ich hierzu die Artikel von den “Musterbrechern”:

http://www.musterbrecher.de/index.php/kiosk/fachartikel

wie z.B.

http://www.musterbrecher.de/images/stories/kiosk/artikel/texte/2008/HR_Today_OsmetzKaduk_Musterbrecher_Nov08.pdf