Home > Xtext > Xtext 2.0 and UML

Xtext 2.0 and UML

Consider you have some (Eclipse) UML2 models and now want to reference e.g. Classes from these model from your dsl. In this blog post i want to show a simple example what to do. We have to do two things: Provide an IResourceServiceProvider for .uml resources and reference the UML class from the grammar.

So first we write the grammar. that is quite easy

grammar org.xtext.example.umldsl.UmlDsl with org.eclipse.xtext.common.Terminals

import "http://www.eclipse.org/uml2/3.0.0/UML" as uml
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

generate umlDsl "http://www.xtext.org/example/umldsl/UmlDsl"

Model:
	elements+=Element*
;

Element:
	"element" name=ID "mapsTo" ref=[uml::Class|FQN]
;

FQN returns ecore::EString:
	ID ("." ID)*
;

Then we have to add some stuff to the Language workflow to get the stuff running

module org.xtext.example.umldsl.GenerateUmlDsl

import org.eclipse.emf.mwe.utils.*
import org.eclipse.xtext.generator.*
import org.eclipse.xtext.ui.generator.*

var grammarURI = "classpath:/org/xtext/example/umldsl/UmlDsl.xtext"
var file.extensions = "umldsl"
var projectName = "org.xtext.example.umldsl"
var runtimeProject = "../${projectName}"

Workflow {
    bean = StandaloneSetup {
        scanClassPath = true
        platformUri = "${runtimeProject}/.."
        uriMap = {
			from = "platform:/plugin/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel"
			to = "platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel"
		}
		uriMap = {
			from = "platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel"
			to = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel"
		}
		uriMap = {
			from = "platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel"
			to = "platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel"
		}
		uriMap = {
			from = "platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel"
			to = "platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel"
		}
		uriMap = {
			from = "platform:/plugin/org.eclipse.emf.codegen.ecore/model/GenModel.ecore"
			to = "platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.ecore"
		}
		uriMap = {
			from = "platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore"
			to = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore"
		}
		uriMap = {
			from = "platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore"
			to = "platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore"
		}
		uriMap = {
			from = "platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore"
			to = "platform:/resource/org.eclipse.uml2.uml/model/UML.ecore"
		}
		//
        registerGeneratedEPackage = "org.eclipse.emf.ecore.EcorePackage"
        registerGeneratedEPackage = "org.eclipse.uml2.uml.UMLPackage"
        registerGeneratedEPackage = "org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage"
        registerGeneratedEPackage = "org.eclipse.uml2.codegen.ecore.genmodel.GenModelPackage"
        registerGenModelFile = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel"
        registerGenModelFile = "platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel"
        registerGenModelFile = "platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel"
        registerGenModelFile = "platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel"

    }

    ...
}

We add some extra deps to the manifest

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.xtext.example.umldsl
Bundle-Vendor: My Company
Bundle-Version: 1.0.0
Bundle-SymbolicName: org.xtext.example.umldsl; singleton:=true
Bundle-ActivationPolicy: lazy
Require-Bundle: org.eclipse.xtext;bundle-version="2.0.0";visibility:=reexport,
 org.apache.log4j;bundle-version="1.2.15";visibility:=reexport,
 org.apache.commons.logging;bundle-version="1.0.4";resolution:=optional;visibility:=reexport,
 org.eclipse.xtext.generator;resolution:=optional,
 org.eclipse.emf.codegen.ecore;resolution:=optional,
 org.eclipse.emf.mwe.utils;resolution:=optional,
 org.eclipse.emf.mwe2.launch;resolution:=optional,
 org.eclipse.uml2.uml;bundle-version="3.2.0",
 org.eclipse.xtext.util,
 org.eclipse.emf.ecore,
 org.eclipse.emf.common,
 org.antlr.runtime,
 org.eclipse.xtext.common.types,
 org.eclipse.uml2.codegen.ecore;bundle-version="1.7.0"
Import-Package: org.apache.log4j,
 org.apache.commons.logging,
 org.eclipse.xtext.xbase.lib,
 org.eclipse.xtext.xtend2.lib
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.xtext.example.umldsl,
 org.xtext.example.umldsl.services,
 org.xtext.example.umldsl.umlDsl,
 org.xtext.example.umldsl.umlDsl.impl,
 org.xtext.example.umldsl.umlDsl.util,
 org.xtext.example.umldsl.serializer,
 org.xtext.example.umldsl.parser.antlr,
 org.xtext.example.umldsl.parser.antlr.internal,
 org.xtext.example.umldsl.validation

and generate the Language. If we now run a runtime application and create a .uml file and a .umlmodel file
we see nothing since the uml stuff is not yet referenceable

So the second with we create is a  IResourceServiceProvider . Therefore we take the plugins org.eclipse.xtext.ecore and org.eclipse.xtext.ui.ecore, that do the same for .ecore files, as inspiration.

So we create the plugins org.eclipse.xtext.uml and org.eclipse.xtext.ui.uml with following content:

The UmlResourceDescriptionStrategy customizes the creation of IEObjectDescriptions. This is the stuff that Xtext puts into the index and maps a Name to an EObject or Proxy. In our case we simply subclass from the default and do no further customizations.

package org.eclipse.xtext.uml;

import org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy;

public class UmlResourceDescriptionStrategy extends DefaultResourceDescriptionStrategy {

}

The UmlQualifiedNameProvider gives our UML Stuff a fully qualified name – we take the defaults here too

package org.eclipse.xtext.uml;

import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;

public class UmlQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider {

}

Then we have to create a Guice Module to Glue the stuff

package org.eclipse.xtext.uml;

import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy;
import org.eclipse.xtext.resource.generic.AbstractGenericResourceRuntimeModule;

public class UmlRuntimeModule extends AbstractGenericResourceRuntimeModule {

	@Override
	protected String getLanguageName() {
		return "org.eclipse.uml2.uml.editor.presentation.UMLEditorID";
	}

	@Override
	protected String getFileExtensions() {
		return "uml";
	}

	public Class<? extends IDefaultResourceDescriptionStrategy> bindIDefaultResourceDescriptionStrategy() {
		return UmlResourceDescriptionStrategy.class;
	}

	@Override
	public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
		return UmlQualifiedNameProvider.class;
	}

}

If we want to use this stuff from an mwe(2) workflow we have to create a Support-Class for this too

package org.eclipse.xtext.uml;

import org.eclipse.xtext.resource.generic.AbstractGenericResourceSupport;

import com.google.inject.Module;

public class UmlSupport extends AbstractGenericResourceSupport {

