List<Configurable> (@NotNull List<? extends ConfigurableEP<Configurable>> extensions, @Nullable ConfigurableFilter filter) { final List<Configurable> result = new ArrayList<>(); final Map<String, HierarchicalConfigurable> idToConfigurable = new HashMap<>(); List<String> idsInEpOrder = new ArrayList<>(); for (ConfigurableEP<Configurable> ep : extensions) { Configurable configurable = ConfigurableWrapper.wrapConfigurable(ep); if (filter != null && !filter.isIncluded(configurable)) { continue; } if (configurable instanceof HierarchicalConfigurable wrapper) { idToConfigurable.put(wrapper.getId(), wrapper); idsInEpOrder.add(wrapper.getId()); } else { //dumpConfigurable(configurablesExtensionPoint, ep, configurable); if (configurable != null) { result.add(configurable); } } } Set<String> visited = new HashSet<>(); Map<String, List<String>> idTree = buildIdTree(idToConfigurable, idsInEpOrder); // modify configurables (append children) // Before adding a child to a parent, all children of the child should be already added to the child, // because ConfigurableWrapper#addChild may return a new instance. for (final String id : idsInEpOrder) { addChildrenRec(id, idToConfigurable, visited, idTree); } // add roots only (i.e. configurables without parents) for (String id : idsInEpOrder) { HierarchicalConfigurable wrapper = idToConfigurable.get(id); String parentId = wrapper.getParentId(); if (parentId == null || !idToConfigurable.containsKey(parentId)) { result.add(wrapper); } } return result; }