Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Referencing existing metamodels in a DSL
Referencing existing metamodels in a DSL [message #688051] Thu, 23 June 2011 19:08 Go to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
We are currently experimenting with Xtext, and would like to create a special constraint language over EMF models.

The Xtext grammar language contains similar option: metamodels (EPackages) can be referenced via their namespace URIs, and then EClassifiers can be used inside the language.

I would like to create a similar functionality for our constraint language. I defined our import option similarly to the one in xtext.xtext:
Import:	'import' ePackage=[ecore::EPackage|STRING] ('as' alias=ID)?;
, and used the code from the Xtext scope provider to gather the list of NS URIs (and thus content assist was also working) with a minor modification: the qualified name is created using the default qualified name converter:
	public IScope scope_EPackage(Import ctx, EReference ref){
		IScope current = new SimpleScope(IScope.NULLSCOPE, Iterables.transform(EPackage.Registry.INSTANCE.keySet(), new Function<String, IEObjectDescription>() {
			public IEObjectDescription apply(String from) {
				InternalEObject proxyPackage = (InternalEObject) EcoreFactory.eINSTANCE.createEPackage();
				proxyPackage.eSetProxyURI(URI.createURI(from));
				
				return EObjectDescription.create(qualifiedNameConverter.toQualifiedName(from), proxyPackage, Collections.singletonMap("nsURI", "true"));
			}
		}));
		return current;
	}


However, the inserted namespace is not resolved: I got a nullpointer exception, as during the linking phase it tried to resolve the object of the URI "http://www.eclipse.org/emf/2002/Ecore", but its fragment part was missing.

My question is, what might be missing from my code? Do I have to register some specific linking functionality? Or should I use a completely different mechanism for resolution?

Thank you for your help,
Zoltán Ujhelyi
Re: Referencing existing metamodels in a DSL [message #688055 is a reply to message #688051] Thu, 23 June 2011 19:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14670
Registered: July 2009
Senior Member
Hi,

maybe yes. have a look that is done in org.eclipse.xtext.xtext.XtextScopeProvider and org.eclipse.xtext.xtext.XtextLinkingService

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Referencing existing metamodels in a DSL [message #688065 is a reply to message #688055] Thu, 23 June 2011 20:03 Go to previous message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi,

thanks for the quick answer. I found the ScopeProvider, but the LinkingService was missing from my code. It finally works.

Zoltán
Previous Topic:Several extensions for one gramar
Next Topic:How to fix "Syntax error:A return type must be specified for java extensions!"
Goto Forum:
  


Current Time: Sat Apr 27 04:31:08 GMT 2024

Powered by FUDForum. Page generated in 0.02993 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top