	@Override
	protected Module createGuiceModule() {
		return new UmlRuntimeModule();
	}

}

Finally we add some stuff to the manifest and we’re done with the runtime stuff

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Uml
Bundle-SymbolicName: org.eclipse.xtext.uml
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.xtext;bundle-version="2.0.0",
 org.eclipse.uml2.uml;bundle-version="3.2.0"
Export-Package: org.eclipse.xtext.uml

Then we have to do some stuff at the ui side too.

We create some glue code (Activator, ExecutableExtensionFactory (to be able to use guice in the plugin.xml) and an UiModule)

/*******************************************************************************
 * Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.xtext.ui.uml;

import org.apache.log4j.Logger;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.xtext.ui.shared.SharedStateModule;
import org.eclipse.xtext.uml.UmlRuntimeModule;
import org.osgi.framework.BundleContext;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.util.Modules;

/**
 * The activator class controls the plug-in life cycle
 */
public class Activator extends AbstractUIPlugin {

	private static final Logger logger = Logger.getLogger(Activator.class);

	// The plug-in ID
	public static final String PLUGIN_ID = "org.eclipse.xtext.ui.uml"; //$NON-NLS-1$

	// The shared instance
	private static Activator plugin;

	private Injector injector;

	/**
	 * The constructor
	 */
	public Activator() {
	}

	public Injector getInjector() {
		return injector;
	}

	private void initializeEcoreInjector() {
		injector = Guice.createInjector(
				Modules.override(Modules.override(new UmlRuntimeModule())
				.with(new UmlUiModule(plugin)))
				.with(new SharedStateModule()));
	}

	@Override
	public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;
		try {
			initializeEcoreInjector();
		} catch(Exception e) {
			logger.error(e.getMessage(), e);
			throw e;
		}
	}

	@Override
	public void stop(BundleContext context) throws Exception {
		plugin = null;
		injector = null;
		super.stop(context);
	}

	/**
	 * Returns the shared instance
	 *
	 * @return the shared instance
	 */
	public static Activator getDefault() {
		return plugin;
	}

}

 

