Home » Modeling » TMF (Xtext) » I need both ImportUriGlobalScopeProvider and TypesAwareDefaultGlobalScopeProvider in my DSL
|
Re: I need both ImportUriGlobalScopeProvider and TypesAwareDefaultGlobalScopeProvider in my DSL [message #918699 is a reply to message #917588] |
Fri, 21 September 2012 08:57 |
Nicolas 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 |
Sebastian Zarnekow 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);
> }
> }
> }
>
>
|
|
| |
Goto Forum:
Current Time: Thu Mar 28 23:16:43 GMT 2024
Powered by FUDForum. Page generated in 0.04323 seconds
|