Accessing properties... the right way! [message #1722072] |
Tue, 02 February 2016 10:43  |
Eclipse User |
|
|
|
Hello Christian,
I had some time to think yesterday about the mismatch between jvm type mapping vs model. I realize I focussed too much on the jvm aspect, especially since I control the whole model.
So I have come up with something that will probably be more to your liking and that will probably allow you to tell me exactly where I should be going.
Here is the relevant part of my new model :
Configurable:
(abstract?='abstract')? 'configurable' name=ValidID ('extends' superType=JvmTypeReference)?
'{'
properties+=Property*
assignments+=Assignment* //////// new element
'}';
JavaType:
type=JvmTypeReference
;
ConfigurableType:
type=[Configurable]
;
Property:
///// I'm not even sure this is really needed, but I wanted a way to know if the type refers to a Configurable or a simple jvm type
type=(JavaType|ConfigurableType) name=ValidID (
defaultValue=DefaultValue |
block=MyXBlockExpression
)? ;
Assignment returns xbase::XExpression:
{MyAssignment} 'set' address=DotExpression op=('='|':=') expression=XLiteral
;
DotExpression returns Ref:
PropertyRef ({DotExpression.ref=current} "." tail=[Property])*
;
PropertyRef returns Ref:
{PropertyRef} property=[Property]
;
I'm having some scoping questions.
Firstly, since the rule for assignments starts with 'set' it's clear that what follows is a DotExpression, which much start with a property reference.
OOTB, the properties don't auto complete, when I was expecting them to.
Secondly, I created a scope function like :
def IScope scope_DotExpression_tail(DotExpression exp, EReference ref) {
val head = exp.ref
switch(head) {
PropertyRef: {
val type = head.property.type
switch (type) {
JavaType: {
////// can i get the right scope here ? ie treat the property as a Configurable and get it's own properties ?
IScope::NULLSCOPE
}
}
}
default: IScope::NULLSCOPE
}
}
Hope this will make it less obscure and more in line with standard XText scoping.
Thanks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Accessing properties... the right way! [message #1722282 is a reply to message #1722280] |
Wed, 03 February 2016 13:46   |
Eclipse User |
|
|
|
The grammar fragment is in:
https://www.eclipse.org/forums/index.php?t=msg&th=1074397&goto=1722245&#msg_1722245
But, I think it's doing its job properly. The delegate gets called, and returns an ImportScope. Debugging shows an "importFrom" (SelectableBasedScope) inside that has all the actual attributes.
but if I return the delegateGetScope as my IScope, it doesn't propose anything.
maybe the call sequence is not the right one ?
in my DslScopeProvider:
if (reference == ModelDslPackage.Literals.MY_ASSIGNMENT__ATTRIBUTE) {
if (context instanceof MyAssignment) {
return delegateGetScope(context, reference) // context and reference come from the getScope method
The SelectableBasedScope debugger structure
SelectableBasedScope[com.client360.configuration.blinds.horizontal.BonjourAttributes.description,
com.client360.configuration.blinds.horizontal.BonjourAttributes.visible,
com.client360.configuration.blinds.horizontal.BonjourAttributes.readOnly,
com.client360.configuration.blinds.horizontal.BonjourAttributes.position]
-> SelectableBasedScope[]
-> SelectableBasedScope[org.eclipse.xtext.builder.builderState.impl.EObjectDescriptionImpl@21bac1a8 (name: com.netappsid.configurator.attrs.MyAttributes.ADDEDATTRIBUTE, fragment: /0/@elements.0/@definitions.0)] -> NULLSCOPE
You can see the "local" ones first and the "ADDEDATTRIBUTE" is also present, but in a different structure.
Thanks
|
|
|
|
|
|
|
|
|