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




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
Hello Karsten, feel free to do so. Christian
Great job! Tank you for sharing it !
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
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
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.
simply add it (before the reader)
component = x.y.z.XYZSupport{}I got this to work in eclipse. But not with the XtextRunner-JUnit-Testcases.
Where do i have to put the new xxxSupport().register()?
simply calling it in an @Before method doesnt work?
Shouldn’t it be done while firing up the “infrastructure”? So that other User of my Dsl-SDK don’t have to worry…
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.
It’s working perfectly !!! Thank you very much for your answer !!!
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
Hi,
no – i created two simple plugin projects:
- org.eclipse.xtext.ui.uml
- org.eclipse.xtext.uml
and an xtext dsl with the wizard that has refereces to an uml class as sample application.
btw you can find the code here now: http://code.google.com/a/eclipselabs.org/p/xtext-utils/source/browse/?repo=uml#git%2Fexamples
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.
You’re right. Many thanks.
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
Hi,
Hard to guess from having no code at all can you share your complete code
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..
Hi I still don’t see where the mylang stuff comes from do you have somewhere a package with that nsuri
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
Hi this should be done by the stuff blow the ….
(Ecoregeneratorfragment)
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..
Please share the rest of your workflow
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
}
}
}
}
Looks good. Please share your complete code (zip / drop box ….)
http://dl.dropbox.com/u/59483079/projects.zip
Hi,
this code works perfectly for me.
uncomment the last 3 lines in xtext file
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]
;
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!
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.
I use the Xtext 2.3.1 distro from the Xtext website with uml additionally installed
Could you share your installation of Eclipse on dropbox, if I am not asking too much
I have no strong inet during the week. WhichOS do you have. BTW did you try it with the distro I mentioned?
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..
Please download the distro from eclipse.org/xtext
Hmm will retry that.
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..
Hi can you please post the complete workflow log
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.
Doesn’t look pretty.. Sory if I clogged up blog
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.
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..
Your tutorial works perfectly in Eclipse Indigo, however Juno SR1 I didn’t manage to make work..
Same problem here, I can only make it work using Indigo. If anyone has a solution, please share.
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?
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.
I just tried Win7 64bit and i can reproduce the problem.
can you please file a bugzilla with example attached
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”
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
sorry the guice bindings got somehow broken (the source code stuff in wordpress sucks)
i updated the stuff
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?
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.
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
Hi
Xxx=[y] is short for Xxx=[y|ID] thus an Id will be parsed and an ID does not allow a .
It works!! Thank you soo much! I am new to Xtext, so I had no idea that this with grammar is issue..
Cheers,
Stefan
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.
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..
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
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
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..
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.
I have registered the epackage and invoked perInvoke(), but it doesnt work that way.. i am running code as junit plugin test..
hi just oversaw that: you of course have to feed the resourceset with all possible resources yourself!!!!
This worked for me: http://www.eclipse.org/forums/index.php/mv/msg/309645/821575/#msg_821575
Thanks!
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
Sorry I have no idea on that