Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross reference feature & import question
Cross reference feature & import question [message #635616] Wed, 27 October 2010 14:21 Go to next message
Christian Saad is currently offline Christian SaadFriend
Messages: 39
Registered: July 2009
Member
Hi,

I'm currently have two problems trying to build an xtext editor:

1. I'd like to use a non-default feature to identify cross references. In my (existing) ecore meta model, the relevant feature is called "id", but the linker seems to consider only "name". Is there a way to change this behavior?

2. I'm using importURI to enable referencing EClasses from existing ecore files in the DSL. It would be great if this would not only work with platform URIs but also with the namespaces of the registered EPackages. So, it's basically what's also possible in the xtext grammar editor, but I have no idea how it's done there.

Thanks,
Chris

Re: Cross reference feature & import question [message #635624 is a reply to message #635616] Wed, 27 October 2010 14:38 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
@1: The linker considers all exported objects who have a certain name. That name is computed by looking at a 'name' attribute, by default. You can override this by binding your own IQualifiedNameProvider implementation (which'd usually extends from DefaultDeclarativeQualifiedNameProvider) in the runtime. That implementation would have a 'qualifiedName' method with 1 argument whose type will be the relevant type with feature 'id'.

@2: The source is open and Xtext is implemented using Xtext, so it's quickest to have a look at how it's done there. You're bound to learn a lot on the way as well.


Re: Cross reference feature & import question [message #635883 is a reply to message #635624] Thu, 28 October 2010 13:37 Go to previous messageGo to next message
Christian Saad is currently offline Christian SaadFriend
Messages: 39
Registered: July 2009
Member
Meinte Boersma wrote on Wed, 27 October 2010 10:38
@1: The linker considers all exported objects who have a certain name. That name is computed by looking at a 'name' attribute, by default. You can override this by binding your own IQualifiedNameProvider implementation (which'd usually extends from DefaultDeclarativeQualifiedNameProvider) in the runtime. That implementation would have a 'qualifiedName' method with 1 argument whose type will be the relevant type with feature 'id'.

@2: The source is open and Xtext is implemented using Xtext, so it's quickest to have a look at how it's done there. You're bound to learn a lot on the way as well.


Thanks, I'll your suggestion concerning the name provider.

For 2., I've already taken a look at xtext.xtext and it says there:

// referenced metamodels may share aliases with other referenced metamodels
// and with generated metamodels
ReferencedMetamodel :
'import' ePackage=[ecore::EPackage|STRING] ('as' alias=ID)?;

but this doesn't work for me if I include it in my xtext file. So I'm guessing the magic probably happens elsewhere.
Re: Cross reference feature & import question [message #635985 is a reply to message #635616] Thu, 28 October 2010 19:49 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Chris,

1) You have to implement your own resource descriptions that use the id
to create qualified names. If you customize local scoping, you have use
the Scopes utility methods with an explicit name-function.

2) You have to customize the scoping for your the reference to the
EPackage and take installed packages into account. Just make the
packages from the EPackage.Registry of the resource set available as
scoped elements.

Please refer to the documentation for details about scoping and linking.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 27.10.10 16:21, schrieb C. Saad:
> Hi,
>
> I'm currently have two problems trying to build an xtext editor:
>
> 1. I'd like to use a non-default feature to identify cross references.
> In my (existing) ecore meta model, the relevant feature is called "id",
> but the linker seems to consider only "name". Is there a way to change
> this behavior?
>
> 2. I'm using importURI to enable referencing EClasses from existing
> ecore files in the DSL. It would be great if this would not only work
> with platform URIs but also with the namespaces of the registered
> EPackages. So, it's basically what's also possible in the xtext grammar
> editor, but I have no idea how it's done there.
>
> Thanks,
> Chris
>
>
Re: Cross reference feature & import question [message #636619 is a reply to message #635985] Tue, 02 November 2010 09:14 Go to previous message
Christian Saad is currently offline Christian SaadFriend
Messages: 39
Registered: July 2009
Member
Thanks for the help. Here's my implementation for anyone who might be interested:

public class CustomQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider
{

public String qualifiedName(Object obj)
{
if (obj instanceof ElementWithID)
return ((ElementWithID) obj).getId();
else
return "";
}

}


public class CustomGlobalScopeProvider extends ImportUriGlobalScopeProvider
{

@Override
protected IScope createLazyResourceScope(IScope parent, final URI uri,
final IResourceDescriptions descriptions, final EReference reference)
{
EPackage registeredPackage = (EPackage) EPackage.Registry.INSTANCE.get(uri.toString());

if (registeredPackage != null)
{
try
{
Object ecoreDescriptor = IResourceServiceProvider.Registry.INSTANCE
.getExtensionToFactoryMap().get("ecore");

IResourceServiceProvider serviceProvider = (IResourceServiceProvider) ecoreDescriptor
.getClass().getMethod("get").invoke(ecoreDescriptor, null);

if (serviceProvider == null)
throw new IllegalStateException("No "
+ IResourceServiceProvider.class.getSimpleName()
+ " found in registry for uri " + uri);

Manager manager = serviceProvider.getResourceDescriptionManager();
IResourceDescription description = manager.getResourceDescription(registeredPackage
.eResource());

return new ResourceDescriptionBasedScope(parent, description,
reference.getEReferenceType());
}
catch (Exception e)
{
e.printStackTrace();
}
}

return super.createLazyResourceScope(parent, uri, descriptions, reference);
}

}
Previous Topic:Problem Using Resource URIs to Import Existing EPackages
Next Topic:Keywords with whitespaces and same prefix
Goto Forum:
  


Current Time: Fri Apr 26 21:03:46 GMT 2024

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

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

Back to the top