/*******************************************************************************
 * Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.xtext.ui.uml;

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.xtext.ui.LanguageSpecific;
import org.eclipse.xtext.ui.editor.IURIEditorOpener;
import org.eclipse.xtext.ui.resource.generic.EmfUiModule;

public class UmlUiModule extends EmfUiModule {

	public UmlUiModule(AbstractUIPlugin plugin) {
		super(plugin);
	}

	@Override
	public void configureLanguageSpecificURIEditorOpener(com.google.inject.Binder binder) {
		binder.bind(IURIEditorOpener.class).annotatedWith(LanguageSpecific.class).to(UmlEditorOpener.class);
	}

}

 

/*******************************************************************************
 * Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.xtext.ui.uml;

import org.eclipse.xtext.ui.guice.AbstractGuiceAwareExecutableExtensionFactory;
import org.osgi.framework.Bundle;

import com.google.inject.Injector;

public class ExecutableExtensionFactory extends AbstractGuiceAwareExecutableExtensionFactory {

	@Override
	protected Bundle getBundle() {
		return Activator.getDefault().getBundle();
	}

	@Override
	protected Injector getInjector() {
		return Activator.getDefault().getInjector();
	}

}

Of course we want to UML Editor to open smoothly if we click on an element referenced from UML too so we create an LanguageSpecificURIEditorOpener too

/*******************************************************************************
 * Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.xtext.ui.uml;

import java.util.Collections;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.ui.IEditorPart;
import org.eclipse.xtext.ui.editor.LanguageSpecificURIEditorOpener;
import org.eclipse.uml2.uml.editor.presentation.UMLEditor;

public class UmlEditorOpener extends LanguageSpecificURIEditorOpener {

	@Override
	protected void selectAndReveal(IEditorPart openEditor, URI uri,
			EReference crossReference, int indexInList, boolean select) {
		UMLEditor umlEditor = (UMLEditor) openEditor.getAdapter(UMLEditor.class);
		if (umlEditor != null) {
			EObject eObject = umlEditor.getEditingDomain().getResourceSet().getEObject(uri, true);
			umlEditor.setSelectionToViewer(Collections.singletonList(eObject));
		}
	}

}

we add some deps to the manifest

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Uml
Bundle-SymbolicName: org.eclipse.xtext.ui.uml;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.uml2.uml.editor;bundle-version="3.1.100",
 org.eclipse.xtext.uml;bundle-version="1.0.0",
 org.eclipse.xtext.ui;bundle-version="2.0.0",
 org.eclipse.xtext.ui.shared;bundle-version="2.0.0"
Import-Package: org.apache.log4j;version="1.2.15"
Bundle-Activator: org.eclipse.xtext.ui.uml.Activator
Bundle-ActivationPolicy: lazy

And finally register our resource service provider to the extensionpoint Xtext offers for that.

<!--?xml version="1.0" encoding="UTF-8"?-->
<!--?eclipse version="3.4"?-->
<plugin>
	<extension
	      point="org.eclipse.xtext.extension_resourceServiceProvider">
	    <resourceServiceProvider
	          class="org.eclipse.xtext.ui.uml.ExecutableExtensionFactory:org.eclipse.xtext.ui.resource.generic.EmfResourceUIServiceProvider"
	          uriExtension="uml">
	    </resourceServiceProvider>
	</extension>

</plugin>

We restart our runtime application, and TATATATA: it works ;-)

About these ads
Categories: Xtext
  1. kthoms
    July 18, 2011 at 06:28 | #1

    Great, Christian! Would you mind if I take the sources to xtext-utils, or do you have another place to publish them outside this blog post?

    ~Karsten

  2. Laurent
    July 18, 2011 at 18:52 | #3

    Great job! Tank you for sharing it !

  3. Arnaud
    July 22, 2011 at 15:10 | #4

    Hello and thank you for this post !!!

    This is working under eclipse but not in Standalone mode. Is it normal ?
    Thank you for your answer

    • July 22, 2011 at 15:20 | #5

      Hi,

      that is what the UmlSupport class is for ;-) Include it in your workflow.
      or call preInvoke on an instance from a java class

      ~Christian

      • Huy Trần
        December 23, 2011 at 02:35 | #6

        Hi Christian,

        Many thanks for your excellent post. I just followed and successfully made a working DSL editor that allows references to the elements of an external EMF model. Unfortunately, when I use the MWE2 workflow with the org.eclipse.xtext.mwe.Reader component to load the Xtext DSLs (with external refs), it says “Couldn’t resolve reference to ABC”.
        I suppose the XXXSupport class (e.g., UmlSupport) you mentioned can be the solution for this case but I did not know where to add this info in the workflow. Many thanks in advance for your suggestions.
        MfG,Huy.

      • December 27, 2011 at 23:36 | #7

        simply add it (before the reader) component = x.y.z.XYZSupport{}

      • Joshi
        April 22, 2012 at 19:27 | #8

        I got this to work in eclipse. But not with the XtextRunner-JUnit-Testcases.
        Where do i have to put the new xxxSupport().register()?

      • April 22, 2012 at 19:50 | #9

        simply calling it in an @Before method doesnt work?

      • Joshi
        April 23, 2012 at 03:22 | #10

        Shouldn’t it be done while firing up the “infrastructure”? So that other User of my Dsl-SDK don’t have to worry…

      • April 23, 2012 at 05:26 | #11

        Hi,

        your users need to know that they have to call the YourDslStandaloneSetup as well.

        I do not know your SDK and its usage scenarios so it is hard to tell what todo and what not. so what about documenting this?

        maybe you can add it to your dsls standalone setup (override the register method) as well but since the resource service provider is idependent from your dsl this is dirty imho.

  4. Arnaud
    July 23, 2011 at 12:26 | #12

    It’s working perfectly !!! Thank you very much for your answer !!!

  5. Oliveira
    September 16, 2011 at 01:15 | #13

    Hi Christian,

    Excellent stuff!
    Just a quick point. Did you use the XText Project wizard?
    I’m asking that because you seem to have two projects
    – org.xtext.example.umldsl.UmlDsl
    – org.eclipse.xtext.ui.uml

    Is that so?
    cheers

  6. October 5, 2011 at 15:48 | #15

    Hi Chistian,

    This post is very interesting and util. I have started with xtext and your Blog has been a great help.

    I hope you keep updating.

  7. Huy Trần
    December 28, 2011 at 13:53 | #16

    Christian Dietrich :
    simply add it (before the reader) component = x.y.z.XYZSupport{}

    You’re right. Many thanks.

  8. Stefan
    December 10, 2012 at 14:21 | #17

    I have a problem when I try to run MWE workflow file.
    I get error:
    Could not find a GenModel for EPackage ‘http://www.mycompany.org/MyLang’

    I have included all proper stuff into workflow and manifest files,
    and even import in my grammar works:
    import “http://www.eclipse.org/uml2/4.0.0/UML” as uml

    However, as soon as I define reference to some UML type in my grammar rules,
    I get the error.

    I have also created uml and ui projects, and added the as extensions to my project,
    but I guess this later steps are not related to my issue..

    Please help :)
    Best, Stefan

  9. Stefan
    December 10, 2012 at 15:56 | #19

    XTEXT FILE:

    grammar org.modelexecution.fumltesting.FumlTestLang with org.eclipse.xtext.common.Terminals

    import “http://www.eclipse.org/emf/2002/Ecore” as ecore
    import “http://www.eclipse.org/uml2/4.0.0/UML” as uml

    generate fumlTestLang “http://www.modelexecution.org/fumltesting/FumlTestLang”

    TestSuite:
    (tests+=TestCase)*
    ;

    TestCase returns TestCase:
    ‘test’ name=ID ‘activity’ //activityUnderTest=ActivityUnderTest ‘{}’
    ;

    //ActivityUnderTest:
    // ref=[uml::Activity]
    //;

    MWE WORKFLOW FILE:

    module org.modelexecution.fumltesting.GenerateFumlTestLang

    import org.eclipse.emf.mwe.utils.*
    import org.eclipse.xtext.generator.*
    import org.eclipse.xtext.ui.generator.*

    var grammarURI = “classpath:/org/modelexecution/fumltesting/FumlTestLang.xtext”
    var file.extensions = “fumltest”
    var projectName = “org.modelexecution.fumltesting.fumltestlang”
    var runtimeProject = “../${projectName}”

    Workflow {
    bean = StandaloneSetup {
    scanClassPath = true
    platformUri = “${runtimeProject}/..”

    // The following two lines can be removed, if Xbase is not used.
    registerGeneratedEPackage = “org.eclipse.xtext.xbase.XbasePackage”
    registerGenModelFile = “platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel”

    registerGeneratedEPackage = “org.eclipse.emf.ecore.EcorePackage”
    registerGeneratedEPackage = “org.eclipse.uml2.uml.UMLPackage”
    registerGeneratedEPackage = “org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage”
    registerGeneratedEPackage = “org.eclipse.uml2.codegen.ecore.genmodel.GenModelPackage”
    registerGenModelFile = “platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel”
    registerGenModelFile = “platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel”
    registerGenModelFile = “platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel”
    registerGenModelFile = “platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel”

    //In order to be able to refer to UML models from the language
    uriMap = {
    from = “platform:/plugin/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel”
    to = “platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel”
    }
    uriMap = {
    from = “platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel”
    to = “platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel”
    }
    uriMap = {
    from = “platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel”
    to = “platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel”
    }
    uriMap = {
    from = “platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel”
    to = “platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel”
    }
    uriMap = {
    from = “platform:/plugin/org.eclipse.emf.codegen.ecore/model/GenModel.ecore”
    to = “platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.ecore”
    }
    uriMap = {
    from = “platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore”
    to = “platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore”
    }
    uriMap = {
    from = “platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore”
    to = “platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore”
    }
    uriMap = {
    from = “platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore”
    to = “platform:/resource/org.eclipse.uml2.uml/model/UML.ecore”
    }
    }
    //….
    }

    And I also added stuff from tutorial into manifest file..
    When I remove comments from last part of xtext file I get the aforementioned error ..
    Thanks..

    • December 10, 2012 at 16:01 | #20

      Hi I still don’t see where the mylang stuff comes from do you have somewhere a package with that nsuri

  10. Stefan
    December 10, 2012 at 16:06 | #21

    The exact error is:
    java.lang.RuntimeException: Could not find a GenModel for EPackage ‘http://www.modelexecution.org/fumltesting/FumlTestLang’ from http://www.modelexecution.org/fumltesting/FumlTestLang

  11. Stefan
    December 10, 2012 at 16:18 | #23

    I am not sure I understand :( I am new to Xtext and especially with combining DSL with UML. Anyway, I did all as in tutorial from scratch.. I have no gemodel or ecore metamodel for my language, I was only creating grammar from scratch..

  12. Stefan
    December 10, 2012 at 16:21 | #25

    This is the whole workflow:

    module org.modelexecution.fumltesting.GenerateFumlTestLang

    import org.eclipse.emf.mwe.utils.*
    import org.eclipse.xtext.generator.*
    import org.eclipse.xtext.ui.generator.*

    var grammarURI = “classpath:/org/modelexecution/fumltesting/FumlTestLang.xtext”
    var file.extensions = “fumltest”
    var projectName = “org.modelexecution.fumltesting.fumltestlang”
    var runtimeProject = “../${projectName}”

    Workflow {
    bean = StandaloneSetup {
    scanClassPath = true
    platformUri = “${runtimeProject}/..”

    // The following two lines can be removed, if Xbase is not used.
    registerGeneratedEPackage = “org.eclipse.xtext.xbase.XbasePackage”
    registerGenModelFile = “platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel”

    registerGeneratedEPackage = “org.eclipse.emf.ecore.EcorePackage”
    registerGeneratedEPackage = “org.eclipse.uml2.uml.UMLPackage”
    registerGeneratedEPackage = “org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage”
    registerGeneratedEPackage = “org.eclipse.uml2.codegen.ecore.genmodel.GenModelPackage”
    registerGenModelFile = “platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel”
    registerGenModelFile = “platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel”
    registerGenModelFile = “platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel”
    registerGenModelFile = “platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel”

    //In order to be able to refer to UML models from the language
    uriMap = {
    from = “platform:/plugin/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel”
    to = “platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel”
    }
    uriMap = {
    from = “platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel”
    to = “platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel”
    }
    uriMap = {
    from = “platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel”
    to = “platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel”
    }
    uriMap = {
    from = “platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel”
    to = “platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel”
    }
    uriMap = {
    from = “platform:/plugin/org.eclipse.emf.codegen.ecore/model/GenModel.ecore”
    to = “platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.ecore”
    }
    uriMap = {
    from = “platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore”
    to = “platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore”
    }
    uriMap = {
    from = “platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore”
    to = “platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore”
    }
    uriMap = {
    from = “platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore”
    to = “platform:/resource/org.eclipse.uml2.uml/model/UML.ecore”
    }
    }

    component = DirectoryCleaner {
    directory = “${runtimeProject}/src-gen”
    }

    component = DirectoryCleaner {
    directory = “${runtimeProject}.ui/src-gen”
    }

    component = Generator {
    pathRtProject = runtimeProject
    pathUiProject = “${runtimeProject}.ui”
    pathTestProject = “${runtimeProject}.tests”
    projectNameRt = projectName
    projectNameUi = “${projectName}.ui”
    language = {
    uri = grammarURI
    fileExtensions = file.extensions

    // Java API to access grammar elements (required by several other fragments)
    fragment = grammarAccess.GrammarAccessFragment {}

    // generates Java API for the generated EPackages
    fragment = ecore.EcoreGeneratorFragment {
    // referencedGenModels = ”
    // platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel,
    // platform:/resource/org.eclipse.xtext.common.types/model/JavaVMTypes.genmodel
    // ”
    }

    // Serializer 2.0
    fragment = serializer.SerializerFragment {
    generateStub = false
    }

    // the serialization component (1.0)
    // fragment = parseTreeConstructor.ParseTreeConstructorFragment {}

    // a custom ResourceFactory for use with EMF
    fragment = resourceFactory.ResourceFactoryFragment {
    fileExtensions = file.extensions
    }

    // The antlr parser generator fragment.
    fragment = parser.antlr.XtextAntlrGeneratorFragment {
    // options = {
    // backtrack = true
    // }
    }

    // java-based API for validation
    fragment = validation.JavaValidatorFragment {
    // composedCheck = “org.eclipse.xtext.validation.ImportUriValidator”
    // composedCheck = “org.eclipse.xtext.validation.NamesAreUniqueValidator”
    }

    // scoping and exporting API
    // fragment = scoping.ImportURIScopingFragment {}
    // fragment = exporting.SimpleNamesFragment {}

    // scoping and exporting API
    fragment = scoping.ImportNamespacesScopingFragment {}
    fragment = exporting.QualifiedNamesFragment {}
    fragment = builder.BuilderIntegrationFragment {}

    // generator API
    fragment = generator.GeneratorFragment {
    generateMwe = false
    generateJavaMain = false
    }

    // formatter API
    fragment = formatting.FormatterFragment {}

    // labeling API
    fragment = labeling.LabelProviderFragment {}

    // outline API
    fragment = outline.OutlineTreeProviderFragment {}
    fragment = outline.QuickOutlineFragment {}

    // quickfix API
    fragment = quickfix.QuickfixProviderFragment {}

    // content assist API
    fragment = contentAssist.JavaBasedContentAssistFragment {}

    // generates a more lightweight Antlr parser and lexer tailored for content assist
    fragment = parser.antlr.XtextAntlrUiGeneratorFragment {}

    // generates junit test support classes into Generator#pathTestProject
    fragment = junit.Junit4Fragment {}

    // project wizard (optional)
    // fragment = projectWizard.SimpleProjectWizardFragment {
    // generatorProjectName = “${projectName}”
    // modelFileExtension = file.extensions
    // }

    // rename refactoring
    fragment = refactoring.RefactorElementNameFragment {}

    // provides the necessary bindings for java types integration
    fragment = types.TypesGeneratorFragment {}

    // generates the required bindings only if the grammar inherits from Xbase
    fragment = xbase.XbaseGeneratorFragment {}

    // provides a preference page for template proposals
    fragment = templates.CodetemplatesGeneratorFragment {}

    // provides a compare view
    fragment = compare.CompareFragment {
    fileExtensions = file.extensions
    }

    }
    }
    }

  13. Stefan
  14. Stefan
    December 10, 2012 at 18:25 | #29

    uncomment the last 3 lines in xtext file

    • December 10, 2012 at 18:53 | #30

      I did that
      (1) try a new project
      (2) make sure you have deps (uml …) installed.
      TestCase returns TestCase:
      ‘test’ name=ID ‘activity’ activityUnderTest=ActivityUnderTest ‘{}’
      ;
      ActivityUnderTest:
      ref=[uml::Activity]
      ;

  15. Stefan
    December 11, 2012 at 09:53 | #31

    I tried but it still doesn’t work. I will see what can I do about it, I have to make it work, thanks for help anyway! :)

  16. Stefan
    December 11, 2012 at 11:10 | #32

    Can you please tell me which Eclipse version are you using? I have installed Eclipse Juno SR1 and installed Xtext using Eclipse Modeling Components Discovery. I think that I have all dependencies installed and registered in manifest file.

  17. Stefan
    December 11, 2012 at 13:57 | #34

    Could you share your installation of Eclipse on dropbox, if I am not asking too much :)

    • December 11, 2012 at 14:00 | #35

      I have no strong inet during the week. WhichOS do you have. BTW did you try it with the distro I mentioned?

  18. Stefan
    December 11, 2012 at 14:04 | #36

    I have Windows 7 32bit – I have installed Eclipse Juno and Xtext 2.3.1. I also checked and I have UML 4.0.1. installed by default in eclipse distro (EMF version) and somehow it simply doesn’t work, and I tried to install from update site and many other combinations, and starting to lose faith.. :(

  19. Stefan
    December 11, 2012 at 14:24 | #39

    I have downloaded distro from xtext site and installed UML plugin from here: http://www.eclipse.org/downloads/download.php?file=/modeling/mdt/uml2/downloads/drops/4.0.1/R201209131441/mdt-uml2-Update-4.0.1.zip into it, and it still gives me the same error when I run MWE file. I import the project into workspace from zip file I have put into dropbox..

    • December 11, 2012 at 18:42 | #40

      Hi can you please post the complete workflow log

      • Stefan
        December 11, 2012 at 18:44 | #41

        0 [main] INFO lipse.emf.mwe.utils.StandaloneSetup – Registering platform uri ‘C:\eclipse_juno\workspace’
        90 [main] INFO lipse.emf.mwe.utils.StandaloneSetup – Adding generated EPackage ‘org.eclipse.xtext.xbase.XbasePackage’
        222 [main] INFO clipse.emf.mwe.utils.GenModelHelper – Registered GenModel ‘http://www.eclipse.org/Xtext/Xbase/XAnnotations’ from ‘platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel’
        223 [main] INFO clipse.emf.mwe.utils.GenModelHelper – Registered GenModel ‘http://www.eclipse.org/xtext/xbase/Xtype’ from ‘platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel’
        228 [main] INFO clipse.emf.mwe.utils.GenModelHelper – Registered GenModel ‘http://www.eclipse.org/xtext/xbase/Xbase’ from ‘platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel’
        228 [main] INFO clipse.emf.mwe.utils.GenModelHelper – Registered GenModel ‘http://www.eclipse.org/xtext/common/JavaVMTypes’ from ‘platform:/resource/org.eclipse.xtext.common.types/model/JavaVMTypes.genmodel’
        229 [main] INFO lipse.emf.mwe.utils.StandaloneSetup – Adding generated EPackage ‘org.eclipse.emf.ecore.EcorePackage’
        626 [main] INFO lipse.emf.mwe.utils.StandaloneSetup – Adding generated EPackage ‘org.eclipse.uml2.uml.UMLPackage’
        626 [main] INFO lipse.emf.mwe.utils.StandaloneSetup – Adding generated EPackage ‘org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage’
        640 [main] INFO lipse.emf.mwe.utils.StandaloneSetup – Adding generated EPackage ‘org.eclipse.uml2.codegen.ecore.genmodel.GenModelPackage’
        654 [main] INFO clipse.emf.mwe.utils.GenModelHelper – Registered GenModel ‘http://www.eclipse.org/emf/2002/Ecore’ from ‘platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel’
        667 [main] INFO clipse.emf.mwe.utils.GenModelHelper – Registered GenModel ‘http://www.eclipse.org/emf/2002/GenModel’ from ‘platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel’
        864 [main] INFO clipse.emf.mwe.utils.GenModelHelper – Registered GenModel ‘http://www.eclipse.org/uml2/4.0.0/UML’ from ‘platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel’
        869 [main] INFO clipse.emf.mwe.utils.GenModelHelper – Registered GenModel ‘http://www.eclipse.org/uml2/2.2.0/GenModel’ from ‘platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel’
        870 [main] INFO lipse.emf.mwe.utils.StandaloneSetup – Adding URI mapping from ‘platform:/plugin/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel’ to ‘platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel’
        870 [main] INFO lipse.emf.mwe.utils.StandaloneSetup – Adding URI mapping from ‘platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel’ to ‘platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel’
        871 [main] INFO lipse.emf.mwe.utils.StandaloneSetup – Adding URI mapping from ‘platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel’ to ‘platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel’
        871 [main] INFO lipse.emf.mwe.utils.StandaloneSetup – Adding URI mapping from ‘platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel’ to ‘platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel’
        871 [main] INFO lipse.emf.mwe.utils.StandaloneSetup – Adding URI mapping from ‘platform:/plugin/org.eclipse.emf.codegen.ecore/model/GenModel.ecore’ to ‘platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.ecore’
        871 [main] INFO lipse.emf.mwe.utils.StandaloneSetup – Adding URI mapping from ‘platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore’ to ‘platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore’
        871 [main] INFO lipse.emf.mwe.utils.StandaloneSetup – Adding URI mapping from ‘platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore’ to ‘platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore’
        872 [main] INFO lipse.emf.mwe.utils.StandaloneSetup – Adding URI mapping from ‘platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore’ to ‘platform:/resource/org.eclipse.uml2.uml/model/UML.ecore’
        1325 [main] INFO ipse.emf.mwe.utils.DirectoryCleaner – Cleaning C:\eclipse_juno\workspace\org.modelexecution.fumltesting.fumltestlang\..\org.modelexecution.fumltesting.fumltestlang\src-gen
        1340 [main] INFO ipse.emf.mwe.utils.DirectoryCleaner – Cleaning C:\eclipse_juno\workspace\org.modelexecution.fumltesting.fumltestlang\..\org.modelexecution.fumltesting.fumltestlang.ui\src-gen
        1417 [main] INFO ipse.xtext.generator.LanguageConfig – generating infrastructure for org.modelexecution.fumltesting.FumlTestLang with fragments : ImplicitRuntimeFragment, ImplicitUiFragment, GrammarAccessFragment, EcoreGeneratorFragment, SerializerFragment, ResourceFactoryFragment, XtextAntlrGeneratorFragment, JavaValidatorFragment, ImportNamespacesScopingFragment, QualifiedNamesFragment, BuilderIntegrationFragment, GeneratorFragment, FormatterFragment, LabelProviderFragment, OutlineTreeProviderFragment, QuickOutlineFragment, QuickfixProviderFragment, JavaBasedContentAssistFragment, XtextAntlrUiGeneratorFragment, Junit4Fragment, RefactorElementNameFragment, TypesGeneratorFragment, XbaseGeneratorFragment, CodetemplatesGeneratorFragment, CompareFragment
        java.lang.NullPointerException
        at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.getGenPackagesForPackages(EcoreGeneratorFragment.java:481)
        at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.reconcileMissingGenPackagesInUsedModels(EcoreGeneratorFragment.java:693)
        at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.getSaveAndReconcileGenModel(EcoreGeneratorFragment.java:676)
        at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.generate(EcoreGeneratorFragment.java:221)
        at org.eclipse.xtext.generator.CompositeGeneratorFragment.generate(CompositeGeneratorFragment.java:92)
        at org.eclipse.xtext.generator.LanguageConfig.generate(LanguageConfig.java:113)
        at org.eclipse.xtext.generator.Generator.generate(Generator.java:361)
        at org.eclipse.xtext.generator.Generator.invokeInternal(Generator.java:128)
        at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
        at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
        at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
        at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)
        at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:102)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:62)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
        2599 [main] ERROR enerator.CompositeGeneratorFragment – Could not find a GenModel for EPackage ‘http://www.modelexecution.org/fumltesting/FumlTestLang’ from http://www.modelexecution.org/fumltesting/FumlTestLang
        If the missing GenModel has been generated via EcoreGeneratorFragment make sure to run it first in the workflow.
        If you have a *.genmodel-file, make sure to register it via StandaloneSetup.registerGenModelFile(String)
        java.lang.RuntimeException: Could not find a GenModel for EPackage ‘http://www.modelexecution.org/fumltesting/FumlTestLang’ from http://www.modelexecution.org/fumltesting/FumlTestLang
        If the missing GenModel has been generated via EcoreGeneratorFragment make sure to run it first in the workflow.
        If you have a *.genmodel-file, make sure to register it via StandaloneSetup.registerGenModelFile(String)
        at org.eclipse.xtext.generator.GenModelAccess.getGenModelResource(GenModelAccess.java:119)
        at org.eclipse.xtext.generator.GenModelAccess.getGenPackage(GenModelAccess.java:85)
        at org.eclipse.xtext.generator.serializer.JavaEMFFile.importedGenTypeName(JavaEMFFile.java:100)
        at org.eclipse.xtext.generator.serializer.JavaEMFFile.importedGenTypeLiteral(JavaEMFFile.java:69)
        at org.eclipse.xtext.generator.serializer.AbstractSemanticSequencer.genMethodCreateSequence(AbstractSemanticSequencer.java:305)
        at org.eclipse.xtext.generator.serializer.AbstractSemanticSequencer.getFileContents(AbstractSemanticSequencer.java:217)
        at org.eclipse.xtext.generator.serializer.SerializerFragment.generate(SerializerFragment.java:92)
        at org.eclipse.xtext.generator.Xtend2GeneratorFragment.generate(Xtend2GeneratorFragment.java:66)
        at org.eclipse.xtext.generator.Xtend2GeneratorFragment.generate(Xtend2GeneratorFragment.java:59)
        at org.eclipse.xtext.generator.CompositeGeneratorFragment.generate(CompositeGeneratorFragment.java:92)
        at org.eclipse.xtext.generator.LanguageConfig.generate(LanguageConfig.java:113)
        at org.eclipse.xtext.generator.Generator.generate(Generator.java:361)
        at org.eclipse.xtext.generator.Generator.invokeInternal(Generator.java:128)
        at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
        at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
        at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
        at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)
        at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:102)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:62)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
        3122 [main] INFO or.validation.JavaValidatorFragment – generating Java-based EValidator API
        3666 [main] INFO text.generator.junit.Junit4Fragment – generating Junit4 Test support classes
        3676 [main] INFO text.generator.junit.Junit4Fragment – generating Compare Framework infrastructure
        3761 [main] INFO .emf.mwe2.runtime.workflow.Workflow – Done.

  20. Stefan
    December 11, 2012 at 18:45 | #42

    Doesn’t look pretty.. Sory if I clogged up blog :)

    • December 11, 2012 at 19:12 | #43

      The Log file looks quite the same. i am kind of “out of ideas”
      you may debug org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.getSaveAndReconcileGenModel(ResourceSet, Grammar, XpandExecutionContext, List)

      Especially the place where the warning comes from.
      org.eclipse.xtext.generator.GenModelAccess.getGenModelResource(String, String, ResourceSet)

      in my case getSaveAndReconcileGenModel adds/creates the missing genpackage to the resourceset.

  21. Stefan
    December 11, 2012 at 19:16 | #44

    I will try to do that, and consult with other colleagues.
    Thank you very much for your time!
    If I manage, I’ll let you know what was the problem..

  22. Stefan
    December 18, 2012 at 14:23 | #45

    Your tutorial works perfectly in Eclipse Indigo, however Juno SR1 I didn’t manage to make work..

  23. Rod
    December 30, 2012 at 15:42 | #46

    Same problem here, I can only make it work using Indigo. If anyone has a solution, please share.

    • December 30, 2012 at 21:28 | #47

      I gave it a fresh try (with having time an a internet with reasonable speed)
      (1) Download Xtext Distro from Xtext Homepage (Mac 64 bit)
      (2) Installed Uml2 4.0.1
      (3) Import Sample Project
      (4) run workflow

      => did you try a different workspace or eclipse location? how do you unzip eclipse?

  24. Rod
    January 2, 2013 at 16:12 | #48

    I use Windows 7 64 bit, I downloaded Indigo and Juno and unzipped them on separate folders on C:, then I created a new Xtext Project and the 2 plugins following your tutorial for each one. Indigo works perfectly, Juno gives the error “Could not find a GenModel for EPackage ‘org.xtext.example.mydsl.MyDsl’ from org.xtext.example.mydsl.MyDsl” when running the workflow. Indigo is using Xtext 2.0.0 and Uml2 3.2.1, and Juno is using Xtext 2.3.1 and Uml2 4.0.1.

    • January 3, 2013 at 11:03 | #49

      I just tried Win7 64bit and i can reproduce the problem.
      can you please file a bugzilla with example attached

      • January 3, 2013 at 11:13 | #50

        Just gave the debugger a try as suggested before. this showed the following is missing

        uriMap = {
        from = “platform:/plugin/org.eclipse.uml2.types/model/Types.genmodel”
        to = “platform:/resource/org.eclipse.uml2.types/model/Types.genmodel”
        }
        uriMap = {
        from = “platform:/plugin/org.eclipse.uml2.types/model/Types.ecore”
        to = “platform:/resource/org.eclipse.uml2.types/model/Types.ecore”
        }
        registerGeneratedEPackage = “org.eclipse.uml2.types.TypesPackage”

  25. Stefan
    January 4, 2013 at 08:01 | #51

    Christian thanks! It works with additional mappings.. However, now I have another problem. When I create my model, and try to reference a uml element by ctrl-space shortcut I get this runtime error:

    Caused by: com.google.inject.CreationException: Guice creation errors:

    1) No implementation for org.eclipse.xtext.naming.IQualifiedNameProvider was bound.
    while locating org.eclipse.xtext.naming.IQualifiedNameProvider
    for field at org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy.qualifiedNameProvider(Unknown Source)
    while locating org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy
    for field at org.eclipse.xtext.resource.generic.GenericResourceDescriptionManager.resourceDescriptionStrategy(Unknown Source)
    at org.eclipse.xtext.service.MethodBasedModule.configure(MethodBasedModule.java:55)

    2) No implementation for org.eclipse.xtext.naming.IQualifiedNameProvider was bound.
    while locating org.eclipse.xtext.naming.IQualifiedNameProvider
    for field at org.eclipse.xtext.ui.refactoring.impl.DefaultDependentElementsCalculator.nameProvider(Unknown Source)
    while locating org.eclipse.xtext.ui.refactoring.IDependentElementsCalculator
    for field at org.eclipse.xtext.ui.refactoring.impl.RenameElementProcessor.dependentElementsCalculator(Unknown Source)
    while locating com.google.inject.Provider
    for field at org.eclipse.xtext.ui.refactoring.impl.DefaultRenameRefactoringProvider.processorProvider(Unknown Source)
    at org.eclipse.xtext.service.MethodBasedModule.configure(MethodBasedModule.java:55)

    It seems something is wrong with umleditor projects org.eclipse.xtext.uml and ui.uml..
    Could you help with this?

    Thanks in advance!
    Best,
    Stefan

    • January 4, 2013 at 08:19 | #52

      sorry the guice bindings got somehow broken (the source code stuff in wordpress sucks)
      i updated the stuff

  26. Stefan
    January 4, 2013 at 09:43 | #53

    Great, now I don’t get the error anymore, however, I don’t get the autocomplete on ctrl-space still. :( Is there something I got to do in my example project where I am creating uml model and my language model? I set the folder to be the source folder where uml and dsl models are, and the project is EMF project with Xtext nature added?

    • January 4, 2013 at 09:55 | #54

      i have no idea. Do the uml elements appear in the open model element dialog (crtl shift f3)? And if yes under what names. If not there must be something wrong with your setup. Can you once more share your projects and the sample models.

  27. Stefan
    January 4, 2013 at 12:56 | #55

    Yes, they are shown in open model element dialog, however they don’t work in dsl editor (ctrl-space)..I shared project here: https://www.dropbox.com/s/a6h98q362bmvha6/projects.zip

    • January 4, 2013 at 13:23 | #56

      Hi

      Xxx=[y] is short for Xxx=[y|ID] thus an Id will be parsed and an ID does not allow a .

  28. Stefan
    January 4, 2013 at 13:57 | #57

    It works!! Thank you soo much! I am new to Xtext, so I had no idea that this with grammar is issue..
    Cheers,
    Stefan

  29. Rod
    January 12, 2013 at 17:57 | #58

    Thank you Christian, that worked, I’m new to Xtext and that helped a lot. I’m trying to implement something more complex, could you give me any tips? This is part of my grammar:

    Assignment:
    variable=Variable ‘=’ expression=Expression
    ;

    Variable:
    name=ID
    ;

    Expression:
    New_Package |
    New_Class |
    New_Interface |

    ;

    New_Class:
    ‘NEW_CLASS’ ‘(‘ packID=Qualified_ID ‘,’ classID=[uml::Class|Qualified_ID] ‘)’
    ;

    With your tutorial, I can do the following on the editor (assuming myPack.myClass is present in some uml file):

    var = NEW_CLASS (org.example, myPack.myClass)

    I would like this to be valid too:

    var2 = NEW_CLASS (org.another, var)

    I don’t think I can solve this through the grammar only. Will I have to study something like scoping? Any tips will help.

  30. Stefan
    January 29, 2013 at 10:27 | #59

    Seems like I cannot influence much on meta-model generated by Xtext. One problem is I cannot specify in Xtext grammar bidirectional relationships. I have read somewhere I should first create abstract syntax and then derive and modify Xtext grammar from it..

    When I do it this way I have problem that Xtext grammar editor shows that it cannot find metamodel of the language – even though it was generated from it..

    Second thing, the way you have described the approach of using UML and DSL in Xtext, it all works well until I have to load a model of my language.. What happens is that references to UML model elements are null in a loaded model. Do you have any suggestions?

    Btw, if I create abstract syntax, loaded model has all references to uml model elements properly loaded and all works well.. So now I am stuck that I cannot implement either concrete syntax while execution of my language, or I implement concrete syntax and then execution is not working… :(

    Here is the code for loading models:

    resourceSet = new ResourceSetImpl();

    resourceSet.getResourceFactoryRegistry()
    .getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);

    new TestLangStandaloneSetup().createInjectorAndDoEMFRegistration();

    resource = resourceSet.getResource(URI.createURI(“example/persons.fumltest”), true);

    Thank you for any suggestion! Cheers..

    • January 29, 2013 at 10:35 | #60

      Hi,

      for the first Problem: this may be a classpath thing and is not related to this post so using the xtext forum may be better.
      for the second thing, this is what the umlsupport class is for

  31. Stefan
    January 29, 2013 at 12:47 | #61

    Not sure how to use UMLSupport class when programatically loading models of my dsl..

    Anyway, I wanted to ask one more question: Is UmlEditorOpener class used for listing existing UML elements from loaded model in the editor of my DSL? That list of UML elements I get by pressing CTRL-space.. I need to constraint this list, so my guess I would need to edit somehow this code, or am I totally wrong? :) Cheers

  32. Stefan
    January 30, 2013 at 10:40 | #62

    Could you please provide some example code on how to resolve xtext references to uml model elements if possible? I found several bug posts about this but no solution..

    • January 30, 2013 at 11:12 | #63

      Hi,

      first you coult try to use a mwe2 workflow instead of a java main. or you simply try to call new UmlSupport.preInvoke()
      additionaly you have to take case the umlpackage is registered in the epackage registry.

      since i dont have the time this is all i can do for you so far.

  33. Stefan
    January 30, 2013 at 12:12 | #64

    I have registered the epackage and invoked perInvoke(), but it doesnt work that way.. i am running code as junit plugin test..

  34. January 30, 2013 at 12:22 | #65

    hi just oversaw that: you of course have to feed the resourceset with all possible resources yourself!!!!

  35. Stefan
    February 4, 2013 at 16:26 | #66
  36. Mark
    May 21, 2013 at 07:42 | #67

    Hi Christian,

    Thanks for excellent tips how to cross reference from the DSL language to the external EMF model. I follow your blog and I managed to make it working. I am relatively new to Xtext an still learning how to customize things. My next challenge is to implement Rename Refactoring. I know it works fine in the scope of single DSL, but it does not when renaming objects in my external EMF model. Do you have any idea what will be the best way to approach this problem?

    Thanks
    Regards
    Marek

  37. Stefan
    September 10, 2013 at 10:19 | #69

    Hi. I was checking around a bit, but couldn’t find an easy to follow and complete guide on how to deal with the problem that I have, so forgive me if I am repeating the issue.

    So, I need to constraint the list of auto complete functionality in my editor. I have list of actions that are part of an activity for which a test is defined. I want to constraint the offered list of actions in the test to those actions that belong to the activity.

    I have implemented MyDslScopeProvider as explained in the official Xtext Manual and Guide, however, the implementation never gets called when running the editor.

    Could you please provide information on how to register the custom implementation of ScopeProvider and how to bind it so that it gets called in the editor. Does it metter that I am using qualified name provider from xbase, and how does it affect the process? (UML and DSL combination case)

    I apologize again if I am asking a question that is not appropriate here, but as I said my luck in finding a complete tutorial of this was poor, and I am a beginner in Xtext so configuration is hard thing for me :)

    Thanks a lot!

    • September 13, 2013 at 05:33 | #70

      Hi, i am not sure in detail what is your problem but have a look how XbaseScopeProvider (for content assist) and XbaseBatchScopeProvider are bound (I think you should override them both) Maybe Adding a breakpoint to their getScope Method will give you a hint if you are at the right point.

  38. Stefan
    September 13, 2013 at 08:49 | #71

    Hi. Thanks for the answer, unfortunately I still have a problem. The error I get as soon as I open my editor is:

    A binding to org.eclipse.xtext.scoping.IScopeProvider was already configured at org.eclipse.xtext.service.MethodBasedModule.configure

    I have declared my scope provider binding in the configure method of RuntimeModule:

    public void configure(Binder binder) {
    super.configure(binder);
    binder
    .bind(IScopeProvider.class)
    .to(TestLangScopeProvider.class);
    }

    Any suggestions? Thanks :)

  39. Stefan
    September 16, 2013 at 10:19 | #73

    I have removed the code from RUntimeModule class and added the method public Class bindIScopeProvider() as explained in xtext manual. I also changed the super class of my scope provider to XbaseScopeProvider and now it gets called. I still have problems with the fact that the method doesn’t get called, I guess it has to do something with IQualifiedNameProvider implemantion, but I will try to figure it out..

    Thanks for help! Cheers

  40. Stefan
    September 16, 2013 at 13:16 | #74

    I finally found the solution! :)
    All that is needed is to implement XBaseScopeProvider, add bindIScopeProvider() method in the runtime module and override the getScope(EObject context, EReference ref) method in my custom scope provider.. The method getScope gets called, and not the usual scope_Type_reference as described in xtext manual..

    Cheers :)

  41. Stefan
    September 17, 2013 at 11:27 | #75

    Hi. The only problem with this approach is that auto complete now gives only the name of the element to insert, and not its fully qualified name as before. Any suggestions? :) I tried to overwrite qulifiedName() method in UmlQualifiedNameProvider and changed its super type to XbaseQualifiedNameProvider but it doesn’t work..

  42. Stefan
    September 23, 2013 at 13:16 | #76

    Hi again :)
    I am a bit stuck here, and since it might be important for anyone trying to combine UML and Xtext i would share a bit of my code and ask you if you can determine what am I doing wrong :) Thanks again for your patience :)

    So I implemented my own ScopeProvider and have override the method getScope(EObject context, EReference reference). When I use content assist in the editor, I get the proper list of valid elements. Here is part of code in provider I am having trouble with:

    if(context instanceof VarDeclaration && reference.getName().equals(“ref”)){
    Activity activity = ((TestCase)context.eContainer()).getActivityUnderTest();
    List nodes = new ArrayList();
    for(ActivityNode node: activity.getNodes()){
    if(node instanceof Action){
    for(ObjectNode inNode: ((Action)node).getInputs()){nodes.add(inNode);}
    for(ObjectNode outNode: ((Action)node).getOutputs()){nodes.add(outNode);}
    }
    }
    return Scopes.scopeFor(nodes);
    }

    Now, in UmlQualifiedNameProvider I have implemented method qualifiedName for Pins:

    protected QualifiedName qualifiedName(Pin pin) {
    return super.qualifiedName(((NamedElement)pin.getOwner()).getName() + “.” +
    pin.getName());
    }

    This method gets called, binding in UmlRuntimeModule is correct, but what I get in suggested list is just name of a pin, instead of what I wanted name of owning node concatenated to pin name.

    When I remove scoping NameProvider works perfect, but as soon as I add scoping back, naming doesn’t work anymore..

    Could you please tell me what am I missing to do here, or what am I doing wrong?
    How to connect scoping and naming in case of UML + Xtext?

    Thanks you again so much in advance,
    Best regards

  43. Stefan
    September 23, 2013 at 13:19 | #77

    *Edit
    Sory, that last part of code in qulifiedName() method should be QulifiedName.create(((NamedElement)pin.getOwner()).getName() + “.” +
    pin.getName())

    • September 25, 2013 at 05:09 | #78

      Have a look at the scopes.scopefor methods source code and you will see that it produces simple names

  44. Stefan
    November 20, 2013 at 17:23 | #79

    Hi Christian,

    I am currently trying the same thing with Xtext DSL and OCL integration.
    Is there any example for such case by chance?
    I tried loading the OCL resource contents into the Xtext DSL resource, but I see that during runtime, these elements from OCL do not get set into the references from my DSL, as it happens in case of references to UML elements..

    Cheers,
    Stefan

    • November 24, 2013 at 19:46 | #80

      Hi,
      hard to say from my perspective. you can test your resourceserviceprovider
      by using the “open model element” dialog (crtl shift f3) an search there for your stuff.
      (project has to have Xtext Nature)
      if the elements are there and their names fit (xxx=[YYY] is short for xxx=[YYY|ID]
      => an ID will be parsed) it should work.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: