Home » Modeling » TMF (Xtext) » Providing context values for the Xbase interpreter
|
Re: Providing context values for the Xbase interpreter [message #845678 is a reply to message #841971] |
Sun, 15 April 2012 09:43 |
Jan Koehnlein 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 |
Hallvard Traetteberg 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 |
Jan Koehnlein 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 |
Hallvard Traetteberg 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 |
Hallvard Traetteberg 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 |
Sebastian Zarnekow 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
>>>>>
>>>>>
>>>>
>>>
>>>
>>
>
|
|
|
Goto Forum:
Current Time: Thu Sep 19 09:50:11 GMT 2024
Powered by FUDForum. Page generated in 0.04800 seconds
|