void (@NotNull List<? extends PackagingElement<?>> elements, @NotNull CompositePackagingElementNode parentNode, @NotNull CompositePackagingElement parentElement, @NotNull ArtifactEditorContext context, @NotNull ComplexElementSubstitutionParameters substitutionParameters, @NotNull Collection<PackagingNodeSource> nodeSources, @NotNull List<PackagingElementNode<?>> nodes, ArtifactType artifactType, Set<? super PackagingElement<?>> processed) { for (PackagingElement<?> element : elements) { final PackagingElementNode<?> prev = findEqual(nodes, element); if (prev != null) { prev.addElement(element, parentElement, nodeSources); continue; } if (element instanceof ArtifactRootElement) { throw new AssertionError("artifact root not expected here"); } else if (element instanceof CompositePackagingElement) { nodes.add(new CompositePackagingElementNode((CompositePackagingElement<?>)element, context, parentNode, parentElement, substitutionParameters, nodeSources, artifactType)); } else if (element instanceof ComplexPackagingElement<?> complexElement) { if (processed.add(element) && substitutionParameters.shouldSubstitute(complexElement)) { final List<? extends PackagingElement<?>> substitution = complexElement.getSubstitution(context, artifactType); if (substitution != null) { final PackagingNodeSource source = new PackagingNodeSource(complexElement, parentNode, parentElement, nodeSources); addNodes(substitution, parentNode, parentElement, context, substitutionParameters, Collections.singletonList(source), nodes, artifactType, processed); continue; } } nodes.add(new ComplexPackagingElementNode(complexElement, context, parentNode, parentElement, substitutionParameters, nodeSources)); } else { nodes.add(new PackagingElementNode<PackagingElement<?>>(element, context, parentNode, parentElement, nodeSources)); } } }