Source:
<code>public void run(IMarker marker) { ResourceSet resourceSet = new ResourceSetImpl(); List<Connection> toDelete = new ArrayList<>(); EObject artifactToDelete = null; TracePersistenceAdapter tracePersistenceAdapter = ExtensionPointHelper.getTracePersistenceAdapter().get(); EObject traceModel = tracePersistenceAdapter.getTraceModel(resourceSet); TraceHelper traceHelper = new TraceHelper(traceModel); TraceMetaModelAdapter traceMetamodelAdapter = ExtensionPointHelper.getTraceMetamodelAdapter().get(); EObject artifactModel = tracePersistenceAdapter.getArtifactWrappers(new ResourceSetImpl()); List<EObject> artifacts = artifactAdapter.getAllArtifacts(artifactModel); String artifactContainerFileName = artifactModel.eResource().getURI().lastSegment(); String markerContainerFileName = new File(marker.getResource().toString()).getName(); String markerUri = marker.getAttribute(CapraNotificationHelper.OLD_URI, null); if (markerContainerFileName.equals(artifactContainerFileName)) { for (EObject aw : artifacts) { if (artifactAdapter.getArtifactUri(aw).equals(markerUri)) { toDelete = traceMetamodelAdapter.getConnectedElements(aw, traceModel); <START> artifactToDelete = aw; <END> } } traceMetamodelAdapter.deleteTrace(toDelete, traceModel); EcoreUtil.delete(artifactToDelete); tracePersistenceAdapter.saveTracesAndArtifacts(traceModel, artifactModel); try { marker.delete(); MessageDialog.openWarning(null, "TraceLinkDeleted", "Links successfully deleted"); } catch (CoreException e) { e.printStackTrace(); } } else { URI deletedEObjectUri = URI.createURI(markerUri); for (Connection c : traceMetamodelAdapter.getAllTraceLinks(traceModel)) { for (EObject item : traceHelper.getTracedElements(c)) { URI itemUri = CapraNotificationHelper.getFileUri(item); if (deletedEObjectUri.equals(itemUri)) { toDelete.add(c); break; } } } traceMetamodelAdapter.deleteTrace(toDelete, traceModel); try { marker.delete(); } catch (CoreException e) { e.printStackTrace(); } } }</code><technical_language>If artifact delete here, break out of loop soon artifact for. Otherwise, artifactToDelete a list</technical_language>

Target:
public void run(IMarker marker) { ResourceSet resourceSet = new ResourceSetImpl(); List<Connection> toDelete = new ArrayList<>(); EObject artifactToDelete = null; TracePersistenceAdapter tracePersistenceAdapter = ExtensionPointHelper.getTracePersistenceAdapter().get(); EObject traceModel = tracePersistenceAdapter.getTraceModel(resourceSet); TraceHelper traceHelper = new TraceHelper(traceModel); TraceMetaModelAdapter traceMetamodelAdapter = ExtensionPointHelper.getTraceMetamodelAdapter().get(); EObject artifactModel = tracePersistenceAdapter.getArtifactWrappers(new ResourceSetImpl()); List<EObject> artifacts = artifactAdapter.getAllArtifacts(artifactModel); String artifactContainerFileName = artifactModel.eResource().getURI().lastSegment(); String markerContainerFileName = new File(marker.getResource().toString()).getName(); String markerUri = marker.getAttribute(CapraNotificationHelper.OLD_URI, null); if (markerContainerFileName.equals(artifactContainerFileName)) { for (EObject aw : artifacts) { if (artifactAdapter.getArtifactUri(aw).equals(markerUri)) { toDelete = traceMetamodelAdapter.getConnectedElements(aw, traceModel); artifactToDelete = aw; break; } } traceMetamodelAdapter.deleteTrace(toDelete, traceModel); EcoreUtil.delete(artifactToDelete); tracePersistenceAdapter.saveTracesAndArtifacts(traceModel, artifactModel); try { marker.delete(); MessageDialog.openWarning(null, "TraceLinkDeleted", "Links successfully deleted"); } catch (CoreException e) { e.printStackTrace(); } } else { URI deletedEObjectUri = URI.createURI(markerUri); for (Connection c : traceMetamodelAdapter.getAllTraceLinks(traceModel)) { for (EObject item : traceHelper.getTracedElements(c)) { URI itemUri = CapraNotificationHelper.getFileUri(item); if (deletedEObjectUri.equals(itemUri)) { toDelete.add(c); break; } } } traceMetamodelAdapter.deleteTrace(toDelete, traceModel); try { marker.delete(); } catch (CoreException e) { e.printStackTrace(); } } }