How can I return a list based on a condition on the referencing elements of the list

151 Views Asked by At

I want to return a list of elements of 'ListOfObjects' that are being referenced by 'SomeOtherObject' with it's(SomeOtherObject's) attribute satisfying the condition. I'm trying this code:

ParentObj.ListOfObjects.select(e|e.referencingContainers.typeSelect(SomOtherObject).attr.isValid());

'ListOfObjects' extracts a list of particular objects from the 'ParentObj'.But the above code gives me nothing. Please help me out in figuring out what's wrong here.

2

There are 2 best solutions below

1
On BEST ANSWER

It's because, in the above piece of code, the result of the expression inside the select returns a list and not an a boolean. To make it boolean I'd have to rewrite the code this way:

ParentObj.ListOfObjects.select(e|e.referencingContainers.typeSelect(SomOtherObject).select(el|el.attr.isValid()).size > 0);

The select inside the select along with the check for size is what made the difference there.

0
On

There is an extension to find objects that reference a specific object: org::eclipse::xtend::util::stdlib::crossref

You can also specify conditions in the same way. Here is more information about Cross References Extensions.