Bug 511301 No debug from the initial behavior

Enable the capability to debug the behavior used to initiate the
execution. It also ensures this initial behavior appears in the list of
available threads as this latter evolves on its own. 

Change-Id: I4e3840dca178282d44466629da96b020e3c8fd08
Signed-off-by: jeremie.tatibouet <jeremie.tatibouet@cea.fr>
diff --git a/bundles/core/engines/org.eclipse.papyrus.moka.fuml/aspects/org/eclipse/papyrus/moka/fuml/profiling/Semantics/Loci/ExecutionFactoryProfiler.aj b/bundles/core/engines/org.eclipse.papyrus.moka.fuml/aspects/org/eclipse/papyrus/moka/fuml/profiling/Semantics/Loci/ExecutionFactoryProfiler.aj
new file mode 100644
index 0000000..53dbfbd
--- /dev/null
+++ b/bundles/core/engines/org.eclipse.papyrus.moka.fuml/aspects/org/eclipse/papyrus/moka/fuml/profiling/Semantics/Loci/ExecutionFactoryProfiler.aj
@@ -0,0 +1,40 @@
+/*****************************************************************************

+ * Copyright (c) 2017 CEA LIST and others.

+ * 

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *   CEA LIST - Initial API and implementation

+ *   

+ *****************************************************************************/

+

+package org.eclipse.papyrus.moka.fuml.profiling.Semantics.Loci;

+

+import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.IObject_;

+import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.BasicBehaviors.IExecution;

+import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.IExecutionFactory;

+import org.eclipse.uml2.uml.Behavior;

+import org.eclipse.uml2.uml.OpaqueBehavior;

+

+public aspect ExecutionFactoryProfiler extends ValueLifecycleObservable{

+

+	pointcut createExecution(IExecutionFactory factory, Behavior behavior, IObject_ context):

+		target(factory) &&

+		args(behavior, context) &&

+		call(* IExecutionFactory.createExecution(Behavior, IObject_));

+	

+	after(IExecutionFactory factory, Behavior behavior, IObject_ context) returning (IExecution execution): 

+		 createExecution(factory, behavior, context){

+		// The creation of an execution for a behavior is only notified if the

+		// the behavior for which the execution created is not an OpaqueBehavior

+		// and the execution is its own context (this implies the behavior is executed

+		// outside an instance of class)

+		if(!(behavior instanceof OpaqueBehavior) && execution == execution.getContext()) {

+			this.fireValueCreated(execution);

+		}

+	}

+	

+}

diff --git a/bundles/core/engines/org.eclipse.papyrus.moka.fuml/aspects/org/eclipse/papyrus/moka/fuml/profiling/Semantics/Loci/LocusProfiler.aj b/bundles/core/engines/org.eclipse.papyrus.moka.fuml/aspects/org/eclipse/papyrus/moka/fuml/profiling/Semantics/Loci/LocusProfiler.aj
index 1c9c0b6..789dfbc 100644
--- a/bundles/core/engines/org.eclipse.papyrus.moka.fuml/aspects/org/eclipse/papyrus/moka/fuml/profiling/Semantics/Loci/LocusProfiler.aj
+++ b/bundles/core/engines/org.eclipse.papyrus.moka.fuml/aspects/org/eclipse/papyrus/moka/fuml/profiling/Semantics/Loci/LocusProfiler.aj
@@ -14,15 +14,12 @@
 

 package org.eclipse.papyrus.moka.fuml.profiling.Semantics.Loci;

 

-import org.eclipse.papyrus.moka.fuml.profiling.MokaObservable;

-import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.IValue;

 import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.IExtensionalValue;

 import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.IObject_;

 import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.ILocus;

-import org.eclipse.papyrus.moka.service.IMokaExecutionListener;

 import org.eclipse.uml2.uml.Class;

 

