Skip to main content



      Home
Home » Modeling » TMF (Xtext) » debugging DSL serialisation
debugging DSL serialisation [message #52874] Thu, 25 June 2009 13:44 Go to next message
Eclipse UserFriend
Hi,

I'm experiencing an exception while trying to save a transformed model to
an XText DSL grammar.

I'm having trouble debugging what the problem is - I was hoping for some
advice.

I'm fairly new to the eclipse modeling world - so please forgive any
naivety (but I have years of experience writing metamodels/m2m/m2t in MOF
and other tools - so I'll understand the concepts).

So - I have two XText dsls, a model in one language, and a transformation
to transform it to the other. I have a MWE workflow to load the first
model, run the transformation, then save the transformed model to a new
file.

The final Writer step falls over with an exception. To be honest I don't
fully understand it, but it seems to suggest that I haven't properly
created a serialisable model (so really the problem is probably in my m2m
transformation). The exception mentions a particular instance in the
target model - if I remove that instance I don't get the error (it's the
only instance of that type in the model).

Here's the exception:
org.eclipse.xtext.parsetree.reconstr.XtextSerializationExcep tion:
Serialization failed
<# of serialized tokens>: "<serializable fragment, starting from the end>":
-> <possible reasons for not continuing>
107: "controller usecase1 { outcome-state-action event_ou...":
-> Can not leave rule 'Controller' since the current object 'Controller'
has features with unconsumed values: 'states':1
104: ", finished , cancelled } outcome-state-action outco...":
-> OutcomeAction_StatesAssignment_4_1: All 2 values of
OutcomeAction.states have been consumed. More are needed to continue here.
104: "controller usecase1 { outcome-state-action event_ou...":
-> Can not leave rule 'Controller' since the current object 'Controller'
has features with unconsumed values: 'states':1
104: "controller usecase1 { outcome-state-action event_ou...":
-> Can not leave rule 'Controller' since the current object 'Controller'
has features with unconsumed values: 'states':1
101: "outcome-state-action event_outcomes_view1 { cancell...":
-> Can not leave rule 'OutcomeAction' since the current object
'OutcomeAction' has features with unconsumed values: 'states':1

at
org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeC onstructor.serialize(AbstractParseTreeConstructor.java:432)
at
org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeC onstructor.serialize(AbstractParseTreeConstructor.java:378)
at
org.eclipse.xtext.parsetree.reconstr.SerializerUtil.serializ e(SerializerUtil.java:47)
at
org.eclipse.xtext.parsetree.reconstr.SerializerUtil.serializ e(SerializerUtil.java:52)
at org.eclipse.xtext.resource.XtextResource.doSave(XtextResourc e.java:188)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1406)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:993)
at org.eclipse.emf.mwe.utils.Writer.write(Writer.java:149)


So - I wonder where to go from here.

The type in question:

OutcomeAction:
'outcome-state-action' name=ID '{' states+=[State] (','
states+=[State])* '}';

