Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » correct downcast from Element to other UML types
correct downcast from Element to other UML types [message #1848202] Wed, 24 November 2021 20:57 Go to next message
Ilja Kraval is currently offline Ilja KravalFriend
Messages: 43
Registered: October 2021
Member
Hi all,
I'm a beginner in Acceleo and I can't find a solution for one template:
I have an "anIssue" UML element of type "InstanceSpecification". From it, several "Dependencies" lead to various elements of different types (Class, Property, UseCase, etc.). I need to list their properties, ie perform a treated downcast.
I downcast to subtypes via oclAsType (). It works for me, but I don't know how to handle the correctness of the downcast before it is called and thus avoid "invalid".
I enclose a statement cycle for Dependency with a note where treatment is missing:
-------------------------------------

[for (dep: uml :: Dependency | anIssue.getClientDependencies ())]
[dep.name /]
[comment Missing correctness handling like "If anIssue.Type is Class" /]
Class:
JAVA name = [dep.target.oclAsType (Class) .name /],
ANALYSIS name = [dep.target.oclAsType (Class) .getLabel () /]
[dep.ownedComment._body /]

[comment Next block for "if anIssue.Type is Property" etc. /]
[/ for]

-----------------------------------

Thanks for concrete advice

Ilya
Re: correct downcast from Element to other UML types [message #1848203 is a reply to message #1848202] Wed, 24 November 2021 21:11 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7680
Registered: July 2009
Senior Member
oclIsKindOf() (NB not oclIsTypeOf()).
Re: correct downcast from Element to other UML types [message #1848204 is a reply to message #1848203] Wed, 24 November 2021 21:42 Go to previous messageGo to next message
Ilja Kraval is currently offline Ilja KravalFriend
Messages: 43
Registered: October 2021
Member
Hi Ed,
thanks a lot, I have tried that before.

Although the return type of OclIsKindOf() is according to Acceleo / OCL documentation Boolean:

https://wiki.eclipse.org/Acceleo/OCL_Operations_Reference#oclIsKindOf.28_Classifier_typespec_.29_:_Boolean

so this line (according to previous code with loop)

[ if (dep.target.oclIsKindOf (Class)) ]

reports an error:

"Invalid Expression Type: Bag (Boolean) should be Boolean"

I don't understand why this is so?

Regards,

Ilya
Re: correct downcast from Element to other UML types [message #1848209 is a reply to message #1848204] Thu, 25 November 2021 06:02 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7680
Registered: July 2009
Senior Member
Hi

You provide barely 10% of a repro so I can only guess that at least one of dep or target involve a collection causing a Bag to be used where you and Acceleo expected a Boolean. (OCL's implicit collect can be nice and readable when correctly used, but distinctly confusing when unwanted.)

If you paste you code so that you can use the Complete OCL or OCLinEcore editor or Xtext OCL Console you can use hovertext to determine the type of each term and operator in an expression. This may help you understand it.

Regards

Ed Willink
Re: correct downcast from Element to other UML types [message #1848235 is a reply to message #1848209] Thu, 25 November 2021 17:54 Go to previous messageGo to next message
Ilja Kraval is currently offline Ilja KravalFriend
Messages: 43
Registered: October 2021
Member
Hi Ed,

your advice to run editor and test the code was very good!

I did a very simple example: I have one InstanceSpecification1 with two Dependency Dep1 and Dep2, one leading to Class Class1 and the other to Activity Activity1. This can be seen in the pictures in the diagram.

Figure Pic1 shows a list of end properties to the output, including a oclIsKindOf (Activity). Everything looks as expected: One Dependency dep (= iteration parameter) has one supplier and one Boolean output true / false.

However, when I put this Boolean expression to the if condition, see Figure Pic2, Acceleo reports an error. And that's strange.

Is there an explanation for this or is it a bug?

Regards
Ilya
  • Attachment: Pic2.png
    (Size: 49.37KB, Downloaded 179 times)
  • Attachment: Pic1.png
    (Size: 52.06KB, Downloaded 153 times)
Re: correct downcast from Element to other UML types [message #1848239 is a reply to message #1848235] Thu, 25 November 2021 19:16 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7680
Registered: July 2009
Senior Member
Hi

Once again you provide only 10% of a repro. I suggest you read https://wiki.eclipse.org/OCL/ForumNetiquette to see how to ask questions that provoke answers rather than mutual irritation.

Regards

Ed Willink
Previous Topic:working with imported models
Next Topic:problem with oclIsKindOf()
Goto Forum:
  


Current Time: Thu Dec 12 08:05:50 GMT 2024

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

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

Back to the top