Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Providing context values for the Xbase interpreter
Providing context values for the Xbase interpreter [message #841971] Wed, 11 April 2012 22:39 Go to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Hi,

In my DSL for state machines I use a scope provider to provide a context
for Xbase expressions. E.g. for the following snippet, the scope
provider binds "this" to the qa.QAGamePlayerState type and this lets
Xbase link the currentQA name in the "on enter" clause to
qa.QAGamePlayerState's getCurrentQA() method. This seems to work as
expected, since there are no parsing or linking errors.

state playerState for qa.QAGamePlayerState {
-> state init {
on enter if currentQA == null do {
currentQA = game.qas.head;
};
-> active on ~ currentQA;
}

Now I want to evaluate the expression using the XbaseInterpreter. I
create an evaluation context and bind "this" to an instance of
qa.QAGamePlayerState, as explained in
http://www.eclipse.org/Xtext/documentation/2_0_0/199d-xbase-expressions.php#xbaseExpressions_6
The hope is that this will be used by the interpreter as the context for
the invocation of the getCurrentQA() method. However, instead I get an
error message stating the getCurrentQA() cannot be invoked on a null.
Stepping through the code, I see no trace of actually using the
evaluation context to get the value of "this" when determining the
receiver for the getCurrentQA() method.

So, what am I doing wrong?

Hallvard
Re: Providing context values for the Xbase interpreter [message #845678 is a reply to message #841971] Sun, 15 April 2012 09:43 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Usually, setting up an interpreter involves dealing with some
classloader trouble. Make sure the Java class qa.QAGamePlayerState is on
loadable by the XbaseInterpreter's classloader.

The feature call's receiver resolution should be handled by the
org.eclipse.xtext.xbase.impl.FeatureCallToJavaMapping.getActualReceiver().
The scope provider should have set the implicit receiver to a feature
call to "this".


Am 12.04.12 00:39, schrieb Hallvard Trætteberg:
> Hi,
>
> In my DSL for state machines I use a scope provider to provide a context
> for Xbase expressions. E.g. for the following snippet, the scope
> provider binds "this" to the qa.QAGamePlayerState type and this lets
> Xbase link the currentQA name in the "on enter" clause to
> qa.QAGamePlayerState's getCurrentQA() method. This seems to work as
> expected, since there are no parsing or linking errors.
>
> state playerState for qa.QAGamePlayerState {
> -> state init {
> on enter if currentQA == null do {
> currentQA = game.qas.head;
> };
> -> active on ~ currentQA;
> }
>
> Now I want to evaluate the expression using the XbaseInterpreter. I
> create an evaluation context and bind "this" to an instance of
> qa.QAGamePlayerState, as explained in
> http://www.eclipse.org/Xtext/documentation/2_0_0/199d-xbase-expressions.php#xbaseExpressions_6
>
> The hope is that this will be used by the interpreter as the context for
> the invocation of the getCurrentQA() method. However, instead I get an
> error message stating the getCurrentQA() cannot be invoked on a null.
> Stepping through the code, I see no trace of actually using the
> evaluation context to get the value of "this" when determining the
> receiver for the getCurrentQA() method.
>
> So, what am I doing wrong?
>
> Hallvard


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Providing context values for the Xbase interpreter [message #849494 is a reply to message #845678] Thu, 19 April 2012 07:36 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Jan,

I think I'm closing in on the problem: The left operand of == is an
XFeatureCall with an implicitReceiver set to another XFeatureCall, which
I assume corresponds to the "this" binding in the scope. However, the
XExpression that is interpreted is an (EcoreUtil.)copy of the original,
and in this copy the implicitReceiver is null! For this object
isFeatureLinked return false, whereas on the original it was true. BTW,
in addition to copying the XExpression, I want to serialize it and
interpret it later.

I guess the questions then is: How do I (re)link a (serialized) copy to
restore the implicitReceiver, before interpreting it using an
XBaseInterpreter?

Hallvard

On 15.04.12 11.43, Jan Koehnlein wrote:
> Usually, setting up an interpreter involves dealing with some
> classloader trouble. Make sure the Java class qa.QAGamePlayerState is on
> loadable by the XbaseInterpreter's classloader.
>
> The feature call's receiver resolution should be handled by the
> org.eclipse.xtext.xbase.impl.FeatureCallToJavaMapping.getActualReceiver().
> The scope provider should have set the implicit receiver to a feature
> call to "this".
>
>
> Am 12.04.12 00:39, schrieb Hallvard Trætteberg:
>> Hi,
>>
>> In my DSL for state machines I use a scope provider to provide a context
>> for Xbase expressions. E.g. for the following snippet, the scope
>> provider binds "this" to the qa.QAGamePlayerState type and this lets
>> Xbase link the currentQA name in the "on enter" clause to
>> qa.QAGamePlayerState's getCurrentQA() method. This seems to work as
>> expected, since there are no parsing or linking errors.
>>
>> state playerState for qa.QAGamePlayerState {
>> -> state init {
>> on enter if currentQA == null do {
>> currentQA = game.qas.head;
>> };
>> -> active on ~ currentQA;
>> }
>>
>> Now I want to evaluate the expression using the XbaseInterpreter. I
>> create an evaluation context and bind "this" to an instance of
>> qa.QAGamePlayerState, as explained in
>> http://www.eclipse.org/Xtext/documentation/2_0_0/199d-xbase-expressions.php#xbaseExpressions_6
>>
>>
>> The hope is that this will be used by the interpreter as the context for
>> the invocation of the getCurrentQA() method. However, instead I get an
>> error message stating the getCurrentQA() cannot be invoked on a null.
>> Stepping through the code, I see no trace of actually using the
>> evaluation context to get the value of "this" when determining the
>> receiver for the getCurrentQA() method.
>>
>> So, what am I doing wrong?
>>
>> Hallvard
>
>
Re: Providing context values for the Xbase interpreter [message #849551 is a reply to message #849494] Thu, 19 April 2012 08:40 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Counterquestion: Why copy?

Am 19.04.12 09:36, schrieb Hallvard Trætteberg:
> Jan,
>
> I think I'm closing in on the problem: The left operand of == is an
> XFeatureCall with an implicitReceiver set to another XFeatureCall, which
> I assume corresponds to the "this" binding in the scope. However, the
> XExpression that is interpreted is an (EcoreUtil.)copy of the original,
> and in this copy the implicitReceiver is null! For this object
> isFeatureLinked return false, whereas on the original it was true. BTW,
> in addition to copying the XExpression, I want to serialize it and
> interpret it later.
>
> I guess the questions then is: How do I (re)link a (serialized) copy to
> restore the implicitReceiver, before interpreting it using an
> XBaseInterpreter?
>
> Hallvard
>
> On 15.04.12 11.43, Jan Koehnlein wrote:
>> Usually, setting up an interpreter involves dealing with some
>> classloader trouble. Make sure the Java class qa.QAGamePlayerState is on
>> loadable by the XbaseInterpreter's classloader.
>>
>> The feature call's receiver resolution should be handled by the
>> org.eclipse.xtext.xbase.impl.FeatureCallToJavaMapping.getActualReceiver().
>>
>> The scope provider should have set the implicit receiver to a feature
>> call to "this".
>>
>>
>> Am 12.04.12 00:39, schrieb Hallvard Trætteberg:
>>> Hi,
>>>
>>> In my DSL for state machines I use a scope provider to provide a context
>>> for Xbase expressions. E.g. for the following snippet, the scope
>>> provider binds "this" to the qa.QAGamePlayerState type and this lets
>>> Xbase link the currentQA name in the "on enter" clause to
>>> qa.QAGamePlayerState's getCurrentQA() method. This seems to work as
>>> expected, since there are no parsing or linking errors.
>>>
>>> state playerState for qa.QAGamePlayerState {
>>> -> state init {
>>> on enter if currentQA == null do {
>>> currentQA = game.qas.head;
>>> };
>>> -> active on ~ currentQA;
>>> }
>>>
>>> Now I want to evaluate the expression using the XbaseInterpreter. I
>>> create an evaluation context and bind "this" to an instance of
>>> qa.QAGamePlayerState, as explained in
>>> http://www.eclipse.org/Xtext/documentation/2_0_0/199d-xbase-expressions.php#xbaseExpressions_6
>>>
>>>
>>>
>>> The hope is that this will be used by the interpreter as the context for
>>> the invocation of the getCurrentQA() method. However, instead I get an
>>> error message stating the getCurrentQA() cannot be invoked on a null.
>>> Stepping through the code, I see no trace of actually using the
>>> evaluation context to get the value of "this" when determining the
>>> receiver for the getCurrentQA() method.
>>>
>>> So, what am I doing wrong?
>>>
>>> Hallvard
>>
>>
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Providing context values for the Xbase interpreter [message #849664 is a reply to message #849551] Thu, 19 April 2012 10:52 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 19.04.12 10.40, Jan Koehnlein wrote:
> Counterquestion: Why copy?

The state machine is weaved with an instance tree, so that there is one
copy of the state for each corresponding instance. It is currently
possible to link back to the original XExpression, but want to 1) avoid
parsing in the runtime and 2) may need to customize each XExpression
copy for its corresponding instance.

In general, I think it should be possible to save a parsed XExpression
as part of an "ordinary" XMI file and interpret it in that context.
Hence the question: How do I (re)link a (serialized) copy to restore the
implicitReceiver (or otherwise prepare it), before interpreting it using
an XBaseInterpreter?

Hallvard

> Am 19.04.12 09:36, schrieb Hallvard Trætteberg:
>> Jan,
>>
>> I think I'm closing in on the problem: The left operand of == is an
>> XFeatureCall with an implicitReceiver set to another XFeatureCall, which
>> I assume corresponds to the "this" binding in the scope. However, the
>> XExpression that is interpreted is an (EcoreUtil.)copy of the original,
>> and in this copy the implicitReceiver is null! For this object
>> isFeatureLinked return false, whereas on the original it was true. BTW,
>> in addition to copying the XExpression, I want to serialize it and
>> interpret it later.
>>
>> I guess the questions then is: How do I (re)link a (serialized) copy to
>> restore the implicitReceiver, before interpreting it using an
>> XBaseInterpreter?
>>
>> Hallvard
>>
>> On 15.04.12 11.43, Jan Koehnlein wrote:
>>> Usually, setting up an interpreter involves dealing with some
>>> classloader trouble. Make sure the Java class qa.QAGamePlayerState is on
>>> loadable by the XbaseInterpreter's classloader.
>>>
>>> The feature call's receiver resolution should be handled by the
>>> org.eclipse.xtext.xbase.impl.FeatureCallToJavaMapping.getActualReceiver().
>>>
>>>
>>> The scope provider should have set the implicit receiver to a feature
>>> call to "this".
>>>
>>>
>>> Am 12.04.12 00:39, schrieb Hallvard Trætteberg:
>>>> Hi,
>>>>
>>>> In my DSL for state machines I use a scope provider to provide a
>>>> context
>>>> for Xbase expressions. E.g. for the following snippet, the scope
>>>> provider binds "this" to the qa.QAGamePlayerState type and this lets
>>>> Xbase link the currentQA name in the "on enter" clause to
>>>> qa.QAGamePlayerState's getCurrentQA() method. This seems to work as
>>>> expected, since there are no parsing or linking errors.
>>>>
>>>> state playerState for qa.QAGamePlayerState {
>>>> -> state init {
>>>> on enter if currentQA == null do {
>>>> currentQA = game.qas.head;
>>>> };
>>>> -> active on ~ currentQA;
>>>> }
>>>>
>>>> Now I want to evaluate the expression using the XbaseInterpreter. I
>>>> create an evaluation context and bind "this" to an instance of
>>>> qa.QAGamePlayerState, as explained in
>>>> http://www.eclipse.org/Xtext/documentation/2_0_0/199d-xbase-expressions.php#xbaseExpressions_6
>>>>
>>>>
>>>>
>>>>
>>>> The hope is that this will be used by the interpreter as the context
>>>> for
>>>> the invocation of the getCurrentQA() method. However, instead I get an
>>>> error message stating the getCurrentQA() cannot be invoked on a null.
>>>> Stepping through the code, I see no trace of actually using the
>>>> evaluation context to get the value of "this" when determining the
>>>> receiver for the getCurrentQA() method.
>>>>
>>>> So, what am I doing wrong?
>>>>
>>>> Hallvard
>>>
>>>
>>
>
>
Re: Providing context values for the Xbase interpreter [message #853812 is a reply to message #849664] Mon, 23 April 2012 10:56 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 19.04.12 12.52, Hallvard Trætteberg wrote:
> On 19.04.12 10.40, Jan Koehnlein wrote:
>> Counterquestion: Why copy?
>
> The state machine is weaved with an instance tree, so that there is one
> copy of the state for each corresponding instance. It is currently
> possible to link back to the original XExpression, but want to 1) avoid
> parsing in the runtime and 2) may need to customize each XExpression
> copy for its corresponding instance.
>
> In general, I think it should be possible to save a parsed XExpression
> as part of an "ordinary" XMI file and interpret it in that context.

From looking at the information that is preserved when serializing the
XExpression as XMI, it seems there is not enough information left to
(re)link. E.g. you wouldn't know if the implicit receiver was a this or
it reference, which would be important when (re)linking.

Can someone confirm that this (re)linking a XExpression saved as XMI (so
it can be interpreted) is in general impossible?

Hallvard

> Hence the question: How do I (re)link a (serialized) copy to restore the
> implicitReceiver (or otherwise prepare it), before interpreting it using
> an XBaseInterpreter?
>
> Hallvard
>
>> Am 19.04.12 09:36, schrieb Hallvard Trætteberg:
>>> Jan,
>>>
>>> I think I'm closing in on the problem: The left operand of == is an
>>> XFeatureCall with an implicitReceiver set to another XFeatureCall, which
>>> I assume corresponds to the "this" binding in the scope. However, the
>>> XExpression that is interpreted is an (EcoreUtil.)copy of the original,
>>> and in this copy the implicitReceiver is null! For this object
>>> isFeatureLinked return false, whereas on the original it was true. BTW,
>>> in addition to copying the XExpression, I want to serialize it and
>>> interpret it later.
>>>
>>> I guess the questions then is: How do I (re)link a (serialized) copy to
>>> restore the implicitReceiver, before interpreting it using an
>>> XBaseInterpreter?
>>>
>>> Hallvard
>>>
>>> On 15.04.12 11.43, Jan Koehnlein wrote:
>>>> Usually, setting up an interpreter involves dealing with some
>>>> classloader trouble. Make sure the Java class qa.QAGamePlayerState
>>>> is on
>>>> loadable by the XbaseInterpreter's classloader.
>>>>
>>>> The feature call's receiver resolution should be handled by the
>>>> org.eclipse.xtext.xbase.impl.FeatureCallToJavaMapping.getActualReceiver().
>>>>
>>>>
>>>>
>>>> The scope provider should have set the implicit receiver to a feature
>>>> call to "this".
>>>>
>>>>
>>>> Am 12.04.12 00:39, schrieb Hallvard Trætteberg:
>>>>> Hi,
>>>>>
>>>>> In my DSL for state machines I use a scope provider to provide a
>>>>> context
>>>>> for Xbase expressions. E.g. for the following snippet, the scope
>>>>> provider binds "this" to the qa.QAGamePlayerState type and this lets
>>>>> Xbase link the currentQA name in the "on enter" clause to
>>>>> qa.QAGamePlayerState's getCurrentQA() method. This seems to work as
>>>>> expected, since there are no parsing or linking errors.
>>>>>
>>>>> state playerState for qa.QAGamePlayerState {
>>>>> -> state init {
>>>>> on enter if currentQA == null do {
>>>>> currentQA = game.qas.head;
>>>>> };
>>>>> -> active on ~ currentQA;
>>>>> }
>>>>>
>>>>> Now I want to evaluate the expression using the XbaseInterpreter. I
>>>>> create an evaluation context and bind "this" to an instance of
>>>>> qa.QAGamePlayerState, as explained in
>>>>> http://www.eclipse.org/Xtext/documentation/2_0_0/199d-xbase-expressions.php#xbaseExpressions_6
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> The hope is that this will be used by the interpreter as the context
>>>>> for
>>>>> the invocation of the getCurrentQA() method. However, instead I get an
>>>>> error message stating the getCurrentQA() cannot be invoked on a null.
>>>>> Stepping through the code, I see no trace of actually using the
>>>>> evaluation context to get the value of "this" when determining the
>>>>> receiver for the getCurrentQA() method.
>>>>>
>>>>> So, what am I doing wrong?
>>>>>
>>>>> Hallvard
>>>>
>>>>
>>>
>>
>>
>
Re: Providing context values for the Xbase interpreter [message #853920 is a reply to message #853812] Mon, 23 April 2012 13:17 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Hallvard,

no, that's not possible for the exact reason that you describe.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 23.04.12 12:56, schrieb Hallvard Trætteberg:
> On 19.04.12 12.52, Hallvard Trætteberg wrote:
>> On 19.04.12 10.40, Jan Koehnlein wrote:
>>> Counterquestion: Why copy?
>>
>> The state machine is weaved with an instance tree, so that there is one
>> copy of the state for each corresponding instance. It is currently
>> possible to link back to the original XExpression, but want to 1) avoid
>> parsing in the runtime and 2) may need to customize each XExpression
>> copy for its corresponding instance.
>>
>> In general, I think it should be possible to save a parsed XExpression
>> as part of an "ordinary" XMI file and interpret it in that context.
>
> From looking at the information that is preserved when serializing the
> XExpression as XMI, it seems there is not enough information left to
> (re)link. E.g. you wouldn't know if the implicit receiver was a this or
> it reference, which would be important when (re)linking.
>
> Can someone confirm that this (re)linking a XExpression saved as XMI (so
> it can be interpreted) is in general impossible?
>
> Hallvard
>
>> Hence the question: How do I (re)link a (serialized) copy to restore the
>> implicitReceiver (or otherwise prepare it), before interpreting it using
>> an XBaseInterpreter?
>>
>> Hallvard
>>
>>> Am 19.04.12 09:36, schrieb Hallvard Trætteberg:
>>>> Jan,
>>>>
>>>> I think I'm closing in on the problem: The left operand of == is an
>>>> XFeatureCall with an implicitReceiver set to another XFeatureCall,
>>>> which
>>>> I assume corresponds to the "this" binding in the scope. However, the
>>>> XExpression that is interpreted is an (EcoreUtil.)copy of the original,
>>>> and in this copy the implicitReceiver is null! For this object
>>>> isFeatureLinked return false, whereas on the original it was true. BTW,
>>>> in addition to copying the XExpression, I want to serialize it and
>>>> interpret it later.
>>>>
>>>> I guess the questions then is: How do I (re)link a (serialized) copy to
>>>> restore the implicitReceiver, before interpreting it using an
>>>> XBaseInterpreter?
>>>>
>>>> Hallvard
>>>>
>>>> On 15.04.12 11.43, Jan Koehnlein wrote:
>>>>> Usually, setting up an interpreter involves dealing with some
>>>>> classloader trouble. Make sure the Java class qa.QAGamePlayerState
>>>>> is on
>>>>> loadable by the XbaseInterpreter's classloader.
>>>>>
>>>>> The feature call's receiver resolution should be handled by the
>>>>> org.eclipse.xtext.xbase.impl.FeatureCallToJavaMapping.getActualReceiver().
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> The scope provider should have set the implicit receiver to a feature
>>>>> call to "this".
>>>>>
>>>>>
>>>>> Am 12.04.12 00:39, schrieb Hallvard Trætteberg:
>>>>>> Hi,
>>>>>>
>>>>>> In my DSL for state machines I use a scope provider to provide a
>>>>>> context
>>>>>> for Xbase expressions. E.g. for the following snippet, the scope
>>>>>> provider binds "this" to the qa.QAGamePlayerState type and this lets
>>>>>> Xbase link the currentQA name in the "on enter" clause to
>>>>>> qa.QAGamePlayerState's getCurrentQA() method. This seems to work as
>>>>>> expected, since there are no parsing or linking errors.
>>>>>>
>>>>>> state playerState for qa.QAGamePlayerState {
>>>>>> -> state init {
>>>>>> on enter if currentQA == null do {
>>>>>> currentQA = game.qas.head;
>>>>>> };
>>>>>> -> active on ~ currentQA;
>>>>>> }
>>>>>>
>>>>>> Now I want to evaluate the expression using the XbaseInterpreter. I
>>>>>> create an evaluation context and bind "this" to an instance of
>>>>>> qa.QAGamePlayerState, as explained in
>>>>>> http://www.eclipse.org/Xtext/documentation/2_0_0/199d-xbase-expressions.php#xbaseExpressions_6
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> The hope is that this will be used by the interpreter as the context
>>>>>> for
>>>>>> the invocation of the getCurrentQA() method. However, instead I
>>>>>> get an
>>>>>> error message stating the getCurrentQA() cannot be invoked on a null.
>>>>>> Stepping through the code, I see no trace of actually using the
>>>>>> evaluation context to get the value of "this" when determining the
>>>>>> receiver for the getCurrentQA() method.
>>>>>>
>>>>>> So, what am I doing wrong?
>>>>>>
>>>>>> Hallvard
>>>>>
>>>>>
>>>>
>>>
>>>
>>
>
Previous Topic:Possible bug due to keywords with "special" chars
Next Topic:Strage Memory leak in Semantic Highlighting
Goto Forum:
  


Current Time: Thu Mar 28 10:47:00 GMT 2024

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

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

Back to the top