Skip to content

Commit 8b913a2

Browse files
authored
Fix several trace consistency and serialization issues (#215)
* Fix several trace consistency and serialization issues * Make sure to not create orphan operations twice
1 parent 2894856 commit 8b913a2

File tree

40 files changed

+4681
-2450
lines changed

40 files changed

+4681
-2450
lines changed

framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.engine/src/org/eclipse/gemoc/executionframework/engine/core/AbstractSequentialExecutionEngine.java

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
import java.util.ArrayList;
1515
import java.util.Arrays;
1616
import java.util.Collections;
17+
import java.util.HashMap;
18+
import java.util.HashSet;
1719
import java.util.List;
20+
import java.util.Map;
1821
import java.util.Set;
1922

2023
import org.eclipse.emf.ecore.EClass;
@@ -151,10 +154,18 @@ private Step<?> createStep(EObject caller, String className, String methodName,
151154
result.getMseoccurrence().getParameters().addAll(Arrays.asList(args));
152155
return result;
153156
}
157+
158+
private Map<EClass, Set<EOperation>> orphanOperations = new HashMap<EClass, Set<EOperation>>();
159+
160+
private void addOrpanOperation(EClass c, EOperation op) {
161+
if (!orphanOperations.containsKey(c)) {
162+
orphanOperations.put(c, new HashSet<>());
163+
}
164+
orphanOperations.get(c).add(op);
165+
}
154166

155167
private EOperation findOperation(EObject object, String className, String methodName) {
156-
// We try to find the corresponding EOperation in the execution
157-
// metamodel
168+
// We try to find the corresponding EOperation
158169
EOperation result = null;
159170
final List<EClass> openSet = new ArrayList<>();
160171
openSet.add(object.eClass());
@@ -173,28 +184,29 @@ private EOperation findOperation(EObject object, String className, String method
173184
return result;
174185
}
175186

176-
// If we didn't find it, we try to find the class that should contain
177-
// this operation
178-
EClass containingEClass = null;
179-
if (object.eClass().getName().equalsIgnoreCase(className)) {
180-
containingEClass = object.eClass();
181-
} else {
182-
for (EClass candidate : object.eClass().getEAllSuperTypes()) {
183-
if (candidate.getName().equalsIgnoreCase(className)) {
184-
containingEClass = candidate;
187+
// Else if the EOperation was created already
188+
if (orphanOperations.containsKey(object.eClass())) {
189+
for (EOperation op : orphanOperations.get(object.eClass())) {
190+
if (op.getName().equals(methodName)) {
191+
return op;
185192
}
186193
}
187194
}
188-
189-
// Then we create the missing operation (VERY approximatively)
195+
// Else we create the missing operation (VERY approximatively)
190196
EOperation operation = EcoreFactory.eINSTANCE.createEOperation();
191-
if (containingEClass != null) {
192-
containingEClass.getEOperations().add(operation);
193-
}
197+
this.getActionModel().getOrphanOperations().add(operation);
194198
operation.setName(methodName);
199+
addOrpanOperation(object.eClass(),operation);
195200
return operation;
196201
}
197202

203+
private MSEModel getActionModel() {
204+
if (_actionModel == null) {
205+
_actionModel = TraceFactory.eINSTANCE.createMSEModel();
206+
}
207+
return _actionModel;
208+
}
209+
198210
/**
199211
* Find the MSE element for the triplet caller/className/MethodName in the model
200212
* of precalculated possible MSE. If it doesn't exist yet, create one and add it
@@ -210,14 +222,9 @@ private EOperation findOperation(EObject object, String className, String method
210222
*/
211223
public final MSE findOrCreateMSE(EObject caller, String className, String methodName) {
212224
EOperation operation = findOperation(caller, className, methodName);
213-
// TODO Should be created/loaded before execution by analyzing the
214-
// model?
215-
if (_actionModel == null) {
216-
_actionModel = TraceFactory.eINSTANCE.createMSEModel();
217-
}
218225

219-
if (_actionModel != null) {
220-
for (MSE existingMSE : _actionModel.getOwnedMSEs()) {
226+
if (getActionModel() != null) {
227+
for (MSE existingMSE : getActionModel().getOwnedMSEs()) {
221228
if (existingMSE.getCaller().equals(caller) && ((existingMSE.getAction() != null && existingMSE.getAction().equals(operation)) || (existingMSE.getAction() == null && operation == null))) {
222229
// no need to create one, we already have it
223230
return existingMSE;
@@ -233,26 +240,26 @@ public final MSE findOrCreateMSE(EObject caller, String className, String method
233240
else
234241
mse.setName("MSE_" + caller.getClass().getSimpleName() + "_" + methodName);
235242
// and add it for possible reuse
236-
if (_actionModel != null) {
243+
if (getActionModel() != null) {
237244

238-
if (_actionModel.eResource() != null) {
239-
TransactionUtil.getEditingDomain(_actionModel.eResource());
240-
RecordingCommand command = new RecordingCommand(TransactionUtil.getEditingDomain(_actionModel.eResource()), "Saving new MSE ") {
245+
if (getActionModel().eResource() != null) {
246+
TransactionUtil.getEditingDomain(getActionModel().eResource());
247+
RecordingCommand command = new RecordingCommand(TransactionUtil.getEditingDomain(getActionModel().eResource()), "Saving new MSE ") {
241248
@Override
242249
protected void doExecute() {
243-
_actionModel.getOwnedMSEs().add(mse);
250+
getActionModel().getOwnedMSEs().add(mse);
244251
try {
245-
_actionModel.eResource().save(null);
252+
getActionModel().eResource().save(null);
246253
} catch (IOException e) {
247254
// TODO Auto-generated catch block
248255
e.printStackTrace();
249256
}
250257
}
251258
};
252-
TransactionUtil.getEditingDomain(_actionModel.eResource()).getCommandStack().execute(command);
259+
TransactionUtil.getEditingDomain(getActionModel().eResource()).getCommandStack().execute(command);
253260
}
254261
} else {
255-
_actionModel.getOwnedMSEs().add(mse);
262+
getActionModel().getOwnedMSEs().add(mse);
256263
}
257264
return mse;
258265
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.eclipse.gemoc.executionframework.engine.core;
2+
3+
import org.eclipse.core.runtime.IStatus;
4+
import org.eclipse.emf.transaction.ExceptionHandler;
5+
import org.eclipse.emf.transaction.RollbackException;
6+
7+
public class SimpleExceptionHandler implements ExceptionHandler {
8+
9+
private Exception e;
10+
11+
@Override
12+
public void handleException(Exception e) {
13+
this.e = e;
14+
}
15+
16+
public Throwable getException() {
17+
if (e instanceof RollbackException) {
18+
RollbackException e_cast = (RollbackException) e;
19+
return getFirstExceptionOfStatus(e_cast.getStatus());
20+
}
21+
return e;
22+
}
23+
24+
25+
private Throwable getFirstExceptionOfStatus(IStatus s) {
26+
if (s.getException() != null) {
27+
return s.getException();
28+
}
29+
30+
for (IStatus c : s.getChildren()) {
31+
Throwable t = getFirstExceptionOfStatus(c);
32+
if (t != null) {
33+
return t;
34+
}
35+
}
36+
return null;
37+
}
38+
}
223 Bytes
Loading

trace/commons/plugins/org.eclipse.gemoc.trace.commons.model.edit/plugin.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,4 @@ _UI_Value_states_feature = States
109109
_UI_State_startedSteps_feature = Started Steps
110110
_UI_State_endedSteps_feature = Ended Steps
111111
_UI_State_values_feature = Values
112+
_UI_MSEModel_orphanOperations_feature = Orphan Operations

trace/commons/plugins/org.eclipse.gemoc.trace.commons.model.edit/src/org/eclipse/gemoc/trace/commons/model/trace/provider/MSEModelItemProvider.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import org.eclipse.emf.ecore.EStructuralFeature;
1515

16+
import org.eclipse.emf.ecore.EcoreFactory;
1617
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
1718
import org.eclipse.emf.edit.provider.IItemLabelProvider;
1819
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
@@ -78,6 +79,7 @@ public Collection<? extends EStructuralFeature> getChildrenFeatures(Object objec
7879
if (childrenFeatures == null) {
7980
super.getChildrenFeatures(object);
8081
childrenFeatures.add(TracePackage.Literals.MSE_MODEL__OWNED_MS_ES);
82+
childrenFeatures.add(TracePackage.Literals.MSE_MODEL__ORPHAN_OPERATIONS);
8183
}
8284
return childrenFeatures;
8385
}
@@ -131,6 +133,7 @@ public void notifyChanged(Notification notification) {
131133

132134
switch (notification.getFeatureID(MSEModel.class)) {
133135
case TracePackage.MSE_MODEL__OWNED_MS_ES:
136+
case TracePackage.MSE_MODEL__ORPHAN_OPERATIONS:
134137
fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false));
135138
return;
136139
}
@@ -152,6 +155,11 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors
152155
(createChildParameter
153156
(TracePackage.Literals.MSE_MODEL__OWNED_MS_ES,
154157
TraceFactory.eINSTANCE.createGenericMSE()));
158+
159+
newChildDescriptors.add
160+
(createChildParameter
161+
(TracePackage.Literals.MSE_MODEL__ORPHAN_OPERATIONS,
162+
EcoreFactory.eINSTANCE.createEOperation()));
155163
}
156164

157165
/**
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16"/>
5+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>org.eclipse.gemoc.trace.commons.model.editor</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.jdt.core.javanature</nature>
26+
<nature>org.eclipse.pde.PluginNature</nature>
27+
</natures>
28+
</projectDescription>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: %pluginName
4+
Bundle-SymbolicName: org.eclipse.gemoc.trace.commons.model.editor;singleton:=true
5+
Automatic-Module-Name: org.eclipse.gemoc.trace.commons.model.editor
6+
Bundle-Version: 1.0.0.qualifier
7+
Bundle-ClassPath: .
8+
Bundle-Activator: org.eclipse.gemoc.trace.commons.model.trace.presentation.GenericTraceEditorPlugin$Implementation
9+
Bundle-Vendor: %providerName
10+
Bundle-Localization: plugin
11+
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
12+
Export-Package: org.eclipse.gemoc.trace.commons.model.trace.presentation
13+
Require-Bundle: org.eclipse.core.runtime,
14+
org.eclipse.core.resources;visibility:=reexport,
15+
org.eclipse.gemoc.trace.commons.model.edit;visibility:=reexport,
16+
org.eclipse.emf.ecore.xmi;visibility:=reexport,
17+
org.eclipse.emf.edit.ui;visibility:=reexport,
18+
org.eclipse.ui.ide;visibility:=reexport,
19+
org.eclipse.emf.ecore.edit;visibility:=reexport
20+
Bundle-ActivationPolicy: lazy
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
3+
bin.includes = .,\
4+
icons/,\
5+
META-INF/,\
6+
plugin.xml,\
7+
plugin.properties
8+
jars.compile.order = .
9+
source.. = src/
10+
output.. = bin
346 Bytes
Loading

0 commit comments

Comments
 (0)