Xtext 2.4.2 ScopeProvider [message #1066209] |
Mon, 01 July 2013 14:43 |
tiange zhang Messages: 16 Registered: February 2011 Location: Shanghai, China |
Junior Member |
|
|
I modified the DomainModel example slightly as following:
Feature:
Property | Operation | DateFeatureRef;
DateFeatureRef:
'ref' op=[jvmTypes::JvmOperation];
and a customized ScopeProvider
class ScopeProvider extends XbaseScopeProvider {
@Inject extension TypeReferences typeRefs
override getScope(EObject context, EReference reference) {
if (reference == DomainmodelPackage.eINSTANCE.dateFeatureRef_Op) {
var dateJvmType = typeRefs.findDeclaredType(typeof(Date), context) as JvmDeclaredType
var objectDescriptions = dateJvmType.allFeatures.filter(typeof(JvmOperation)).map[
EObjectDescription::create(it.simpleName, it)]
MapBasedScope::createScope(IScope::NULLSCOPE, objectDescriptions)
} else
super.getScope(context, reference)
}
}
With this grammar and ScopeProvider, a feature in a entity can be a reference to JvmOperation from java.util.Date, such as:
entity A{
ref getCalendarDate
}
It works fine in Xtext 2.3. In Xtext 2.4.2, content assist is OK but after operation is selected, there is validation error saying "Couldn't resolve reference to JvmOperation 'getCalendarDate'.".
How to write ScopeProvider in Xtext 2.4.2?
Thanks.
|
|
|
|
Re: Xtext 2.4.2 ScopeProvider [message #1080725 is a reply to message #1066209] |
Tue, 06 August 2013 10:07 |
|
Hi
from what I understand, in Xbase 2.4.2, XbaseScopeProvider is used only
by the content assist; XbaseScopeProvider is also deprecated. The
actual resolving of references is performed using XbaseBatchScopeProvider.
On 01/07/2013 16:43, tiange zhang wrote:
> I modified the DomainModel example slightly as following:
>
> Feature:
> Property | Operation | DateFeatureRef;
>
> DateFeatureRef:
> 'ref' op=[jvmTypes::JvmOperation];
>
>
> and a customized ScopeProvider
>
> class ScopeProvider extends XbaseScopeProvider {
> @Inject extension TypeReferences typeRefs
>
> override getScope(EObject context, EReference reference) {
> if (reference == DomainmodelPackage.eINSTANCE.dateFeatureRef_Op) {
> var dateJvmType = typeRefs.findDeclaredType(typeof(Date),
> context) as JvmDeclaredType
> var objectDescriptions =
> dateJvmType.allFeatures.filter(typeof(JvmOperation)).map[
> EObjectDescription::create(it.simpleName, it)]
> MapBasedScope::createScope(IScope::NULLSCOPE,
> objectDescriptions)
> } else
> super.getScope(context, reference)
> }
> }
>
>
>
> With this grammar and ScopeProvider, a feature in a entity can be a
> reference to JvmOperation from java.util.Date, such as:
>
>
> entity A{
> ref getCalendarDate
> }
>
>
> It works fine in Xtext 2.3. In Xtext 2.4.2, content assist is OK but
> after operation is selected, there is validation error saying "Couldn't
> resolve reference to JvmOperation 'getCalendarDate'.".
>
> How to write ScopeProvider in Xtext 2.4.2?
>
> Thanks.
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Powered by
FUDForum. Page generated in 0.03081 seconds