|
|
|
Re: Cross reference feature & import question [message #635985 is a reply to message #635616] |
Thu, 28 October 2010 19:49 |
Sebastian Zarnekow 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 |
Christian Saad 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);
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.04339 seconds