Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext 2.4.2 ScopeProvider
Xtext 2.4.2 ScopeProvider [message #1066209] Mon, 01 July 2013 14:43 Go to next message
tiange zhang is currently offline tiange zhangFriend
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 #1066327 is a reply to message #1066209] Tue, 02 July 2013 08:11 Go to previous messageGo to next message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 112
Registered: July 2009
Senior Member
Hello Tiange,


I use following code to restrict my scope to the elements of the specific enum. It works well with Xtext 2.4.2

    @Override
    public IScope getScope(final EObject context, final EReference reference) {
        if (context instanceof MethodDefinition
            && reference.equals(BnoApiPackage.Literals.METHOD_DEFINITION__WARNING_TYPE)) {
            JvmType jvmType = typeReferences.findDeclaredType("my.WarningTypeEnum", context);
            if (jvmType instanceof JvmEnumerationType) {
                return Scopes.scopeFor(((JvmEnumerationType) jvmType).getLiterals(),
                    new Function< JvmEnumerationLiteral, QualifiedName >() {

                        @Override
                        public QualifiedName apply(final JvmEnumerationLiteral input) {
                            return QualifiedName.create(input.getSimpleName());
                        }
                    }, IScope.NULLSCOPE);
            }
        }
        ...
    }


Hope, it helps.


Kind regards,
Boris
Re: Xtext 2.4.2 ScopeProvider [message #1080725 is a reply to message #1066209] Tue, 06 August 2013 10:07 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
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


Previous Topic:Xtext Dsl Persistency in database
Next Topic:Two options in Editor but one in the model
Goto Forum:
  


Current Time: Sat Apr 20 04:26:45 GMT 2024

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

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

Back to the top