Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Limit the feature scope of a type
Limit the feature scope of a type [message #1736475] Wed, 29 June 2016 15:44
Olaf Lenz is currently offline Olaf LenzFriend
Messages: 1
Registered: June 2016
Junior Member
We have a DSL using xbase in some parts.

From the DSL, users can access various Java types and their methods.

What I want to do is to limit the set of methods/fields that the user can access, i.e. I want to allow him to only use a specific set of methods.

At the moment, I use a subclass of FeatureScopes and override createReceiverFeatureScope like this:
class MyFeatureScopes extends FeatureScopes {
    @Inject private OperatorMapping operatorMapping
    @Inject private extension IQualifiedNameProvider

    // Pattern that describes methods that can be called
    final static val ALLOWED_METHODS = (
        ".*\\.(_?set|_?get).*" + "|" + DataTypeExtensions.canonicalName.quote + "\\..*" + "|" +
        FlowFeatures.canonicalName.quote + "\\..*" + "|" + (AbstractMultiSiteData.canonicalName + ".toString()").quote
        ).compile

    override protected IScope createReceiverFeatureScope(EObject featureCall, XExpression receiver,
        LightweightTypeReference receiverType, JvmIdentifiableElement receiverFeature, boolean implicitReceiver,
        boolean validStatic, TypeBucket receiverBucket, IScope parent, IFeatureScopeSession session) {

        val receiverScope = super.createReceiverFeatureScope(
                featureCall, receiver, receiverType, receiverFeature,
                implicitReceiver, validStatic,  receiverBucket, parent, session)

        // Tailor what methods can be called 
        return new FilteringScope(receiverScope) [
            val obj = it.EObjectOrProxy
            if (obj instanceof JvmOperation) {
                return ALLOWED_METHODS.matcher(obj.identifier).matches
            }
            return true
        ]
    }
}


This works, but I do not like it very much, as it requires string parsing, and is tedious to maintain if anything changes.

What I would prefer would be if I could simply exchange the scope of some types with the scope of one of its superclasses (with the restricted interface). The xtext documentation refers to the AbstractTypeScopeProvider as a customization point, and it sounds as though this might be useful for this purpose, but I was unable to get this running.

Is there a way to do this?
Previous Topic:Automatically Load generated Xtext
Next Topic:[Xtend] Setting a class type variable
Goto Forum:
  


Current Time: Thu Jan 21 11:13:30 GMT 2021

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

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

Back to the top