From 90b44b2d1031812fe4bb0f2f7f8c7315ddee4c31 Mon Sep 17 00:00:00 2001 From: Tobias Ortmayr Date: Fri, 13 Oct 2023 11:07:44 +0200 Subject: [PATCH] Bugfixes for 2.0 Fix GModelDeleteOperationHandler by updating the collectDependents method. - Dont add child elements of elements that should be deleted to the dependent set. They will be deleted indirectly anyways because the parent container is deleted. - Correctly add incoming/outgoing edges to the dependet set instead of their targets/sources --- .../gmodel/GModelDeleteOperationHandler.java | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelDeleteOperationHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelDeleteOperationHandler.java index a270d484..1bb93144 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelDeleteOperationHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelDeleteOperationHandler.java @@ -73,23 +73,24 @@ protected boolean delete(final String elementId, final GModelIndex index) { return false; } - // Always delete the top-level node - GModelElement nodeToDelete = findTopLevelElement(element.get()); - if (nodeToDelete.getParent() == null) { + // Always delete the top-level element + GModelElement elementToDelete = findTopLevelElement(element.get()); + if (elementToDelete.getParent() == null) { LOGGER.warn("The requested node doesn't have a parent; it can't be deleted"); return false; // Can't delete the root, or an element that doesn't belong to the model } Set dependents = new LinkedHashSet<>(); - collectDependents(dependents, nodeToDelete, modelState); + collectDependents(dependents, elementToDelete, modelState, false); - dependents.forEach(EcoreUtil::delete); allDependantsIds.addAll(dependents.stream().map(GModelElement::getId).collect(Collectors.toSet())); + dependents.forEach(EcoreUtil::delete); return true; } protected void collectDependents(final Set dependents, final GModelElement nodeToDelete, - final GModelState modelState) { + final GModelState modelState, final boolean isChild) { + if (dependents.contains(nodeToDelete)) { return; } @@ -97,25 +98,21 @@ protected void collectDependents(final Set dependents, final GMod // First, children if (nodeToDelete.getChildren() != null) { for (GModelElement child : nodeToDelete.getChildren()) { - collectDependents(dependents, child, modelState); + collectDependents(dependents, child, modelState, true); } } // Then, incoming/outgoing edges for nodes if (nodeToDelete instanceof GNode) { GModelIndex index = modelState.getIndex(); - - // Then, incoming/outgoing links - for (GModelElement incoming : index.getIncomingEdges(nodeToDelete)) { - collectDependents(dependents, incoming, modelState); - } - for (GModelElement outgoing : index.getOutgoingEdges(nodeToDelete)) { - collectDependents(dependents, outgoing, modelState); - } + dependents.addAll(index.getIncomingEdges(nodeToDelete)); + dependents.addAll(index.getOutgoingEdges(nodeToDelete)); } // Finally, the node to delete - dependents.add(nodeToDelete); + if (!isChild) { + dependents.add(nodeToDelete); + } } protected GModelElement findTopLevelElement(final GModelElement element) {