Karsten's Blog

April 26, 2012

xtext-utils unittesting 0.9.4 released

Filed under: Xtext — Tags: — kthoms @ 3:20 PM

I have just released the new version 0.9.4 of the xtext-utils unittesting framework. The release became necessary due to a too restrictive version constraint for Google Guice, which made the framework incompatible with the upcoming Xtext 2.3.0 release.

This little framework is a useful addition to Xtext which makes writing DSL tests quite easy. In my daily work on developing Xtext projects and coaching Xtext in workshops it became a useful tool which complements Xtext’s test support. It is not the only way to write tests for Xtext DSLs, but a real simple one. The main idea is that the best way to develop DSLs is to write prototype models. This framework allows you to read, parse, validate, format, serialize, and compare your models in a single line.

The framework can be installed from its update site.

April 17, 2012

Unofficial release 2.2.2 of the Xtend Maven Plugin

Filed under: Maven, Spray, Xtext — Tags: , , — kthoms @ 5:52 AM

In my previous post I showed how to use the maven-xtend-plugin to compile Xtend sources within a Maven build. This worked fine in simple cases, but there was a limitation of only one supported source directory (the one configured by build/sourceDirectory property), see Bug#367914. Unfortunately already each Xtext project has already 2 source folders (src and src-gen), so this made the plugin unusable for Xtext projects and forced checking in the generated Java files. This causes terrible problems with version control, especially when working on a team.

In the meantime Bug#367914 was resolved, but only for the upcoming Xtend 2.3 (Eclipse Juno) version. This urgent bugfix was not available on a Maven repository. But I needed it for project Spray to finally get rid of the merge conflicts and delete the generated sources from the repository (issue#94). Spray is still using Xtext/Xtend version 2.2.1 and depends on public available Maven artifacts. Since the bugfix won’t be available from the Xtend project for the 2.2.1 release and Eclipse Juno is still some way to go I decided to backport the current 2.3.0 M6 sources of the Xtend Maven Plugin to 2.2.x and create an unofficial version 2.2.2. This plugin I have deployed to the Fornax Repository to make it public available.

For an usage example refer to the POMs of project Spray: pom.xml, parent pom.xml.

April 3, 2012

JvmType import check

Filed under: Spray, Xtext — Tags: , — kthoms @ 1:47 PM

Several Xtext based DSLs will use import statements that import JvmTypes, be them real Java types, or just inferred types produced with your IJvmModelInferrer. The check for a valid import might be simple, but here it is to just make it even easier for you. I just had the need to realize this to resolve Spray issue#113. Basically you need to get the IJvmTypeProvider, to which you gain access through the IJvmTypeProvider.Factory.

public class SprayJavaValidator extends AbstractSprayJavaValidator implements IssueCodes {
    @Inject
    private IJvmTypeProvider.Factory typeProviderFactory;
    @Check
    public void checkImports(final Import imp) {
        // don't check wildcard imports
        if (imp.getImportedNamespace().endsWith(".*"))
            return;
        IJvmTypeProvider typeProvider = typeProviderFactory.findOrCreateTypeProvider(imp.eResource().getResourceSet());
        JvmType jvmType = typeProvider.findTypeByName(imp.getImportedNamespace());
        if (jvmType == null) {
            error("The import " + imp.getImportedNamespace() + " cannot be resolved", SprayPackage.Literals.IMPORT__IMPORTED_NAMESPACE, IMPORT_NOTEXISTS, new String[0]);
        }
    }
    ...
}

That’s all.

The Silver is the New Black Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 375 other followers