|
|
Re: [Acceleo] Syntax problems [message #538298 is a reply to message #538273] |
Mon, 07 June 2010 08:31 |
|
This is a multi-part message in MIME format.
--------------080006060802090708070001
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Hi Daniel,
<%if (current[!filter("Behavior")] != null &&
!owner.eClass.name.equalsIgnoreCase("Class")){%>
seems really convoluted to me ... I don't really even know how
"[!filter(...)]" would behave. Anyway, "equalsIgnoreCase" and "filter"
have been ported in Acceleo 3 but we didn't make it soon enough to
change the automatic migration. If I understand correctly the meaning of
"current[!filter("Behavior")]", you should be able to use :
[if (not (self.oclIsKindOf(Behavior)) and not
(owner.eClass.name.equalsIgnoreCase("Class"))]
for the same result.
Laurent Goubet
Obeo
Sebastien Roy wrote:
> I think you should replace
>
> self->select(...) <> null
>
> with
>
> not(self->select(...))->isEmpty())
>
> Regards
>
> Sebastien
--------------080006060802090708070001
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=
--------------080006060802090708070001--
|
|
|
|
Re: [Acceleo] Syntax problems [message #538783 is a reply to message #538752] |
Tue, 08 June 2010 15:42 |
|
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 #538963 is a reply to message #538859] |
Wed, 09 June 2010 07:48 |
|
This is a multi-part message in MIME format.
--------------060600090309090602070304
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Daniel,
Sorry my bad, it is indeed "->union()" and not ".union()"... yet your
comment reminds me that OCL is far from good when manipulating collections.
the "union" operator is only defined as such :
Bag::union(Bag)
Bag::union(Set)
Set::union(Bag)
Set::union(Set)
OrderedSet::union(Bag)
OrderedSet::union(Set)
Don't ask me why these last two ...
You'll have to cast your collections to either Bag (non unique, non
ordered) or Set (unique, non ordered) before being able to concatenate
two of them. There is no way of adding to a Sequence another Sequence.
You can cast collections with "->asSet()", "->asBag()", "->asOrderedSet"
and "->asSequence()". Take note that if you cast a Sequence as a Set,
all duplicates will be removed.
Laurent Goubet
Obeo
Daniel wrote:
> Hi again!
>
> I have been trying the union operator but it doesnt work, if I use:
>
> [if
> ((ownedMember->filter(Operation).ownedParameter.union(ownedMember- >
> filter(Property)).union(getAssociations.navigableOwnedEnd))- >select((upper
> = -1 or upper > 1) and isOrdered)->size() > 0)]
>
> It gives me an error:
>
> "Cannot find the operation union(Collection(Property)) for the type
> Parameter"
>
> I also tried with ->union() and it didnt work
>
> How can I fix it? Should I do some kind of upcasting?
>
> Thanks
>
--------------060600090309090602070304
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=
--------------060600090309090602070304--
|
|
|
Re: [Acceleo] Syntax problems [message #539193 is a reply to message #538963] |
Wed, 09 June 2010 21:51 |
Daniel Messages: 44 Registered: June 2010 |
Member |
|
|
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 07:41 |
|
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--
|
|
|
|
Re: [Acceleo] Syntax problems [message #539535 is a reply to message #539475] |
Fri, 11 June 2010 08:25 |
|
This is a multi-part message in MIME format.
--------------050809080802010103010101
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Hi Daniel,
Casting Property to Parameter seems like it will fail in
ClassCastException. I would have done something like :
ownedMember->filter(Operation).ownedParameter.oclAsType(TypedElement)- >union(ownedMember-
>filter(Property))
and add the cast from Property to TypedElement if OCL still failed
compiling. Otherwise, what you have seems good to me.
Laurent Goubet
Obeo
Daniel wrote:
> Hi and thanks again for your help.
>
> I will try the use the oclAsType for the castings, later I will see if I
> get or I dont get exceptions.
>
> The only thing left to try to execute my module is the point 3 of the
> other post. I am going to try to explain the problem and what I have tried:
>
> This is from Acceleo 2:
>
> <%if ((ownedMember.filter("Operation").ownedParameter +
> ownedMember.filter("Property")+
> getAssociations().navigableOwnedEnd)[(upper == -1 || upper > 1) &&
> isOrdered] != null){%>
>
> This is from mt2mtl:
>
> [if ((ownedMember->filter(Operation).ownedParameter +
> ownedMember->filter(Property) +
> getAssociations.navigableOwnedEnd)->select((upper = -1 or upper > 1) and
> isOrdered) <> null)]
>
> In the first 'x' it says:
>
> "Cannot find the operation +Collection(Property) for the type
> Bag(Parameter)"
>
> I understand that ownedMember->filter(Operation).ownedParameter is
> being taken as a Bag(Parameter) and ownedMember.filter("Property") as a
> Collection(Property)
>
> So I tried with union (and without the double () )
>
> [if ((ownedMember->filter(Operation).ownedParameter->union(ownedMember-
> >filter(Property)) .......
>
> It says:
>
> "Cannont find the operation union(Collection(Property)) for the type
> BagParameter()"
>
> So i tried to convert the last part to a bag parameter with:
>
> ..->union(ownedMember->filter(Property)->asBag())....
> but then it says:
>
> "Cannot find operation asBag() for the type Collection(Property)"
>
> I dont know, it seems like it is taking one part of the union as a thing
> and the other as another that cant cast to a bagParameter
>
> So in the end I used again a casting:
>
> [if ((ownedMember->filter(Operation).ownedParameter->union(ownedMember-
> >filter(Property).oclAsType(Parameter))
>
> And it gaves no error but I dont know what am I really doing.
>
> The final result is:
>
> [if
> ((ownedMember->filter(Operation).ownedParameter->union((getAssociations().navigableOwnedEnd)-
> >select((upper = -1 or upper > 1) and
> isOrdered).oclAsType(Parameter))->union(ownedMember->filter(Property).oclAsType(Parameter)))
> <> null)]
>
> Does it have any sense?
> Thank you.
>
>
--------------050809080802010103010101
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=
--------------050809080802010103010101--
|
|
|
|
Re: [Acceleo] Syntax problems [message #539730 is a reply to message #539614] |
Sat, 12 June 2010 09:30 |
|
This is a multi-part message in MIME format.
--------------090806070605010903080209
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Hi Daniel,
My comment was for the second cast :
[if
((ownedMember->filter(Operation).ownedParameter.oclAsType(TypedElement)-
>union(ownedMember->filter(Property).oclAsType(TypedElement))
Regards,
Laurent Goubet
Obeo
Daniel wrote:
> Hi again and thanks for your advice.
>
> I have tried what you said:
>
> [if
> ((ownedMember->filter(Operation).ownedParameter.oclAsType(TypedElement)-
> >union(ownedMember->filter(Property))
>
> But it still doesnt compile:
>
> "Cannont find operation union(Collection(Property)) for the type
> Bag(TypedElement"
>
> You also said:
>
> "and add the cast from Property to TypedElement if OCL still failed
> compiling. Otherwise, what you have seems good to me."
>
> How do i add the cast?
>
> Thank you!
>
>
--------------090806070605010903080209
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=
--------------090806070605010903080209--
|
|
|
|
|
Re: [Acceleo] Syntax problems [message #540328 is a reply to message #539813] |
Tue, 15 June 2010 15:47 |
|
This is a multi-part message in MIME format.
--------------040805050205090703030201
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Daniel,
As far as I know, UML Properties are not Parameters, thus you risk a
ClassCast exception when throwing the result of your unions to Parameter.
IIUC, what you seek to do on the elements of the resulting collection is
only to access "upper", "lower" and "isOrdered" ... which are all
defined on "MultiplicityElement". The easiest way to solve these
compilation issues is then to directly cast to this type :
[if((ownedMember-> filter(Operation).ownedParameter.oclAsType(MultiplicityEleme nt)- >union(ownedMember->filter(Property).oclAsType(MultiplicityElement))- >
union(getAssociations().navigableOwnedEnd))->select((upper = -1 or upper
> 1) and isOrdered) <> null)]
Laurent Goubet
Obeo
Daniel wrote:
> I solved it like this:
>
> [if((ownedMember->filter(Operation).ownedParameter.oclAsType(TypedElement)-
> >union(ownedMember->filter(Property).oclAsType(TypedElement))- >
> union(getAssociations().navigableOwnedEnd)).oclAsType(Parame ter)-
> >select((upper = -1 or upper > 1) and isOrdered) <> null)]
>
> Casting to Parameter, is it all right?
--------------040805050205090703030201
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=
--------------040805050205090703030201--
|
|
|
|
Powered by
FUDForum. Page generated in 0.04768 seconds