-public aspect LocusProfiler extends MokaObservable{

+public aspect LocusProfiler extends ValueLifecycleObservable{

 	

 	pointcut instantiate(ILocus locus, Class type): 

 		target(locus) &&

@@ -42,17 +39,4 @@
 		this.fireValueDestroyed(value);

 	}

 	

-	public void fireValueCreated(final IValue value){

-		for(int i=0; i < this.listeners.size(); i++){

-			IMokaExecutionListener listener = this.listeners.get(i); 

-			listener.valueCreated(value);			

-		}

-	}

-	

-	public void fireValueDestroyed(final IValue value){

-		for(int i=0; i < this.listeners.size(); i++){

-			IMokaExecutionListener listener = this.listeners.get(i); 

-			listener.valueDestroyed(value);

-		}

-	} 

 }
\ No newline at end of file
diff --git a/bundles/core/engines/org.eclipse.papyrus.moka.fuml/aspects/org/eclipse/papyrus/moka/fuml/profiling/Semantics/Loci/ValueLifecycleObservable.java b/bundles/core/engines/org.eclipse.papyrus.moka.fuml/aspects/org/eclipse/papyrus/moka/fuml/profiling/Semantics/Loci/ValueLifecycleObservable.java
new file mode 100644
index 0000000..a9dc456
--- /dev/null
+++ b/bundles/core/engines/org.eclipse.papyrus.moka.fuml/aspects/org/eclipse/papyrus/moka/fuml/profiling/Semantics/Loci/ValueLifecycleObservable.java
@@ -0,0 +1,36 @@
+/*****************************************************************************

+ * Copyright (c) 2017 CEA LIST and others.

+ * 

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *   CEA LIST - Initial API and implementation

+ *   

+ *****************************************************************************/

+

+package org.eclipse.papyrus.moka.fuml.profiling.Semantics.Loci;

+

+import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.IValue;

+import org.eclipse.papyrus.moka.fuml.profiling.MokaObservable;

+import org.eclipse.papyrus.moka.service.IMokaExecutionListener;

+

+public class ValueLifecycleObservable extends MokaObservable{

+

+	public void fireValueCreated(final IValue value){

+		for(int i=0; i < this.listeners.size(); i++){

+			IMokaExecutionListener listener = this.listeners.get(i); 

+			listener.valueCreated(value);			

+		}

+	}

+	

+	public void fireValueDestroyed(final IValue value){

+		for(int i=0; i < this.listeners.size(); i++){

+			IMokaExecutionListener listener = this.listeners.get(i); 

+			listener.valueDestroyed(value);

+		}

+	} 

+	

+}

diff --git a/bundles/core/engines/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/impl/Actions/BasicActions/CallActionActivation.java b/bundles/core/engines/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/impl/Actions/BasicActions/CallActionActivation.java
index 1a814a2..64204b6 100644
--- a/bundles/core/engines/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/impl/Actions/BasicActions/CallActionActivation.java
+++ b/bundles/core/engines/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/impl/Actions/BasicActions/CallActionActivation.java
@@ -111,27 +111,5 @@
 			i = i + 1; // FUML12-36 Problem with CallActionActivation: possible infinite loop in removeCallExecution()
 		}
 	}
-
-	/*
-	 * public void animate(IRender animationManager){
-	 * // If a call is not synchronous then the node is animated as usual following the period of
-	 * // time specified by Moka constant. If it is synchronous then the node is animated until
-	 * // the animation is notified of the termination of the call
-	 * if(animationManager!=null){
-	 * this.animationManager = animationManager;
-	 * if(((CallAction)this.node).isSynchronous()){
-	 * animationManager.startRendering(this.node, AnimationKind.ANIMATED);
-	 * }else{
-	 * super.animate(animationManager);
-	 * }
-	 * }
-	 * }
-	 * 
-	 * public void notifyAnimationEnd(){
-	 * // Notify the termination of the animation period of the call action
-	 * if(this.animationManager!=null){
-	 * this.animationManager.stopRendering(this.node, AnimationKind.ANIMATED);
-	 * }
-	 * }
-	 */
+	
 }
