Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » I need both ImportUriGlobalScopeProvider and TypesAwareDefaultGlobalScopeProvider in my DSL
icon5.gif  I need both ImportUriGlobalScopeProvider and TypesAwareDefaultGlobalScopeProvider in my DSL [message #917588] Thu, 20 September 2012 08:15 Go to next message
Aaron Digulla is currently offline Aaron DigullaFriend
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
I have a DSL where I use jvmTypes (http://www.eclipse.org/xtext/common/JavaVMTypes) and importURI.

When I wire the IGlobalScopeProvider, I can't have both the ImportUriGlobalScopeProvider and TypesAwareDefaultGlobalScopeProvider, so either the JVM types work or the importURI.

Looking at the code, it doesn't seem trivial to merge the two providers.

Suggestions?

Regards,

A. Digulla
Re: I need both ImportUriGlobalScopeProvider and TypesAwareDefaultGlobalScopeProvider in my DSL [message #918699 is a reply to message #917588] Fri, 21 September 2012 08:57 Go to previous messageGo to next message
Nicolas is currently offline NicolasFriend
Messages: 21
Registered: July 2009
Junior Member
On 09/20/2012 10:15 AM, Aaron Digulla wrote:
> I have a DSL where I use jvmTypes (http://www.eclipse.org/xtext/common/JavaVMTypes) and importURI.
>
> When I wire the IGlobalScopeProvider, I can't have both the ImportUriGlobalScopeProvider and TypesAwareDefaultGlobalScopeProvider, so either
> the JVM types work or the importURI.
>
> Looking at the code, it doesn't seem trivial to merge the two providers.
>
> Suggestions?
>
> Regards,
>
> A. Digulla

Hello,

I encountered the same problem some months ago, and did the following to solve
it. I do not know if it is the best solution, but at least it works for me.
I had to use a @SuppressWarnings("restriction") annotation because of export
restrictions, this probably means that this solution is not optimal :-)

Hope it helps.

Nicolas.


/**
* A global scope provider that is both able to process the importURI attributes to establish cross links
* with other EMF models, and to handle references to JVM types.
* This class is a subclass of {@link ImportUriGlobalScopeProvider} in order to get the importURI behavior
* and delegates references to JVM types to an instance of AbstractTypeScopeProvider obtained through Guice.
* @see TypesAwareDefaultGlobalScopeProvider where part of is getScope() function is duplicated here.
* @see ClasspathBasedTypeScopeProvider
* @see org.eclipse.xtext.common.types.xtext.ui.JdtBasedSimpleTypeScopeProvider
*
*/
@SuppressWarnings("restriction")
public class MyDSLGlobalScopeProvider extends ImportUriGlobalScopeProvider {

/*
* AbstractTypeScopeProvider is bound to org.eclipse.xtext.common.types.xtext.ClasspathBasedTypeScopeProvider
* in the "Standalone" setup and to org.eclipse.xtext.common.types.xtext.ui.JdtBasedSimpleTypeScopeProvider
* int the IU setup. In both cases, the class AbstractTypeScopeProvider which is the usual global
* scope provider when using the JVM types uses an AbstractTypeScopeProvider instance (through Guice) to
* handle all references to JVM types : we do the same here.
*/
@Inject
private AbstractTypeScopeProvider typeScopeProvider;

@Override
public IScope getScope(Resource resource, EReference reference,
Predicate<IEObjectDescription> filter) {
if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_TYPE, reference.getEReferenceType())) {
IScope typeScope = typeScopeProvider.getScope(resource, reference, filter);
return typeScope;
}
else {
return super.getScope(resource, reference, filter);
}
}
}
Re: I need both ImportUriGlobalScopeProvider and TypesAwareDefaultGlobalScopeProvider in my DSL [message #918734 is a reply to message #918699] Fri, 21 September 2012 09:37 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi,

your solution looks good to me. The warnings are present because the
referenced types are not necessarily considered to be stable API.
However, we are cautious to change them anyway.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 21.09.12 10:57, schrieb Nicolas:
> On 09/20/2012 10:15 AM, Aaron Digulla wrote:
>> I have a DSL where I use jvmTypes
>> (http://www.eclipse.org/xtext/common/JavaVMTypes) and importURI.
>>
>> When I wire the IGlobalScopeProvider, I can't have both the
>> ImportUriGlobalScopeProvider and TypesAwareDefaultGlobalScopeProvider,
>> so either
>> the JVM types work or the importURI.
>>
>> Looking at the code, it doesn't seem trivial to merge the two providers.
>>
>> Suggestions?
>>
>> Regards,
>>
>> A. Digulla
>
> Hello,
>
> I encountered the same problem some months ago, and did the following to
> solve
> it. I do not know if it is the best solution, but at least it works for me.
> I had to use a @SuppressWarnings("restriction") annotation because of
> export
> restrictions, this probably means that this solution is not optimal :-)
>
> Hope it helps.
>
> Nicolas.
>
>
> /**
> * A global scope provider that is both able to process the importURI
> attributes to establish cross links
> * with other EMF models, and to handle references to JVM types.
> * This class is a subclass of {@link ImportUriGlobalScopeProvider} in
> order to get the importURI behavior
> * and delegates references to JVM types to an instance of
> AbstractTypeScopeProvider obtained through Guice.
> * @see TypesAwareDefaultGlobalScopeProvider where part of is
> getScope() function is duplicated here.
> * @see ClasspathBasedTypeScopeProvider
> * @see
> org.eclipse.xtext.common.types.xtext.ui.JdtBasedSimpleTypeScopeProvider
> *
> */
> @SuppressWarnings("restriction")
> public class MyDSLGlobalScopeProvider extends
> ImportUriGlobalScopeProvider {
>
> /*
> * AbstractTypeScopeProvider is bound to
> org.eclipse.xtext.common.types.xtext.ClasspathBasedTypeScopeProvider
> * in the "Standalone" setup and to
> org.eclipse.xtext.common.types.xtext.ui.JdtBasedSimpleTypeScopeProvider
> * int the IU setup. In both cases, the class
> AbstractTypeScopeProvider which is the usual global
> * scope provider when using the JVM types uses an
> AbstractTypeScopeProvider instance (through Guice) to
> * handle all references to JVM types : we do the same here.
> */
> @Inject
> private AbstractTypeScopeProvider typeScopeProvider;
>
> @Override
> public IScope getScope(Resource resource, EReference reference,
> Predicate<IEObjectDescription> filter) {
> if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_TYPE,
> reference.getEReferenceType())) {
> IScope typeScope = typeScopeProvider.getScope(resource,
> reference, filter);
> return typeScope;
> }
> else {
> return super.getScope(resource, reference, filter);
> }
> }
> }
>
>
Re: I need both ImportUriGlobalScopeProvider and TypesAwareDefaultGlobalScopeProvider in my DSL [message #918833 is a reply to message #918734] Fri, 21 September 2012 11:45 Go to previous message
Aaron Digulla is currently offline Aaron DigullaFriend
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Nice idea. I tried to create an IGlobalScopeProvider which simply merges the results of all method calls of both scopes but of course the deciding factor is JvmType.

I created a gist to make reading and cut&paste more simple: https://gist.github.com/3761048

Thanks,

A. Digulla

[Updated on: Fri, 21 September 2012 11:51]

Report message to a moderator

Previous Topic:@Inject usage in Xtend files
Next Topic:Odd error using IJvmTypeProvider
Goto Forum:
  


Current Time: Thu Mar 28 23:16:43 GMT 2024

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

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

Back to the top