Limit the feature scope of a type [message #1736475] |
Wed, 29 June 2016 15:44 |
Eclipse User |
|
|
|
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?
|
|
|
Powered by
FUDForum. Page generated in 0.04568 seconds