diff --git a/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/DebugService.java b/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/DebugService.java
index bc64b88..40f99f1 100644
--- a/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/DebugService.java
+++ b/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/DebugService.java
@@ -18,6 +18,7 @@
 import org.eclipse.papyrus.moka.fuml.Semantics.Activities.IntermediateActivities.IActivityNodeActivation;

 import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.IObject_;

 import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.IValue;

+import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.BasicBehaviors.IExecution;

 import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.ISemanticVisitor;

 import org.eclipse.papyrus.moka.fuml.statemachines.interfaces.Semantics.StateMachines.IStateMachineSemanticVisitor;

 import org.eclipse.papyrus.moka.service.AbstractMokaService;

@@ -79,9 +80,15 @@
 		if (!this.debugTarget.isDisconnected()) {

 			if (value instanceof IObject_) {

 				IObject_ object = (IObject_) value;

-				if (DebugServiceHelper.INSTANCE.isActive(object)

-						&& this.debugTarget.isNewThread(object)) {

-					this.debugTarget.registerThread(object);

+				if(this.debugTarget.isNewThread(object)) {

+					if(object instanceof IExecution

+							&& ((IExecution)object).getContext() == object) {

+						this.debugTarget.registerThread(object);

+					}else {

+						if(DebugServiceHelper.INSTANCE.isActive(object)) {

+							this.debugTarget.registerThread(object);

+						}

+					}

 				}

 			}

 		}

diff --git a/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/IMokaThread.java b/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/IMokaThread.java
index 593b79b..ec985ae 100644
--- a/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/IMokaThread.java
+++ b/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/IMokaThread.java
@@ -30,5 +30,9 @@
 	public boolean getSuspensionFlag();

 

 	public void setSuspensionFlag(boolean mustSuspend);

+	

+	public void registered();

+	

+	public void unregistered();

 

 }

diff --git a/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/MokaDebugTarget.java b/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/MokaDebugTarget.java
index 50bee74..18bd692 100644
--- a/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/MokaDebugTarget.java
+++ b/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/MokaDebugTarget.java
@@ -56,7 +56,7 @@
 		this.executionThreads = new HashSet<IMokaThread>();
 		this.targetLock = new ReentrantLock(true);
 		this.status = MokaDebugTargetState.RUNNING;
-		fireCreationEvent();
+		this.fireCreationEvent();
 	}
 
 	public void setProcess(MokaProcess process) {
@@ -94,7 +94,6 @@
 		this.executionThreads.clear();
 		this.executionEngineProcess.terminate();
 		this.status = MokaDebugTargetState.TERMINATED;
-		this.fireTerminateEvent();
 	}
 
 	@Override
@@ -151,7 +150,9 @@
 
 	@Override
 	public void registerThread(IObject_ object) {
-		this.executionThreads.add(new MokaThread(this, object));
+		IMokaThread thread = new MokaThread(this, object);
+		this.executionThreads.add(thread);
+		thread.registered();
 	}
 
 	public boolean isNewThread(IObject_ object) {
@@ -177,6 +178,9 @@
 			targetThread = threadIterator.next();
 			if (targetThread.getLogicalThread() == object) {
 				threadIterator.remove();
+				targetThread.unregistered();
+			}else {
+				targetThread = null;
 			}
 		}
 	}
diff --git a/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/MokaThread.java b/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/MokaThread.java
index 9712a32..48592f8 100644
--- a/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/MokaThread.java
+++ b/bundles/core/services/org.eclipse.papyrus.moka.debug/src/org/eclipse/papyrus/moka/debug/engine/MokaThread.java
@@ -57,7 +57,6 @@
 		this.resumeCondition = this.threadLock.newCondition();
 		this.suspensionRequired = false;
 		this.status = MokaThreadState.RUNNING;
-		fireCreationEvent();
 	}
 
 	@Override
@@ -267,4 +266,16 @@
 		this.suspensionPoint = visitor;
 	}
 
+	@Override
+	public void registered() {
+		// Notify the debug interface that a new thread was registered
+		this.fireCreationEvent();
+	}
+
+	@Override
+	public void unregistered() {
+		// Notify the debug interface that a existing thread was destroyed
+		this.fireTerminateEvent();
+	}
+
 }