Friday, August 14, 2009

Making xtext, eclipse and guice work together

There is a new entry in the xtext documentation dealing with enabling guice for your Xtext Editor.

This is pretty useful, though the same concept used to work before it only found its way into the documentation now. Hence I just wanted to share that information with you. Works really well.

<extension
point="org.eclipse.ui.editors">
<editor
class="<MyLanguageName>ExecutableExtensionFactory:
org.eclipse.xtext.ui.core.editor.XtextEditor"
contributorClass=
"org.eclipse.ui.editors.text.TextEditorActionContributor"
default="true"
extensions="ecoredsl"
id="org.eclipse.xtext.example.EcoreDsl"
name="EcoreDsl Editor">
</editor>
</extension>

Please not that MyLanguageName is actually the name of the factory you can find in your src folder of the UI-Project under your main package.

And now, if you'd like to write some ActionHandler for your xtext outline view, you can do just the same. Simply prefix the Handler class with the factory, and there you go!

Wednesday, August 12, 2009

Xtext 0.7.2 released, but...

I get

Cannot complete the install because one or more required items could not be found.
Software being installed: Xtext Runtime (Incubation) 0.7.2.v200908120607 (org.eclipse.xtext.runtime.feature.group 0.7.2.v200908120607)
Missing requirement: Xtext Generator (Incubation) 0.7.2.v200908120607 (org.eclipse.xtext.generator 0.7.2.v200908120607) requires 'bundle org.eclipse.xtend.util.stdlib 0.7.2' but it could not be found
Cannot satisfy dependency:
From: Xtext Runtime (Incubation) 0.7.2.v200908120607 (org.eclipse.xtext.runtime.feature.group 0.7.2.v200908120607)
To: org.eclipse.xtext.generator [0.7.2.v200908120607]



I will investigate that later.

Thursday, August 6, 2009

Setting up guice for xtext/TMF and parsing rules for validation

I am by no means a Guice expert, but here is a small code snippet which works for me, to setup TMF/xtext with guice. The main method may contain simple @Inject annotations to get your correct implementations injected.



public static void main(String[] args) {
BausteineStandaloneSetup setup = new BausteineStandaloneSetup();
setup.doSetup();
Injector injector = setup.createInjector();
Main main = injector.getInstance(Main.class);
main.write();
}

I currently use this to preparse arbitrary files which are not in my DSL and transform them. I do not want to rewrite particular checks for Rules, e.g. to verify if an ID is in the correct format, hence I just get the Parser injected and invoke the rule checking with a StringInputStream.
This looks roughly like this:



@Inject
private IAntlrParser parser;
@Inject
private BausteineGrammarAccess access;
...
InputStream inputStream = new StringInputStream("baustein " + name);
IParseResult result = parser.parse(access.getBausteinDefRule().getName(),inputStream);

There might be a more efficient way to do this, but currently I am quite happy with the solution. I guess I could try to use the lexer instead of the parser if I only want to check for terminals, but I need to extend the checks anyway.

Sunday, August 2, 2009

Lego Architecture


Available in the States: Lego Architecture
Shown in the picture is the Guggenheim Museum by Frank Llyod Wright.
Every great architect is — necessarily — a great poet. He must be a great original interpreter of his time, his day, his age.
Couldn't have said it better.