From 636358ea9bdc5a81686bc451c8b53884883a87ae Mon Sep 17 00:00:00 2001 From: Lars Fritsche Date: Tue, 11 Apr 2023 16:35:10 +0200 Subject: [PATCH 01/13] MoflonEmfBuilder no longer throws exceptions when there is no model folder --- .../src/org/moflon/emf/build/MoflonEmfBuilder.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/org.moflon.emf.build/src/org/moflon/emf/build/MoflonEmfBuilder.java b/org.moflon.emf.build/src/org/moflon/emf/build/MoflonEmfBuilder.java index 877b0af3..3b91851c 100644 --- a/org.moflon.emf.build/src/org/moflon/emf/build/MoflonEmfBuilder.java +++ b/org.moflon.emf.build/src/org/moflon/emf/build/MoflonEmfBuilder.java @@ -1,5 +1,6 @@ package org.moflon.emf.build; +import java.io.File; import java.util.Arrays; import java.util.Collection; import java.util.Map; @@ -44,6 +45,9 @@ public class MoflonEmfBuilder extends IncrementalProjectBuilder { protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { IProject project = getProject(); IFolder folder = project.getFolder("model"); + if(!folder.exists()) { + return new IProject[] {project}; + } Collection resources = Arrays.asList(folder.members()); Collection genModelResources = resources.stream().filter(r -> r.getName().endsWith(".genmodel")).collect(Collectors.toList()); Collection ecoreResources = resources.stream().filter(r -> r.getName().endsWith(".ecore")).collect(Collectors.toList()); From c191adaf44a8ee33c9846739343c7dbed07b3744 Mon Sep 17 00:00:00 2001 From: Lars Fritsche Date: Tue, 11 Jul 2023 00:02:01 +0200 Subject: [PATCH 02/13] fixed npe for notifications that involve string attributes --- .../smartemf/runtime/notification/SmartEMFNotification.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/emfcodegenerator/src/org/emoflon/smartemf/runtime/notification/SmartEMFNotification.java b/emfcodegenerator/src/org/emoflon/smartemf/runtime/notification/SmartEMFNotification.java index 9461870a..79dc0d0d 100644 --- a/emfcodegenerator/src/org/emoflon/smartemf/runtime/notification/SmartEMFNotification.java +++ b/emfcodegenerator/src/org/emoflon/smartemf/runtime/notification/SmartEMFNotification.java @@ -245,11 +245,15 @@ public short getNewShortValue() { @Override public String getOldStringValue() { + if(oldValue == null) + return null; return oldValue.toString(); } @Override public String getNewStringValue() { + if(newValue == null) + return null; return newValue.toString(); } From 02286d330bd2e99fef96a213983413ae50d03f96 Mon Sep 17 00:00:00 2001 From: Lars Fritsche Date: Sat, 29 Jul 2023 17:24:23 +0200 Subject: [PATCH 03/13] fixed a bug where adding an element to a resource did not reset eContainer but opposite container edges --- .../src/org/emoflon/smartemf/runtime/SmartObject.java | 5 +++++ .../emoflon/smartemf/templates/SmartEMFObjectTemplate.xtend | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java b/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java index 41782e69..8e968c57 100644 --- a/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java +++ b/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java @@ -378,6 +378,11 @@ public NotifyStatus setContainment(EObject eContainer, EStructuralFeature featur status = setResource(eContainer.eResource(), true); return status; } + + protected void resetContainmentSilently() { + this.eContainer = null; + this.eContainingFeature = null; + } @Override public boolean isContainmentObject() { diff --git a/emfcodegenerator/src/org/emoflon/smartemf/templates/SmartEMFObjectTemplate.xtend b/emfcodegenerator/src/org/emoflon/smartemf/templates/SmartEMFObjectTemplate.xtend index 18303a5e..59aa78bf 100644 --- a/emfcodegenerator/src/org/emoflon/smartemf/templates/SmartEMFObjectTemplate.xtend +++ b/emfcodegenerator/src/org/emoflon/smartemf/templates/SmartEMFObjectTemplate.xtend @@ -361,7 +361,13 @@ class SmartEMFObjectTemplate implements CodeTemplate{ } «ENDIF» + «IF feature.container» + if(this.«TemplateUtil.getValidName(feature.name)» != null && value == null) { + resetContainmentSilently(); + } + «ENDIF» this.«TemplateUtil.getValidName(feature.name)» = value; + «IF feature.isMany && !"EFeatureMapEntry".equals(feature.EType.name) && !feature.EType.name.contains("MapEntry")» From eb0028cdf0357b1e283c8b45f0d2fee720dad4c8 Mon Sep 17 00:00:00 2001 From: Lars Fritsche Date: Sat, 29 Jul 2023 23:19:03 +0200 Subject: [PATCH 04/13] fixed a problem where setting a containment edge did not set the resource (recursively) --- .../smartemf/templates/SmartEMFObjectTemplate.xtend | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/emfcodegenerator/src/org/emoflon/smartemf/templates/SmartEMFObjectTemplate.xtend b/emfcodegenerator/src/org/emoflon/smartemf/templates/SmartEMFObjectTemplate.xtend index 59aa78bf..c4fd3454 100644 --- a/emfcodegenerator/src/org/emoflon/smartemf/templates/SmartEMFObjectTemplate.xtend +++ b/emfcodegenerator/src/org/emoflon/smartemf/templates/SmartEMFObjectTemplate.xtend @@ -382,13 +382,14 @@ class SmartEMFObjectTemplate implements CodeTemplate{ «ENDIF» «IF feature.containment» - if(value != null) - status = ((MinimalSObjectContainer) this.«TemplateUtil.getValidName(feature.name)»).setContainment(this, «TemplateUtil.getPackageClassName(feature)».Literals.«TemplateUtil.getLiteral(feature)»); - if(oldValue != null && value != null) { setResourceWithoutChecks(resource); } + if(value != null) + status = ((MinimalSObjectContainer) this.«TemplateUtil.getValidName(feature.name)»).setContainment(this, «TemplateUtil.getPackageClassName(feature)».Literals.«TemplateUtil.getLiteral(feature)»); + + if(status == NotifyStatus.SUCCESS_NO_NOTIFICATION || oldValue != null && value != null) «ENDIF» sendNotification(SmartEMFNotification.createSetNotification(this, «TemplateUtil.getPackageClassName(feature)».Literals.«TemplateUtil.getLiteral(feature)», oldValue, value, -1)); From 80fe92ad036e1c802cdb4f86b8546b891ba3325b Mon Sep 17 00:00:00 2001 From: Lars Fritsche Date: Wed, 2 Aug 2023 17:42:16 +0200 Subject: [PATCH 05/13] fixed missing notifications such as add messages for the ResourceContentSmartEList --- .../src/org/emoflon/smartemf/runtime/SmartObject.java | 6 ++++++ .../runtime/collections/ResourceContentSmartEList.java | 1 + .../smartemf/runtime/collections/SmartCollection.java | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java b/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java index 8e968c57..47f4f308 100644 --- a/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java +++ b/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java @@ -400,12 +400,18 @@ protected void sendNotification(Notification n) { protected void sendRemoveAdapterNotification(EObject obj) { if (resource != null) { for (Adapter a : resource.eAdapters()) { + if(obj.eContainingFeature() != null) { + a.notifyChanged(SmartEMFNotification.createRemoveNotification(obj.eContainer(), obj.eContainingFeature(), obj, -1)); + } a.notifyChanged(SmartEMFNotification.createRemovingAdapterNotification(this, null, a, -1)); } } } public void sendRemoveAdapterNotificationsRecursively(Adapter adapter) { + if(eContainingFeature() != null) { + adapter.notifyChanged(SmartEMFNotification.createRemoveNotification(eContainer, eContainingFeature(), this, -1)); + } adapter.notifyChanged(SmartEMFNotification.createRemovingAdapterNotification(this, null, adapter, -1)); setResourceOfContainments((o) -> o.sendRemoveAdapterNotificationsRecursively(adapter)); diff --git a/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java b/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java index 4bb197b0..8199eba2 100644 --- a/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java +++ b/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java @@ -40,6 +40,7 @@ public boolean add(T element) { if (element instanceof SmartObject) { resetContainment(element, !resource.equals(element.eResource())); ((SmartObject) element).setResource(resource, true); + sendAddNotification(element); return super.add(element); } else { element.eAdapters().addAll(resource.eAdapters()); diff --git a/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/SmartCollection.java b/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/SmartCollection.java index 8e3b3d64..a0c0e455 100644 --- a/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/SmartCollection.java +++ b/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/SmartCollection.java @@ -88,7 +88,8 @@ public NotifyStatus addInternal(T e, boolean addToEOpposite) { NotifyStatus resultStatus; if (feature.isContainment()) { - resultStatus = ((SmartObject) e).setContainment(eContainer, feature); + var smartObject = ((SmartObject) e); + resultStatus = smartObject.setContainment(eContainer, feature); } else resultStatus = NotifyStatus.SUCCESS_NO_NOTIFICATION; From d4e6bfd3cb8894249383d84fd0e433928a956349 Mon Sep 17 00:00:00 2001 From: Lars Fritsche Date: Thu, 10 Aug 2023 18:49:09 +0200 Subject: [PATCH 06/13] fixed a problem where too many add and remove messages were sent (when adding/removing directly from resources) --- .../runtime/collections/ResourceContentSmartEList.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java b/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java index 8199eba2..100e8470 100644 --- a/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java +++ b/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java @@ -40,7 +40,7 @@ public boolean add(T element) { if (element instanceof SmartObject) { resetContainment(element, !resource.equals(element.eResource())); ((SmartObject) element).setResource(resource, true); - sendAddNotification(element); +// sendAddNotification(element); return super.add(element); } else { element.eAdapters().addAll(resource.eAdapters()); @@ -155,8 +155,8 @@ public T remove(int index) { @Override public boolean remove(Object o) { boolean success = super.remove(o); - if (success) - sendRemoveNotification((EObject) o); +// if (success) +// sendRemoveNotification((EObject) o); if (o instanceof SmartObject) { ((SmartObject) o).setResource(null, true); From a7edf9e6bcae0934d4d2fed5f7a6dbae6e5286ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20M=C3=B6ller?= <45700082+adrianmoeller@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:31:06 +0200 Subject: [PATCH 07/13] Extend copyAll returned result --- .../src/org/moflon/core/utilities/eMoflonEMFUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/org.moflon.core.utilities/src/org/moflon/core/utilities/eMoflonEMFUtil.java b/org.moflon.core.utilities/src/org/moflon/core/utilities/eMoflonEMFUtil.java index 8f4b81e9..13564dae 100644 --- a/org.moflon.core.utilities/src/org/moflon/core/utilities/eMoflonEMFUtil.java +++ b/org.moflon.core.utilities/src/org/moflon/core/utilities/eMoflonEMFUtil.java @@ -1128,7 +1128,7 @@ private static Status createSameNameValidationProblem(GenPackage genPackage) { } /** - * Returns true iff the given {@link GenPackage} contains an {@link EClassifier} + * Returns true if the given {@link GenPackage} contains an {@link EClassifier} * with the same name as the package. * * @param genPackage @@ -1149,9 +1149,9 @@ public static CopyResult copyAll(Collection eObjects) { Map inversed = new HashMap<>(); for (var entry : copier.entrySet()) inversed.put(entry.getValue(), entry.getKey()); - return new CopyResult(result, inversed); + return new CopyResult(result, inversed, new HashMap<>(copier)); } - public record CopyResult(Collection copies, Map copies2originals) { + public record CopyResult(Collection copies, Map copies2originals, Map originals2copies) { } } From c94aa595ce3c3c5a8052dcbb753e5fdf7c808a61 Mon Sep 17 00:00:00 2001 From: Lars Fritsche Date: Tue, 15 Aug 2023 22:17:33 +0200 Subject: [PATCH 08/13] fixed an issue where removing the adapter from the resource led to a stackOverFlow --- .../src/org/emoflon/smartemf/persistence/AdapterList.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/emfcodegenerator/src/org/emoflon/smartemf/persistence/AdapterList.java b/emfcodegenerator/src/org/emoflon/smartemf/persistence/AdapterList.java index 25fbd661..2d9d2fe7 100644 --- a/emfcodegenerator/src/org/emoflon/smartemf/persistence/AdapterList.java +++ b/emfcodegenerator/src/org/emoflon/smartemf/persistence/AdapterList.java @@ -61,9 +61,10 @@ public boolean add(Adapter e) { @Override public boolean remove(Object o) { boolean remove = adapters.remove(o); - if (remove) + if (remove) { resource.adapterRemoved((Adapter) o); - resource.sendRemoveAdapterMessages((Adapter) o); + resource.sendRemoveAdapterMessages((Adapter) o); + } return remove; } From 57ced6de6e4f459779a00001130b4c78279d1a67 Mon Sep 17 00:00:00 2001 From: Lars Fritsche Date: Fri, 18 Aug 2023 01:59:55 +0200 Subject: [PATCH 09/13] fixed an issue with missing add messages when putting an element directly into a resource --- .../smartemf/runtime/collections/ResourceContentSmartEList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java b/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java index 100e8470..cb6883f7 100644 --- a/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java +++ b/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java @@ -40,7 +40,7 @@ public boolean add(T element) { if (element instanceof SmartObject) { resetContainment(element, !resource.equals(element.eResource())); ((SmartObject) element).setResource(resource, true); -// sendAddNotification(element); + sendAddNotification(element); return super.add(element); } else { element.eAdapters().addAll(resource.eAdapters()); From 2fd49b843f84f70ad69d910830482273cc7717da Mon Sep 17 00:00:00 2001 From: Lars Fritsche Date: Fri, 18 Aug 2023 02:00:27 +0200 Subject: [PATCH 10/13] improved the EMoflonModelVisualiser by using name attributes when available --- .../visualisation/models/EMoflonModelVisualiser.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/org.moflon.core.ui/src/org/moflon/core/ui/visualisation/models/EMoflonModelVisualiser.java b/org.moflon.core.ui/src/org/moflon/core/ui/visualisation/models/EMoflonModelVisualiser.java index 050e6b5a..105bfe6f 100644 --- a/org.moflon.core.ui/src/org/moflon/core/ui/visualisation/models/EMoflonModelVisualiser.java +++ b/org.moflon.core.ui/src/org/moflon/core/ui/visualisation/models/EMoflonModelVisualiser.java @@ -4,7 +4,9 @@ import java.util.Collection; import java.util.Map; +import org.eclipse.emf.ecore.EDataType; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EcorePackage; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.moflon.core.ui.VisualiserUtilities; @@ -68,6 +70,15 @@ private void determineObjectNames(Collection elements, Map Date: Sat, 19 Aug 2023 00:18:02 +0200 Subject: [PATCH 11/13] improved readability of SmartEMFNotification.toString() --- .../notification/SmartEMFNotification.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/emfcodegenerator/src/org/emoflon/smartemf/runtime/notification/SmartEMFNotification.java b/emfcodegenerator/src/org/emoflon/smartemf/runtime/notification/SmartEMFNotification.java index 79dc0d0d..24db58b7 100644 --- a/emfcodegenerator/src/org/emoflon/smartemf/runtime/notification/SmartEMFNotification.java +++ b/emfcodegenerator/src/org/emoflon/smartemf/runtime/notification/SmartEMFNotification.java @@ -2,6 +2,7 @@ import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EStructuralFeature; +import org.emoflon.smartemf.runtime.SmartObject; public final class SmartEMFNotification implements Notification { @@ -292,15 +293,28 @@ public String toString() { b.append("eventType: "); b.append(getEventTypeAsString()); b.append(", notifier: "); - b.append(notifier); + b.append(objectToString(notifier)); b.append(", feature: "); - b.append(feature); + b.append(feature != null ? feature.getName() : feature); b.append(", oldValue: "); - b.append(oldValue); + b.append(objectToString(oldValue)); b.append(", newValue: "); - b.append(newValue); + b.append(objectToString(newValue)); b.append(")"); return b.toString(); } + + private Object objectToString(Object obj) { + if(obj == null) + return obj; + + if(obj instanceof SmartObject smartObject) { + for(var attribute : smartObject.eClass().getEAllAttributes()) { + if(attribute.getName().equals("name")) + return smartObject.eClass().getName() + "(" + (String) smartObject.eGet(attribute) + ")"; + } + } + return obj.toString(); + } } From 7e4ecb6cf98ed79699010ba08eedbccbcdbdfe80 Mon Sep 17 00:00:00 2001 From: Lars Fritsche Date: Sat, 19 Aug 2023 00:18:24 +0200 Subject: [PATCH 12/13] removed unncessary remove Notifications and readded missing ones --- .../src/org/emoflon/smartemf/runtime/SmartObject.java | 2 +- .../runtime/collections/ResourceContentSmartEList.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java b/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java index 47f4f308..7f47046c 100644 --- a/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java +++ b/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java @@ -401,7 +401,7 @@ protected void sendRemoveAdapterNotification(EObject obj) { if (resource != null) { for (Adapter a : resource.eAdapters()) { if(obj.eContainingFeature() != null) { - a.notifyChanged(SmartEMFNotification.createRemoveNotification(obj.eContainer(), obj.eContainingFeature(), obj, -1)); +// a.notifyChanged(SmartEMFNotification.createRemoveNotification(obj.eContainer(), obj.eContainingFeature(), obj, -1)); } a.notifyChanged(SmartEMFNotification.createRemovingAdapterNotification(this, null, a, -1)); } diff --git a/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java b/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java index cb6883f7..8199eba2 100644 --- a/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java +++ b/emfcodegenerator/src/org/emoflon/smartemf/runtime/collections/ResourceContentSmartEList.java @@ -155,8 +155,8 @@ public T remove(int index) { @Override public boolean remove(Object o) { boolean success = super.remove(o); -// if (success) -// sendRemoveNotification((EObject) o); + if (success) + sendRemoveNotification((EObject) o); if (o instanceof SmartObject) { ((SmartObject) o).setResource(null, true); From d90faf48e31867f27298533c61386e1a03bfdc59 Mon Sep 17 00:00:00 2001 From: Lars Fritsche Date: Sat, 19 Aug 2023 01:10:53 +0200 Subject: [PATCH 13/13] added another message back in or else readded edges cannot be distinguished from removed ones --- .../src/org/emoflon/smartemf/runtime/SmartObject.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java b/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java index 7f47046c..47f4f308 100644 --- a/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java +++ b/emfcodegenerator/src/org/emoflon/smartemf/runtime/SmartObject.java @@ -401,7 +401,7 @@ protected void sendRemoveAdapterNotification(EObject obj) { if (resource != null) { for (Adapter a : resource.eAdapters()) { if(obj.eContainingFeature() != null) { -// a.notifyChanged(SmartEMFNotification.createRemoveNotification(obj.eContainer(), obj.eContainingFeature(), obj, -1)); + a.notifyChanged(SmartEMFNotification.createRemoveNotification(obj.eContainer(), obj.eContainingFeature(), obj, -1)); } a.notifyChanged(SmartEMFNotification.createRemovingAdapterNotification(this, null, a, -1)); }