Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gendoc » detecting empty collection
detecting empty collection [message #1766706] Mon, 26 June 2017 11:56 Go to next message
samuel kallmeyer is currently offline samuel kallmeyerFriend
Messages: 41
Registered: March 2017
Member
Hi,
I'm looping through requirements properties to detect which are traced, satisfied,...
I'm able to retrieve the associated collection, but I'm not able to detect when it is empty with the following code:
[for (r:uml::Class| p.ownedElement->select(not getAppliedStereotype('SysML::Requirements::Requirement').oclIsUndefined())->sortedBy(name))]<drop/>
[if (r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'),'tracedTo')->notEmpty())] <drop/>
[for (e:Element | r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'),'tracedTo'))] <drop/>
// DO TBD
[/for] <drop/>
[else] <drop/>
// DO in case nothing is traced
[/if] <drop/>
[/for] <drop/>

The (r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'),'tracedTo') should return a collection, or am I wrong ?

Samuel

Re: detecting empty collection [message #1766707 is a reply to message #1766706] Mon, 26 June 2017 12:09 Go to previous messageGo to next message
Yves BERNARD is currently offline Yves BERNARDFriend
Messages: 73
Registered: July 2014
Member
I remember having faced a similar issue in the past.

Try something like that:
r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo').oclAsType(ecore::EObject)->asSet()

Cheers,

Yves


Yves

[Updated on: Mon, 26 June 2017 12:10]

Report message to a moderator

Re: detecting empty collection [message #1766715 is a reply to message #1766707] Mon, 26 June 2017 13:15 Go to previous messageGo to next message
samuel kallmeyer is currently offline samuel kallmeyerFriend
Messages: 41
Registered: March 2017
Member
Hello Yves,
I started to write my code from your old post before asking on the list...
your current reply unfortunately doesn't help.
Regards,

Samuel
Re: detecting empty collection [message #1766716 is a reply to message #1766715] Mon, 26 June 2017 13:22 Go to previous messageGo to next message
Tristan Faure is currently offline Tristan FaureFriend
Messages: 426
Registered: July 2009
Senior Member
What kind of errors do you get ?



Re: detecting empty collection [message #1766719 is a reply to message #1766716] Mon, 26 June 2017 13:36 Go to previous messageGo to next message
samuel kallmeyer is currently offline samuel kallmeyerFriend
Messages: 41
Registered: March 2017
Member
See details.
The execution of a script failed: Error during generation of Gendoc script :Invalid Expression Type: Set(EObject) should be Boolean

if I'm adding the isEmpty() to check the Set:
[if (r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo').oclAsType(ecore::EObject)->asSet()->isEmpty())] <drop/>

I have nothing more as output, neither when I have a traced requirement or not.
Starts to become complicated to mix between Profiles, SysML, UML, ocl, ... :-)

Samuel

Re: detecting empty collection [message #1766720 is a reply to message #1766719] Mon, 26 June 2017 13:38 Go to previous messageGo to next message
Tristan Faure is currently offline Tristan FaureFriend
Messages: 426
Registered: July 2009
Senior Member
and what is the output without the "if"?



Re: detecting empty collection [message #1766722 is a reply to message #1766720] Mon, 26 June 2017 13:47 Go to previous messageGo to next message
samuel kallmeyer is currently offline samuel kallmeyerFriend
Messages: 41
Registered: March 2017
Member
returns invalid
Re: detecting empty collection [message #1766727 is a reply to message #1766722] Mon, 26 June 2017 14:10 Go to previous messageGo to next message
Tristan Faure is currently offline Tristan FaureFriend
Messages: 426
Registered: July 2009
Senior Member
Does it work for other properties like '"id" for instance ?



Re: detecting empty collection [message #1766731 is a reply to message #1766727] Mon, 26 June 2017 14:44 Go to previous messageGo to next message
samuel kallmeyer is currently offline samuel kallmeyerFriend
Messages: 41
Registered: March 2017
Member
[r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'id')/] -> works
[r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo').oclAsType(ecore::EObject)/] -> invalid
[r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo').oclAsType(ecore::EObject)->asSet()/] -> invalid
[r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo').oclAsType(ecore::EObject)->asSet()->isEmpty()/] -> invalid

does oclAsType(ecore::EObject) is the right way to retrieve the ElementName collection part of the Requirement ?
Re: detecting empty collection [message #1766732 is a reply to message #1766731] Mon, 26 June 2017 14:47 Go to previous messageGo to next message
Tristan Faure is currently offline Tristan FaureFriend
Messages: 426
Registered: July 2009
Senior Member
and [r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo')/] ?

you can also try :
[Sequence(r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo'))->flatten().oclAsType(ecore::EObject)->asSet()/]




Re: detecting empty collection [message #1766733 is a reply to message #1766732] Mon, 26 June 2017 15:01 Go to previous messageGo to next message
samuel kallmeyer is currently offline samuel kallmeyerFriend
Messages: 41
Registered: March 2017
Member
[r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo')/] is able to generate my doc file, but I'm not able to open it due to a generated error in the document.
I'm still trying the sequence as it seems the syntax is wrong -> Sequence {} ...
Re: detecting empty collection [message #1766734 is a reply to message #1766733] Mon, 26 June 2017 15:03 Go to previous messageGo to next message
Tristan Faure is currently offline Tristan FaureFriend
Messages: 426
Registered: July 2009
Senior Member
try [r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo').toString().clean()/]



Re: detecting empty collection [message #1766735 is a reply to message #1766734] Mon, 26 June 2017 15:10 Go to previous messageGo to next message
samuel kallmeyer is currently offline samuel kallmeyerFriend
Messages: 41
Registered: March 2017
Member
org.eclipse.uml2.uml.internal.impl.ClassImpl@34b5b73e (name: Requirement2, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false) When something is found
Empty when no tracedTo available
Re: detecting empty collection [message #1766739 is a reply to message #1766735] Mon, 26 June 2017 15:37 Go to previous messageGo to next message
Tristan Faure is currently offline Tristan FaureFriend
Messages: 426
Registered: July 2009
Senior Member
ok and with [r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo').oclAsType(uml::NamedElement)->asSet()/]

(to display : [r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo').oclAsType(uml::NamedElement)->asSet().toString().clean()/]
?




Re: detecting empty collection [message #1766741 is a reply to message #1766739] Mon, 26 June 2017 15:48 Go to previous messageGo to next message
samuel kallmeyer is currently offline samuel kallmeyerFriend
Messages: 41
Registered: March 2017
Member
invalid in both cases
Re: detecting empty collection [message #1766742 is a reply to message #1766741] Mon, 26 June 2017 15:56 Go to previous messageGo to next message
Tristan Faure is currently offline Tristan FaureFriend
Messages: 426
Registered: July 2009
Senior Member
Ok so it is because of one element, try :
[Sequence(r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo'))->flatten().oclAsType(uml::NamedElement)->asSet()/]




[Updated on: Mon, 26 June 2017 15:57]

Report message to a moderator

Re: detecting empty collection [message #1766743 is a reply to message #1766742] Mon, 26 June 2017 15:59 Go to previous messageGo to next message
samuel kallmeyer is currently offline samuel kallmeyerFriend
Messages: 41
Registered: March 2017
Member
We will catch it...

See details.
The execution of a script failed: Error during generation of Gendoc script :1:1:1:8 "{" expected after "Sequence"
Re: detecting empty collection [message #1766764 is a reply to message #1766743] Tue, 27 June 2017 06:31 Go to previous messageGo to next message
Tristan Faure is currently offline Tristan FaureFriend
Messages: 426
Registered: July 2009
Senior Member
I always forget the syntax : [Sequence{r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo')}->flatten().oclAsType(uml::NamedElement)->asSet()/]



Re: detecting empty collection [message #1766765 is a reply to message #1766764] Tue, 27 June 2017 06:36 Go to previous messageGo to next message
samuel kallmeyer is currently offline samuel kallmeyerFriend
Messages: 41
Registered: March 2017
Member
tx, it generates the doc file : I'm unfortunately not able to open it due to errors inside, likem the previous test: [r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo')/]
Re: detecting empty collection [message #1766766 is a reply to message #1766765] Tue, 27 June 2017 06:39 Go to previous messageGo to next message
Tristan Faure is currently offline Tristan FaureFriend
Messages: 426
Registered: July 2009
Senior Member
Yes because you need to use this expression in your test to display a result :
[r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo').toString().clean()/]

This syntax could afraid a little bit, but when you are trained or used to, these errors are less frequent




Re: detecting empty collection [message #1766768 is a reply to message #1766766] Tue, 27 June 2017 06:49 Go to previous messageGo to next message
samuel kallmeyer is currently offline samuel kallmeyerFriend
Messages: 41
Registered: March 2017
Member
Ok, I'm used to work with |= << 0xdeadbeef ...
I'm in this case now:
[Sequence{r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'), 'tracedTo').toString().clean()}->flatten().oclAsType(uml::NamedElement)->asSet()/] returns invalid in both cases
Re: detecting empty collection [message #1766881 is a reply to message #1766768] Wed, 28 June 2017 13:45 Go to previous messageGo to next message
BACH TOBJI Mohamed Ali is currently offline BACH TOBJI Mohamed AliFriend
Messages: 3
Registered: May 2017
Junior Member
Hi Samuel,

Could you please verify if it works with the following code (it's the same code as in your first comment but with a little modification in the If condition) :

[for (r:uml::Class| p.ownedElement->select(not getAppliedStereotype('SysML::Requirements::Requirement').oclIsUndefined())->sortedBy(name))]<drop/>

[if (r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'),'tracedTo')->flatten()->notEmpty())] <drop/>

[for (e:Element | r.getValue(getAppliedStereotype('SysML::Requirements::Requirement'),'tracedTo'))] <drop/>
// DO TBD
[/for] <drop/>

[else] <drop/>
// DO in case nothing is traced
[/if] <drop/>
[/for] <drop/>

Best Regards,

Mohamed Ali
Re: detecting empty collection [message #1766960 is a reply to message #1766881] Thu, 29 June 2017 06:38 Go to previous message
samuel kallmeyer is currently offline samuel kallmeyerFriend
Messages: 41
Registered: March 2017
Member
Hi Mohamed Ali,
Your solution is fine: flatten() was missing.
Thanks a lot,

Samuel
Previous Topic:GenDoc on Eclipse Neon.3
Next Topic:Keeping package hierarchy in the documentation
Goto Forum:
  


Current Time: Wed Nov 14 01:20:58 GMT 2018

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

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

Back to the top