diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings index 8d0eaa94b2b7b5933dd313e7db4cb0b85d399475..b52d2343d9b09a8e7f522a42d0b5af701f155c4b 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings @@ -1,7 +1,7 @@ CompositionUtils.java 34c0a191bd0fb4176c94b4d61abb5c88a679d5e8 GREEN EMFResourceUtils.java 68e6712a52349548bf85346900b17aa65b5f0ea9 GREEN EcoreSerializerBase.java 0a0c2969d793d2e68094c55c8f7b0a662ef6e5d5 GREEN -EcoreUtils.java 18416b5c214410a02eb35596fd807a1cc27d6b35 GREEN +EcoreUtils.java 14f59a93b81dca8d75c192e4bc7c936d4eed799a GREEN ExtensionPointUtils.java 7ce63242b49eb9a7cd4eaadd223f5ebce1dfd75b GREEN HierarchicalNameComparator.java 6face1b673126701a0721af48ead2f9766c17d46 GREEN IdentifierUtils.java fff43dc4e84cdd89c3ece4f5d9d89aec4b0749c2 GREEN diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java index 18416b5c214410a02eb35596fd807a1cc27d6b35..14f59a93b81dca8d75c192e4bc7c936d4eed799a 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java @@ -22,6 +22,8 @@ import static org.eclipse.emf.ecore.util.EcoreUtil.getAllContents; import static org.eclipse.emf.ecore.util.EcoreUtil.getRootContainer; import static org.eclipse.emf.ecore.util.EcoreUtil.replace; import static org.eclipse.emf.ecore.util.EcoreUtil.UsageCrossReferencer.find; +import static org.fortiss.tooling.common.util.LambdaUtils.asStream; +import static org.fortiss.tooling.common.util.LambdaUtils.isAssignableFromAny; import java.util.ArrayList; import java.util.Collection; @@ -268,6 +270,33 @@ public class EcoreUtils { return getChildrenWith(parent, isAssignable); } + /** + * For the given {@code parent}, return the most nested ancestors of the given {@code type} that + * does not have any ancestors of any of the given {@code admissibleSpecializations}. + * + * @param parent + * the parent {@link EObject}. + * @param type + * the type. + * @param admissibleSpecializations + * {@link Collection} of admissible specializations of the given type. + * @return a list of children. + */ + @SuppressWarnings({"rawtypes", "unchecked"}) + public static <T extends EObject> Collection<T> getChildrenWithType(EObject parent, + Class<T> type, Collection<Class<? extends T>> admissibleSpecializations) { + + Predicate<? super EObject> hasApplicableChildren = + modelElement -> asStream(modelElement.eAllContents()) + .anyMatch(c -> isAssignableFromAny((Collection)admissibleSpecializations, + c.getClass())); + + Stream<T> children = asStream(parent.eAllContents()).filter(type::isInstance) + .filter(hasApplicableChildren.negate()).map(type::cast); + + return children.collect(toList()); + } + /** * For a given {@link EObject}, recursively returns the first child that satisfies the given * {@link Predicate}.