[Acceleo] Syntax problems [message #538201] |
Sun, 06 June 2010 07:00  |
Eclipse User |
|
|
|
Hi again, I am having some trouble debugging some problems which araised when doing an automatic mt2mtl conversion:
1- There are some functions like filter which existed in .mt for ENode and I cant find how can I map to mtl ones, for example:
[if (self->select(not (filter(Behavior))) <> null and not (owner.eClass().name.toLower() = 'Class'.toLower()))]
Which comes from
<%if (current[!filter("Behavior")] != null && !owner.eClass.name.equalsIgnoreCase("Class")){%>
I tried:
[if (self->filter(Behavior) <> null and not (owner.eClass().name.toLower() = 'Class'.toLower()))]
Am I doing the conversion right?
2- Other case:
<%if (general != null){%>extends <%general.nFirst().genName%> <%}%>
Migrated to:
[if (general <> null)]extends [general->first().genName()/] [/if]
I couldnt find the first() operation for general so I did:
[if (general <> null)]extends [general.genName()/] [/if]
Is it right?
3- In .mt I had:
<%script type="Element" name="isArray" post="trim"%>
<%(getProperty("tuple.genArrays") == true)%>
Migrated to:
[query public isArray(element : Element) post(trim()) : Boolean = (getProperty('tuple.genArrays') = true)/]
To correct it I eliminated the post(trim()) and changed the true to 'true':
[query public isArray(element : Element) : Boolean = (getProperty('tuple.genArrays') = 'true')/]
Is that right?
4- I was unable to fix some problems, in .mt I had:
<%script type="Classifier" name="genImport" post="trim()" %>
<%if (!isArray){%>
<%if ((ownedMember.filter("Operation").ownedParameter + ownedMember.filter("Property")+ getAssociations().navigableOwnedEnd)[(upper == -1 || upper > 1) && isOrdered] != null){%>
import <%getOrderedCollectionClassPath%>;
<%}%>
<%if ((ownedMember.filter("Operation").ownedParameter + ownedMember.filter("Property") + getAssociations().navigableOwnedEnd)[(upper == -1 || upper > 1) && !isOrdered] != null){%>
import <%getNotOrderedCollectionClassPath%>;
<%}%>
<%}%>
The automatic migration was:
[if ((ownedMember->filter(Operation).ownedParameter + ownedMember->filter(Property) + getAssociations.navigableOwnedEnd)->select((upper = -1 or upper > 1) and isOrdered) <> null)]
From:
<%if ((ownedMember.filter("Operation").ownedParameter + ownedMember.filter("Property")+ getAssociations().navigableOwnedEnd)[(upper == -1 || upper > 1) && isOrdered] != null){%>
The problem it gaves me is:
"Cannont find operation (+(Collection(Property))) for the type Bag(Parameter))
I tried to solve it with the union operation like I did befor but I couldnt.
5- Also:
[template public getTypeList(interface : Interface)]
[ownedAttribute.type + getAssociations.navigableOwnedEnd->select(type<>current(1)).type + ownedOperation.ownedParameter.type + general->first() + nestedClassifier->filter(Class).getTypeList()/]
From:
<%script type="Interface" name="getTypeList" post="nMinimize()" %>
<%ownedAttribute.type
+ getAssociations().navigableOwnedEnd.select("type!=current(1) ").type
+ ownedOperation.ownedParameter.type
+ general.nFirst()
+ nestedClassifier.filter("Class").getTypeList%>
Fails, and the problem is "Unrecognized variable: (getAssociations)"
Why is it treating it as a variable? How can I fix it?
Thank you very much again.
|
|
|
|
|
|
Re: [Acceleo] Syntax problems [message #538783 is a reply to message #538752] |
Tue, 08 June 2010 11:42   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------080200060806020605020708
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Daniel,
See comments inlined below.
Laurent Goubet
Obeo
Daniel wrote:
> Hi again and thank you both for your answers.
>
> For the filter problem I tried what you said:
>
> [if (not (self.oclIsKindOf(Behavior)) and
> not(owner.eClass().name.equalsIgnoreCase('Class')))]
>
> And it seems it works :)
Nice to hear.
>
> I have been working in the other problems, now I know that to solve:
>
> "Unrecognized variable: (getAssociations)"
>
> I only had to add the (), getAssociations().
>
> But I still dont know how to migrate some code:
>
> 1-
> [if ((ownedMember->filter(Operation).ownedParameter +
> ownedMember->filter(Property) +
> getAssociations.navigableOwnedEnd)->select((upper = -1 or upper > 1) and
> isOrdered) <> null)]
>
> From:
>
> <%if ((ownedMember.filter("Operation").ownedParameter +
> ownedMember.filter("Property")+
> getAssociations().navigableOwnedEnd)[(upper == -1 || upper > 1) &&
> isOrdered] != null){%>
>
> The problem it gaves me is:
>
> "Cannont find operation (+(Collection(Property))) for the type
> Bag(Parameter))
>
> What equivalent to the "+" could I use?
Once again, this is some convoluted code :/. Anyway, the "+" used here
is the "+" between collections. You can use OCL's "union" instead. that
would give something like :
[if
((ownedMember->filter(Operation).ownedParameter.union(ownedMember- > filter(Property)).union(getAssociations.navigableOwnedEnd))- >select((upper
= -1 or upper > 1) and isOrdered)->size() > 0)]
>
> 2-
>
> In an Acceleo 2 script I had:
>
> <%script type="Classifier" name="getTypeList"%>
>
> Which is empty and then:
>
> <%script type="Class" name="getTypeList" post="nMinimize()" %>
> code........
>
> and
>
> <%script type="Interface" name="getTypeList" post="nMinimize()" %>
> code........
>
> In the same template I found:
>
> <%for (getTypeList.nMinimize){%>
> <%-- If import path contains only one segment (no '.' character), we
> don't need to import this element --%>
> <%if (genImportPath.indexOf(".") != -1){%>
> import <%genImportPath%>;
>
>
> I dont know if I am right but I think the empty getTypeList for
> classifier isnt used, instead the getTypeList for classes and the other
> getTypeList for interfaces are used on classifieres which are classes
> and classifiers which are interfaces.
>
> I think this is done automatically, I mean, when it reachs the point:
>
> <%for (getTypeList.nMinimize){%>
>
> If the Classifier is a Class it uses the class one and if it is an
> inteface it uses the interface one.
>
> I dont know if this is right and I would also like to know if Acceleo 3
> works in the same way because I think it is giving me some trouble.
Acceleo 3 checks at runtime the actual type of the arguments before
calling a template; it will then act as did Acceleo 2 and call the good
template if you have the two defined (one on Class and one on Interface).
I believe the empty one (on Classifier) is there to allow the compilation.
>
> Thank you very much again for all the help!!!!
--------------080200060806020605020708
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"
YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------080200060806020605020708--
|
|
|
|
|
Re: [Acceleo] Syntax problems [message #539193 is a reply to message #538963] |
Wed, 09 June 2010 17:51   |
Eclipse User |
|
|
|
Hi and thanks for your help!
I'm still having some trouble:
I did:
Which works fine, except for the last part
union((nestedClassifier->filter(Class).getTypeList())->asBag())/]
It gives this error:
"Cannont find operation union(Bag(String)) for the type Bag(Type)"
The .getTypeList() is a recursive call to the same template, I mean, I have:
[/template]
So this template calls itself on nestedClassifier.
And I think that when executing the getTypeList() template it is returning a String, and so the union() operator cannont be used to concat Types and Strings.
Am I right?
I tried to solve it using: union((ownedOperation.ownedParameter.type)->asBag())->union(general)- >asBag()->union((nestedClassifier->filter(Class).getTypeList().oclAsType(Type))- >asBag())
I mean using oclAsType, but I dont know it that might be correct.
What do you think?
2-
Also I use the getTypeList() on a for loop:
But when I am calling methods which need a "Type" parameter, such as when I do:
It says it is not a valid signature, because it doesnt identify the parameters of the sequence generated by the for loop as types, I tried to solve it also with oclAsType like this:
[if (self.oclAsType(Type).genImportPath().index('.') <> -1)]
Might that be right?
3-
I am trying to use asBag() here:
[if ((ownedMember->filter(Operation).ownedParameter->union((ownedMember- >filter(Property))->asBag())
But it says it cant find the asBag() operation for Collection(Property), so I cant use the union operator again.
How can I solve this too?
Thank you very much and sorry because I know I am bothering you too much, but I am really stuck with this .
Thank you again!
|
|
|
Re: [Acceleo] Syntax problems [message #539257 is a reply to message #539193] |
Thu, 10 June 2010 03:41   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------050004060704010401040907
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Hi Daniel,
Sorry, but you forgot parts of this message and I cannot understand most
of it without these parts. Please find my comments inline for what I
could make out.
Laurent Goubet
Obeo
Daniel wrote:
> Hi and thanks for your help!
>
> I'm still having some trouble:
>
> I did:
>
>
>
> Which works fine, except for the last part
> union((nestedClassifier->filter(Class).getTypeList())->asBag())/]
>
> It gives this error:
>
> "Cannont find operation union(Bag(String)) for the type Bag(Type)"
This can be solved in most cases through
".oclAsType(String)->union". (If you are sure you've got
Strings in the source collection.)
>
> The .getTypeList() is a recursive call to the same template, I mean, I
> have:
>
>
>
> [/template]
>
> So this template calls itself on nestedClassifier.
> And I think that when executing the getTypeList() template it is
> returning a String, and so the union() operator cannont be used to
> concat Types and Strings.
>
> Am I right?
Yup, 'union' needs the two operands to have the same type (or a common
supertype).
>
> I tried to solve it using:
> union((ownedOperation.ownedParameter.type)->asBag())->union(general)-
> >asBag()->union((nestedClassifier->filter(Class).getTypeList().oclAsType(Type))-
> >asBag())
>
> I mean using oclAsType, but I dont know it that might be correct.
>
> What do you think?
It is the way to go if you are sure about the contents of your
collections (lest you get ClassCastExceptions).
>
> 2-
>
> Also I use the getTypeList() on a for loop:
>
>
>
> But when I am calling methods which need a "Type" parameter, such as
> when I do:
>
>
>
> It says it is not a valid signature, because it doesnt identify the
> parameters of the sequence generated by the for loop as types, I tried
> to solve it also with oclAsType like this:
>
> [if (self.oclAsType(Type).genImportPath().index('.') <> -1)]
>
> Might that be right?
I am missing both of your exemples ... but yes, oclAsType is the way to
tell OCL that your objects are of another type. This works the same as
Java casts, and can throw the same exceptions (ClassCastException) if
the cast isn't possible.
>
>
>
>
> 3-
>
>
> I am trying to use asBag() here:
>
> [if ((ownedMember->filter(Operation).ownedParameter->union((ownedMember-
> >filter(Property))->asBag())
> But it says it cant find the asBag() operation for Collection(Property),
> so I cant use the union operator again.
>
> How can I solve this too?
Are you sure you even need the cast to bag here? I'd think your two
collections are of the same type from the start. Otherwise I must admit
I don't understand why you get this error here. Try removing the extra
parenthesis maybe?
>
> Thank you very much and sorry because I know I am bothering you too
> much, but I am really stuck with this :(.
>
> Thank you again!
>
>
>
>
>
>
--------------050004060704010401040907
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"
YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------050004060704010401040907--
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05911 seconds