/** * @since 2.6 */ public static TreeIterator<EObject> getAllNonDerivedContents(EObject root, boolean includeRoot) { /* * We cannot simply use root.eAllContents here since the iterator * will probe for #hasNext on each invocation of #next. This is usually * not a problem but with derived containment, it becomes an issue. * For example, the accessor of XAbstractFeatureCall#getImplicitReceiver uses #getFeature * to initialize itself. This will cause the potential proxy feature * to be resolved which in turn tries to access the mapped proxy URI fragments * in the resource. Now these fragments are currently in the process of being * updated, e.g. there may not even be enough entries. Thus #getFeature * shall not be called here. Long story short, this iterator filters * derived containment features. */ return new AbstractTreeIterator<EObject>(root, includeRoot) { private static final long serialVersionUID = 1L; @Override public Iterator<EObject> getChildren(Object object) { EObject eObject = (EObject) object; return getNonDerivedContents(eObject); } }; }
/** * Returns all content filtered by given predicate. Children of filtered elements are omitted as well. Filtered * means that the element does not satisfy the predicate. The given object itself is neither added to the result nor * is it tested against the predicate. * * @param eobj * the root object, may be null * @return the tree iterator, may be an empty iterator but never null */ public static TreeIterator<EObject> getAllContentsFiltered(EObject eobj, final Predicate<EObject> predicate) { if (eobj == null) { return emptyTreeIterator(); } return new AbstractTreeIterator<EObject>(eobj, false) { private static final long serialVersionUID = 1L; @Override public Iterator<EObject> getChildren(Object element) { return Iterators.filter(((EObject) element).eContents().iterator(), predicate); } }; }
/** * Returns all content of a given type, ignoring all elements which are not of the given type. This filters out also * elements of the given type, if their container has a different type. The given object itself is neither added to * the result nor is it tested against the predicate. * * @param eobj * the root object, may be null * @return the tree iterator, may be an empty iterator but never null */ @SuppressWarnings("unchecked") public static <T> TreeIterator<T> getAllDirectlyFoundContentsOfType(EObject eobj, final Class<T> type) { if (eobj == null) { return emptyTreeIterator(); } return (TreeIterator<T>) new AbstractTreeIterator<EObject>(eobj, false) { private static final long serialVersionUID = 1L; @Override public Iterator<? extends EObject> getChildren(Object element) { return (Iterator<? extends EObject>) Iterators.filter(((EObject) element).eContents().iterator(), type); } }; }
/** * @since 2.7 */ @SuppressWarnings("serial") protected TreeIterator<EObject> getAllLinkableContents(EObject model) { return new AbstractTreeIterator<EObject>(model) { @Override public Iterator<EObject> getChildren(Object object) { return ((EObject) object).eContents().iterator(); } }; }
public TreeIterator<EObject> getAllContents() { return new AbstractTreeIterator<EObject>(this, false) { private static final long serialVersionUID = 1L; @Override public Iterator<EObject> getChildren(Object object) { return object == ResourceImpl.this ? ResourceImpl.this.getContents().iterator() : ((EObject)object).eContents().iterator(); } }; }
public TreeIterator<EObject> eAllContents() { return new AbstractTreeIterator<EObject>(this, false) { private static final long serialVersionUID = 1L; @Override public Iterator<EObject> getChildren(Object object) { return ((EObject)object).eContents().iterator(); } }; }
public static TreeIterator<EObject> getAllNonFragmentingContentsIterator(EObject eObject) { return new AbstractTreeIterator<EObject>(eObject) { private static final long serialVersionUID = 1L; @Override protected Iterator<? extends EObject> getChildren(Object o) { return prepareChildrenList((EObject)o).iterator(); } }; }
public static TreeIterator<EObject> getAllNonFragmentingContentsIterator(List<EObject> contents) { return new AbstractTreeIterator<EObject>(contents, false) { private static final long serialVersionUID = 1L; @SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected Iterator<? extends EObject> getChildren(Object o) { if (o instanceof List) { return ((List)o).iterator(); } else { return prepareChildrenList((EObject)o).iterator(); } } }; }