The message seems to say it found 2 instances of State to assign to
"states", but needed more than 2. I doubt I've interpreted it correctly,
though - my DSL definition seems to allow 1 or more States in "states"...
Re: debugging DSL serialisation [message #52903 is a reply to message #52874] Thu, 25 June 2009 13:55 Go to previous messageGo to next message
Eclipse UserFriend
Hmm - okay - a little more info:

I've switched to XMI serialisation to see whether it could save the model
- it does.

I've also reduced the model to a single element that reproduces the
problem, so it's easy to navigate the XMI by eye or in the XMI tree editor
- it seems to have produced a valid model, with all the expected
references set.

So - now I think the error message isn't complaining about the model, so
much as being unable to format it with the grammar I've chosen...
Re: debugging DSL serialisation [message #52927 is a reply to message #52874] Thu, 25 June 2009 14:24 Go to previous messageGo to next message
Eclipse UserFriend
Hi Antony,

thanks for the detailed information in your post. The problem seems to
be the rule Controller instead of OutcomeAction. Would you please be so
kind and post this part of your grammar as well. Maybe you can attach a
minimal sample model?

Regards,
Sebastian

Am 25.06.2009 19:44 Uhr, schrieb Antony Wilkins:
> Hi,
>
> I'm experiencing an exception while trying to save a transformed model
> to an XText DSL grammar.
>
> I'm having trouble debugging what the problem is - I was hoping for some
> advice.
>
> I'm fairly new to the eclipse modeling world - so please forgive any
> naivety (but I have years of experience writing metamodels/m2m/m2t in
> MOF and other tools - so I'll understand the concepts).
>
> So - I have two XText dsls, a model in one language, and a
> transformation to transform it to the other. I have a MWE workflow to
> load the first model, run the transformation, then save the transformed
> model to a new file.
>
> The final Writer step falls over with an exception. To be honest I don't
> fully understand it, but it seems to suggest that I haven't properly
> created a serialisable model (so really the problem is probably in my
> m2m transformation). The exception mentions a particular instance in the
> target model - if I remove that instance I don't get the error (it's the
> only instance of that type in the model).
>
> Here's the exception:
> org.eclipse.xtext.parsetree.reconstr.XtextSerializationExcep tion:
> Serialization failed
> <# of serialized tokens>: "<serializable fragment, starting from the end>":
> -> <possible reasons for not continuing>
> 107: "controller usecase1 { outcome-state-action event_ou...":
> -> Can not leave rule 'Controller' since the current object 'Controller'
> has features with unconsumed values: 'states':1
> 104: ", finished , cancelled } outcome-state-action outco...":
> -> OutcomeAction_StatesAssignment_4_1: All 2 values of
> OutcomeAction.states have been consumed. More are needed to continue here.
> 104: "controller usecase1 { outcome-state-action event_ou...":
> -> Can not leave rule 'Controller' since the current object 'Controller'
> has features with unconsumed values: 'states':1
> 104: "controller usecase1 { outcome-state-action event_ou...":
> -> Can not leave rule 'Controller' since the current object 'Controller'
> has features with unconsumed values: 'states':1
> 101: "outcome-state-action event_outcomes_view1 { cancell...":
> -> Can not leave rule 'OutcomeAction' since the current object
> 'OutcomeAction' has features with unconsumed values: 'states':1
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeC onstructor.serialize(AbstractParseTreeConstructor.java:432)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeC onstructor.serialize(AbstractParseTreeConstructor.java:378)
>
> at
> org.eclipse.xtext.parsetree.reconstr.SerializerUtil.serializ e(SerializerUtil.java:47)
>
> at
> org.eclipse.xtext.parsetree.reconstr.SerializerUtil.serializ e(SerializerUtil.java:52)
>
> at org.eclipse.xtext.resource.XtextResource.doSave(XtextResourc e.java:188)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1406)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:993)
>
> at org.eclipse.emf.mwe.utils.Writer.write(Writer.java:149)
>
>
> So - I wonder where to go from here.
>
> The type in question:
> OutcomeAction:
> 'outcome-state-action' name=ID '{' states+=[State] (','
> states+=[State])* '}';
>
> The message seems to say it found 2 instances of State to assign to
> "states", but needed more than 2. I doubt I've interpreted it correctly,
> though - my DSL definition seems to allow 1 or more States in "states"...
>
Re: debugging DSL serialisation [message #53051 is a reply to message #52927] Thu, 25 June 2009 21:11 Go to previous messageGo to next message
Eclipse UserFriend
Hi Sebastian,

Thanks for the speedy reply!

Here's the things I think are relevant:

Controller:
'controller' name=ID '{'
(actions+=Action)*
(commonTransitions+=CommonTransition)*
('on start' entryAction+=[Action])*
(states+=StartState)
(states+=RunningState)+
(states+=StopState)+
('on end' exitAction+=[Action])*
'}';

State:
StartState|StartedState;

StartedState:
RunningState|StopState;

StartState:
'start-state' ref=[RunningState];

StopState:
'stop-state' name=ID;

RunningState:
EventWaitingState | ActionState | SubControllerState;

EventWaitingState:
'wait-state' name=ID '{'
('on-entry' entryAction+=[Action])*
((transitions+=SimpleTransition)|(transitions+=CommonTransit ionRef))+
('on-exit' exitAction+=[Action])*
'}';


and here's a model that produces the error:

<mVC:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mVC="http://www.antonywilkins.com/mdd/mvc/dsl/MVC"
xsi:schemaLocation="http://www.antonywilkins.com/mdd/mvc/dsl/MVC
java://com.antonywilkins.mdd.mvc.dsl.mVC.MVCPackage">
<controllers name="usecase1">
<actions xsi:type="mVC:OutcomeAction" name="event_outcomes_view1"
states="//@controllers.0/@states.3 //@controllers.0/@states.4"/>
<states xsi:type="mVC:OutcomeActionState" name="event_outcomes_view1"
action="//@controllers.0/@actions.0"/>
<states xsi:type="mVC:StartState" ref="//@controllers.0/@states.2"/>
<states xsi:type="mVC:EventWaitingState" name="view1">
<transitions xsi:type="mVC:SimpleTransition"
to="//@controllers.0/@states.0">
<event name="ok"/>
</transitions>
<transitions xsi:type="mVC:SimpleTransition"
to="//@controllers.0/@states.0">
<event name="cancel"/>
</transitions>
</states>
<states xsi:type="mVC:StopState" name="finished"/>
<states xsi:type="mVC:StopState" name="cancelled"/>
</controllers>
</mVC:Model>

This is the textual version I *think* it should produce:

controller myController {
outcome-state-action event_outcomes_view1 { finished , cancelled }

start-state view1

wait-state view1 {
event ok go to handle_events_view1
event cancel go to event_outcomes_view1
}

action-state event_outcomes_view1 outcomes event_outcomes_view1

stop-state finished

stop-state cancelled
}

As you can guess, I've taken the famous state machine example and altered
it a bit to fit an MVC framework like spring webflow or struts. (You'll
thing that model is a bit odd - it's the result of a transformation from
something else that has a different take on state machines - less verbose,
but less flexible).


Sebastian Zarnekow wrote:

> Hi Antony,

> thanks for the detailed information in your post. The problem seems to
> be the rule Controller instead of OutcomeAction. Would you please be so
> kind and post this part of your grammar as well. Maybe you can attach a
> minimal sample model?

> Regards,
> Sebastian
Re: debugging DSL serialisation [message #53076 is a reply to message #53051] Thu, 25 June 2009 21:12 Go to previous messageGo to next message
Eclipse UserFriend
(Sorry - my browser screwed up the formatting!)
Re: debugging DSL serialisation [message #53101 is a reply to message #53051] Thu, 25 June 2009 21:21 Go to previous messageGo to next message
Eclipse UserFriend
Ah - *that* Sebastian - I knew I recalled the name. We met the other week
at CG2009. I've been XTexting ever since :) (and finding it an absolute
joy to work with - I'm more productive in this after a week of spare time,
than I am at work using our existing MDD stuff).
Re: debugging DSL serialisation [message #53127 is a reply to message #53051] Fri, 26 June 2009 04:07 Go to previous messageGo to next message
Eclipse UserFriend
Hi Antony,

nice to see that you are an Xtext-fan by now ;-)

I cannot find a rule for a type OutcomeActionState in your grammar
snippet. Is it due to the fact, that you simply didn't copy it into the
post or is it actually missing in your grammar?

If you don't mind, you could send my your grammar and your sample model
(or even better: a small sample project with a testcase) and I'll have a
look into this issue. Currently I'm afraid that you stumbled across a bug.

Regards,
Sebastian

Am 26.06.2009 3:11 Uhr, schrieb Antony Wilkins:
> Hi Sebastian,
>
> Thanks for the speedy reply!
>
> Here's the things I think are relevant:
>
> Controller:
> 'controller' name=ID '{' (actions+=Action)*
> (commonTransitions+=CommonTransition)* ('on start' entryAction+=[Action])*
> (states+=StartState) (states+=RunningState)+
> (states+=StopState)+ ('on end' exitAction+=[Action])*
> '}';
>
> State:
> StartState|StartedState;
>
> StartedState:
> RunningState|StopState;
>
> StartState:
> 'start-state' ref=[RunningState];
>
> StopState:
> 'stop-state' name=ID;
>
> RunningState:
> EventWaitingState | ActionState | SubControllerState;
> EventWaitingState:
> 'wait-state' name=ID '{'
> ('on-entry' entryAction+=[Action])*
> ((transitions+=SimpleTransition)|(transitions+=CommonTransit ionRef))+
> ('on-exit' exitAction+=[Action])* '}';
>
>
> and here's a model that produces the error:
>
> <mVC:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:mVC="http://www.antonywilkins.com/mdd/mvc/dsl/MVC"
> xsi:schemaLocation="http://www.antonywilkins.com/mdd/mvc/dsl/MVC
> java://com.antonywilkins.mdd.mvc.dsl.mVC.MVCPackage">
> <controllers name="usecase1">
> <actions xsi:type="mVC:OutcomeAction" name="event_outcomes_view1"
> states="//@controllers.0/@states.3 //@controllers.0/@states.4"/>
> <states xsi:type="mVC:OutcomeActionState" name="event_outcomes_view1"
> action="//@controllers.0/@actions.0"/>
> <states xsi:type="mVC:StartState" ref="//@controllers.0/@states.2"/>
> <states xsi:type="mVC:EventWaitingState" name="view1">
> <transitions xsi:type="mVC:SimpleTransition"
> to="//@controllers.0/@states.0">
> <event name="ok"/>
> </transitions>
> <transitions xsi:type="mVC:SimpleTransition"
> to="//@controllers.0/@states.0">
> <event name="cancel"/>
> </transitions>
> </states>
> <states xsi:type="mVC:StopState" name="finished"/>
> <states xsi:type="mVC:StopState" name="cancelled"/>
> </controllers>
> </mVC:Model>
>
> This is the textual version I *think* it should produce:
>
> controller myController {
> outcome-state-action event_outcomes_view1 { finished , cancelled }
>
> start-state view1
>
> wait-state view1 {
> event ok go to handle_events_view1
> event cancel go to event_outcomes_view1
> }
>
> action-state event_outcomes_view1 outcomes event_outcomes_view1
>
> stop-state finished
>
> stop-state cancelled
> }
>
> As you can guess, I've taken the famous state machine example and
> altered it a bit to fit an MVC framework like spring webflow or struts.
> (You'll thing that model is a bit odd - it's the result of a
> transformation from something else that has a different take on state
> machines - less verbose, but less flexible).
>
>
> Sebastian Zarnekow wrote:
>
>> Hi Antony,
>
>> thanks for the detailed information in your post. The problem seems to
>> be the rule Controller instead of OutcomeAction. Would you please be
>> so kind and post this part of your grammar as well. Maybe you can
>> attach a minimal sample model?
>
>> Regards,
>> Sebastian
>
>
Re: debugging DSL serialisation [message #53153 is a reply to message #53101] Fri, 26 June 2009 04:15 Go to previous messageGo to next message
Eclipse UserFriend
May I quote you? ;-)

Am 26.06.2009 3:21 Uhr, schrieb Antony Wilkins:
> I've been XTexting ever since :) (and finding it an absolute joy to
> work with - I'm more productive in this after a week of spare time, than
> I am at work using our existing MDD stuff).
Re: debugging DSL serialisation [message #53229 is a reply to message #53051] Fri, 26 June 2009 08:34 Go to previous messageGo to next message
Eclipse UserFriend
Hi Antony,

could you try to put your model elements in "state" in the same order as
they would appear in the textual model?

For example, your grammar implies that the start state always should be
the first. Therefore, it must be at this position in the list of states
as well. However, your XMI shows that an OutcomeActionState is at the
first position...

If you don't like the idea that your grammar introduces this constraint,
you can express it like this:

Controller:
'controller' name=ID '{' (actions+=Action)*
(commonTransitions+=CommonTransition)* ('on start'
entryAction+=[Action])*
(states+=State)+ ('on end' exitAction+=[Action])*
'}';

Or, to keep the constrain that you need exactly one start state and at
least one running state and one stop state, you could store the states
in separate features:

Controller:
'controller' name=ID '{' (actions+=Action)*
(commonTransitions+=CommonTransition)* ('on start'
entryAction+=[Action])*
(startState=StartState) (runningStates+=RunningState)+
(stopStates+=StopState)+ ('on end' exitAction+=[Action])*
'}';

hth,
Moritz


> Hi Sebastian,
>
> Thanks for the speedy reply!
>
> Here's the things I think are relevant:
>
> Controller:
> 'controller' name=ID '{' (actions+=Action)*
> (commonTransitions+=CommonTransition)* ('on start'
> entryAction+=[Action])*
> (states+=StartState) (states+=RunningState)+
> (states+=StopState)+ ('on end' exitAction+=[Action])*
> '}';
>
> State:
> StartState|StartedState;
>
> StartedState:
> RunningState|StopState;
>
> StartState:
> 'start-state' ref=[RunningState];
>
> StopState:
> 'stop-state' name=ID;
>
> RunningState:
> EventWaitingState | ActionState | SubControllerState;
> EventWaitingState:
> 'wait-state' name=ID '{'
> ('on-entry' entryAction+=[Action])*
> ((transitions+=SimpleTransition)|(transitions+=CommonTransit ionRef))+
> ('on-exit' exitAction+=[Action])* '}';
>
>
> and here's a model that produces the error:
>
> <mVC:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:mVC="http://www.antonywilkins.com/mdd/mvc/dsl/MVC"
> xsi:schemaLocation="http://www.antonywilkins.com/mdd/mvc/dsl/MVC
> java://com.antonywilkins.mdd.mvc.dsl.mVC.MVCPackage">
> <controllers name="usecase1">
> <actions xsi:type="mVC:OutcomeAction" name="event_outcomes_view1"
> states="//@controllers.0/@states.3 //@controllers.0/@states.4"/>
> <states xsi:type="mVC:OutcomeActionState" name="event_outcomes_view1"
> action="//@controllers.0/@actions.0"/>
> <states xsi:type="mVC:StartState" ref="//@controllers.0/@states.2"/>
> <states xsi:type="mVC:EventWaitingState" name="view1">
> <transitions xsi:type="mVC:SimpleTransition"
> to="//@controllers.0/@states.0">
> <event name="ok"/>
> </transitions>
> <transitions xsi:type="mVC:SimpleTransition"
> to="//@controllers.0/@states.0">
> <event name="cancel"/>
> </transitions>
> </states>
> <states xsi:type="mVC:StopState" name="finished"/>
> <states xsi:type="mVC:StopState" name="cancelled"/>
> </controllers>
> </mVC:Model>
>
> This is the textual version I *think* it should produce:
>
> controller myController {
> outcome-state-action event_outcomes_view1 { finished , cancelled }
>
> start-state view1
>
> wait-state view1 {
> event ok go to handle_events_view1
> event cancel go to event_outcomes_view1
> }
>
> action-state event_outcomes_view1 outcomes event_outcomes_view1
>
> stop-state finished
>
> stop-state cancelled
> }
>
> As you can guess, I've taken the famous state machine example and
> altered it a bit to fit an MVC framework like spring webflow or struts.
> (You'll thing that model is a bit odd - it's the result of a
> transformation from something else that has a different take on state
> machines - less verbose, but less flexible).
>
>
> Sebastian Zarnekow wrote:
>
>> Hi Antony,
>
>> thanks for the detailed information in your post. The problem seems to
>> be the rule Controller instead of OutcomeAction. Would you please be
>> so kind and post this part of your grammar as well. Maybe you can
>> attach a minimal sample model?
>
>> Regards,
>> Sebastian
>
>
Re: debugging DSL serialisation [message #53255 is a reply to message #53153] Fri, 26 June 2009 11:38 Go to previous messageGo to next message
Eclipse UserFriend
Absolutely :) - and to put it into perspective - I've been writing MDD
tool-chains for about six years using MOF based metamodeling/m2m/m2t.
Re: debugging DSL serialisation [message #53282 is a reply to message #53127] Fri, 26 June 2009 11:57 Go to previous messageGo to next message
Eclipse UserFriend
Sure - how do I send you a full project? Can I upload/email an archive
file somewhere or do you mean for me to post the important files as text
here?

Or - how about if I were to give you an SVN link?

https://eclipsecoding.svn.sourceforge.net/svnroot/eclipsecod ing/tags/dsl/serialisation_problem

there are subfolders for XText dsl projects - I think these are the
important ones

com.antonywilkins.mdd.usecase_director.dsl - the transformation source
metamodel
com.antonywilkins.mdd.mvc.dsl - the transformation target metamodel
com.antonywilkins.mdd.ucd_mvc.m2m.generator - the model to model
transformation.

(The other ui projects are also in there).

The last project (com.antonywilkins.mdd.ucd_mvc.m2m.generator) has an mwe:
src/workflow/Ucd2MvcGenerator.mwe

Run that to reproduce the error. It takes the source model from
src/model/MyModel.ucd, transforms to the target model then writes the
target model to src-gen/Usecase.mvc (which is the bit that fails).
Re: debugging DSL serialisation [message #53309 is a reply to message #53229] Fri, 26 June 2009 12:22 Go to previous messageGo to next message
Eclipse UserFriend
That was it - yes - I was putting a non-StartState before the StartState,
contrary to my grammar rules, but not contrary to my metamodel. I see -
hence I was able to store it as XMI.

I tried one of your options and it fixes it! Thank you so much! And
thanks to Sebastian for his kind offer to have a look at the full project
and his help so far.

I went with your second option, because I like the constraints being
effectively expressed in my metamodel definition, and because it's nice to
have the grammar enforce it without having to write validation logic.

(So far I've been able to keep rules out of the validation, just by
scoping things correctly - with the added benefit of adding a bit more
semantics, and getting IDE things like content proposals and validation
for free).

The downside is I have to write a "getAllStates()" operation in my
transformation logic, but that's a small price to pay.

On the subject of adapter logic - I'm finding that XTend is very nice
place to decorate my metamodel with behaviour - great for re-use in m2m
and m2t transformations. Sometimes, though, I want to re-use the logic in
the DSL Validator/ScopeProvider/ContentProposers. Is the easiest way just
to write it in Java static methods and call the operations from there in
the XTend, or is there a way to reuse XTend definitions in Java?
Re: debugging DSL serialisation [message #53336 is a reply to message #53282] Fri, 26 June 2009 12:30 Go to previous messageGo to next message
Eclipse UserFriend
See Moritz reply and my response to that. He spotted the problem - my
model didn't conform to my grammar rules, while still being a valid model
to save as XMI.

Thanks for your help with this - it's increased my understanding a great
deal.

Thanks also for your offer to look at my code in more detail :)
Re: debugging DSL serialisation [message #53583 is a reply to message #53309] Sat, 27 June 2009 14:45 Go to previous messageGo to next message
Eclipse UserFriend
Hi Antony,

have a look at the post processing step of the Ecore model generation.
It allows to add custom properties and operation to your model.

See here:
http://www.eclipse.org/Xtext/documentation/0_7_0/xtext.html# metamodelInference

That is currently the only way to make the model more oo'ish and get rid
of static helper methods.

Regards,
Sebastian



Am 26.06.2009 18:22 Uhr, schrieb Antony Wilkins:
> That was it - yes - I was putting a non-StartState before the
> StartState, contrary to my grammar rules, but not contrary to my
> metamodel. I see - hence I was able to store it as XMI.
>
> I tried one of your options and it fixes it! Thank you so much! And
> thanks to Sebastian for his kind offer to have a look at the full
> project and his help so far.
>
> I went with your second option, because I like the constraints being
> effectively expressed in my metamodel definition, and because it's nice
> to have the grammar enforce it without having to write validation logic.
>
> (So far I've been able to keep rules out of the validation, just by
> scoping things correctly - with the added benefit of adding a bit more
> semantics, and getting IDE things like content proposals and validation
> for free).
>
> The downside is I have to write a "getAllStates()" operation in my
> transformation logic, but that's a small price to pay.
>
> On the subject of adapter logic - I'm finding that XTend is very nice
> place to decorate my metamodel with behaviour - great for re-use in m2m
> and m2t transformations. Sometimes, though, I want to re-use the logic
> in the DSL Validator/ScopeProvider/ContentProposers. Is the easiest way
> just to write it in Java static methods and call the operations from
> there in the XTend, or is there a way to reuse XTend definitions in Java?
>
>
>
>
Re: debugging DSL serialisation [message #53661 is a reply to message #53583] Sat, 27 June 2009 17:23 Go to previous messageGo to next message
Eclipse UserFriend
Ah!

I've had a go - and it works fine :)

I wonder if I'm doing things the hard way though - so let me show you what
I've done (PostProcessor.ext file contents at the end).

I still need my static helper methods, because they may have complex code
that I'd like to edit in the "normal" way. That's no problem.

You see I'm jumping though some hoops to get instances of EClassifier,
though - does what I'm doing seem sensible (calling a JAVA method to
return the EClassifer)? I don't seem to be able to call
EcorePackage.eINSTANCE.getEBoolean() (or
MyDslPackage.eINSTANCE.getMyType()) easily from the xtend - I think I'm
probably doing something stupid and overblown!


import entity;
import xtext;

process(xtext::GeneratedMetamodel this) :
process(ePackage)
;

process(ecore::EPackage this) :
eContents.typeSelect(ecore::EClass).process()
;

process(ecore::EClass this) :
switch (name) {
case "Type" : createTypeOperations()
default:null
}
;

createTypeOperations(ecore::EClass this):
eOperations.add(createIsAssignable())
;

create ecore::EOperation this createIsAssignable():
setEType(booleanType()) ->
eParameters.add(createClassDefParameter()) ->
setName("isAssignable") ->
eAnnotations.add(createIsAssignableBody());

create ecore::EParameter this createClassDefParameter():
setName("classDef") ->
setEType(classDefType());

create ecore::EAnnotation this createIsAssignableBody():
setSource("http://www.eclipse.org/emf/2002/GenModel")->
details.add(createIsAssignableBodyDetail());

create ecore::EStringToStringMapEntry this createIsAssignableBodyDetail():
setKey("body") ->
setValue("return
<%com.antonywilkins.mdd.entity.dsl.EntityModelUtil%>.typeIsAssignable(this,
classDef);");


ecore::EClassifier booleanType() : JAVA
com.antonywilkins.mdd.ecore.util.EcoreUtil.eBooleanType();

ecore::EClassifier classDefType() : JAVA
com.antonywilkins.mdd.entity.dsl.EntityModelUtil.classDefTyp e();
Re: debugging DSL serialisation [message #53762 is a reply to message #53661] Sun, 28 June 2009 03:05 Go to previous messageGo to next message
Eclipse UserFriend
Hi Anthony,

I don't know where your ClassDef type is declared, but you should be able
to use the same trick as for EBoolean here. I.e. given an EObject of the
correct EPackage you can access the EPackage using eClass().ePackage.

cached booleanType() :
ecoreType("EBoolean")
;

cached ecoreType(String name) :
new EObject.eClass().ePackage.getEClassifier(name)
;

If ClassDef is contained by the EPackage you're currently transforming,
it's of course much simpler.

Alternatively you could also write a utility Java extension that given an
xpand2::Type (corresponds to Java interface Type) returns the
corresponding EClassifier (where appropriate).

Hope that helps,

--knut

Antony Wilkins wrote:

> You see I'm jumping though some hoops to get instances of EClassifier,
> though - does what I'm doing seem sensible (calling a JAVA method to
> return the EClassifer)? I don't seem to be able to call
> EcorePackage.eINSTANCE.getEBoolean() (or
> MyDslPackage.eINSTANCE.getMyType()) easily from the xtend - I think I'm
> probably doing something stupid and overblown!
Re: debugging DSL serialisation [message #53815 is a reply to message #53762] Sun, 28 June 2009 04:05 Go to previous message
Eclipse UserFriend
I knew I'd be missing a trick - thanks - that's much nicer :)
Previous Topic:DSL project creation - extention points?
Next Topic:oaw to tmf grammar problem
Goto Forum:
  


Current Time: Tue May 13 15:58:26 EDT 2025

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

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

Back to the top