Bug 514856 - [BPMN] SequenceFlow derived properties
  merge from papyrus/streams/2.0-maintenance b7239c86cf4

Change-Id: I36eaee8280476eb68d9d537fcd1700bed8eaa6ce
Signed-off-by: Géry Deloge <gery.deloge@cea.fr>
diff --git a/org.eclipse.papyrus.bpmn.tests/src/org/eclipse/papyrus/bpmn/bpmnprofiletest/SequenceFlowCustomTest.java b/org.eclipse.papyrus.bpmn.tests/src/org/eclipse/papyrus/bpmn/bpmnprofiletest/SequenceFlowCustomTest.java
new file mode 100644
index 0000000..6825343
--- /dev/null
+++ b/org.eclipse.papyrus.bpmn.tests/src/org/eclipse/papyrus/bpmn/bpmnprofiletest/SequenceFlowCustomTest.java
@@ -0,0 +1,109 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA.
+ * <p>
+ * 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
+ * <p>
+ * Contributors:
+ * Géry Deloge (CEATech AQUI) gery.deloge@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.bpmn.bpmnprofiletest;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.papyrus.bpmn.BPMNProfile.BPMNProfilePackage;
+import org.eclipse.papyrus.bpmn.BPMNProfile.FlowNode;
+import org.eclipse.papyrus.bpmn.BPMNProfile.SequenceFlow;
+import org.eclipse.papyrus.bpmn.BPMNProfile.impl.SequenceFlowCustom;
+import org.eclipse.papyrus.bpmn.util.BPMNResource;
+import org.eclipse.uml2.uml.Activity;
+import org.eclipse.uml2.uml.ControlFlow;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.OpaqueAction;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.util.UMLUtil;
+import org.eclipse.uml2.uml.util.UMLUtil.StereotypeApplicationHelper;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SequenceFlowCustomTest {
+
+	private SequenceFlow sequenceFlow;
+	private OpaqueAction source;
+	private OpaqueAction target;
+
+	@Before
+	public void setUp() {
+		Model model = BPMNResource.createBPMNModel();
+
+		Activity activity = UMLFactory.eINSTANCE.createActivity();
+		model.getPackagedElements().add(activity);
+		StereotypeApplicationHelper.getInstance(null).applyStereotype(activity, BPMNProfilePackage.eINSTANCE.getBPMNProcess());
+
+		ControlFlow controlFlow = UMLFactory.eINSTANCE.createControlFlow();
+		controlFlow.setActivity(activity);
+		sequenceFlow = (SequenceFlow)StereotypeApplicationHelper.getInstance(null).applyStereotype(controlFlow, BPMNProfilePackage.eINSTANCE.getSequenceFlow());
+
+		source = UMLFactory.eINSTANCE.createOpaqueAction();
+		activity.getOwnedNodes().add(source);
+		StereotypeApplicationHelper.getInstance(null).applyStereotype(source, BPMNProfilePackage.eINSTANCE.getTask());
+
+		target = UMLFactory.eINSTANCE.createOpaqueAction();
+		activity.getOwnedNodes().add(target);
+		StereotypeApplicationHelper.getInstance(null).applyStereotype(target, BPMNProfilePackage.eINSTANCE.getTask());
+
+		controlFlow.setSource(source);
+		controlFlow.setTarget(target);
+	}
+
+	@Test
+	public void basicGetSourceRefGeneratedTest() {
+		try{
+			sequenceFlow.getSourceRef();
+		}
+		catch(UnsupportedOperationException e){
+			Assert.fail("missing custom code !");
+		}
+	}
+
+	@Test
+	public void basicGetSourceRefCustomTest() {
+		FlowNode f = SequenceFlowCustom.basicGetSourceRef(sequenceFlow);
+		Assert.assertNotNull(f);
+		assertEquals(f, UMLUtil.getStereotypeApplication(source, FlowNode.class));
+	}
+
+	@Test
+	public void basicGetSourceRefTest() {
+		FlowNode f = sequenceFlow.getSourceRef();
+		Assert.assertNotNull(f);
+		assertEquals(f, UMLUtil.getStereotypeApplication(source, FlowNode.class));
+	}
+
+	@Test
+	public void basicGetTargetRefGeneratedTest() {
+		try{
+			sequenceFlow.getTargetRef();
+		}
+		catch(UnsupportedOperationException e){
+			Assert.fail("missing custom code !");
+		}
+	}
+
+	@Test
+	public void basicGetTargetRefCustomTest() {
+		FlowNode f = SequenceFlowCustom.basicGetTargetRef(sequenceFlow);
+		Assert.assertNotNull(f);
+		assertEquals(f, UMLUtil.getStereotypeApplication(target, FlowNode.class));
+	}
+
+	@Test
+	public void basicGetTargetRefTest() {
+		FlowNode f = sequenceFlow.getTargetRef();
+		Assert.assertNotNull(f);
+		assertEquals(f, UMLUtil.getStereotypeApplication(target, FlowNode.class));
+	}
+}
diff --git a/org.eclipse.papyrus.bpmn/custom-src/org/eclipse/papyrus/bpmn/BPMNProfile/impl/SequenceFlowCustom.java b/org.eclipse.papyrus.bpmn/custom-src/org/eclipse/papyrus/bpmn/BPMNProfile/impl/SequenceFlowCustom.java
new file mode 100644
index 0000000..c68a35e
--- /dev/null
+++ b/org.eclipse.papyrus.bpmn/custom-src/org/eclipse/papyrus/bpmn/BPMNProfile/impl/SequenceFlowCustom.java
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA.
+ * <p>
+ * 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
+ * <p>
+ * Contributors:
+ * Géry Deloge (CEATech AQUI) gery.deloge@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.bpmn.BPMNProfile.impl;
+
+import org.eclipse.papyrus.bpmn.BPMNProfile.FlowNode;
+import org.eclipse.papyrus.bpmn.BPMNProfile.SequenceFlow;
+import org.eclipse.uml2.uml.ActivityNode;
+import org.eclipse.uml2.uml.ControlFlow;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+public class SequenceFlowCustom {
+
+	private SequenceFlowCustom() {
+	}
+
+	public static FlowNode basicGetSourceRef(SequenceFlow sequenceFlow) {
+		FlowNode flowNode = null;
+		ControlFlow controlFlow;
+		ActivityNode node;
+
+		if ((controlFlow = sequenceFlow.getBase_ControlFlow()) != null && (node = controlFlow.getSource()) != null) {
+			flowNode = UMLUtil.getStereotypeApplication(node, FlowNode.class);
+		}
+		return flowNode;
+	}
+
+	public static FlowNode basicGetTargetRef(SequenceFlow sequenceFlow) {
+		FlowNode flowNode = null;
+		ControlFlow controlFlow;
+		ActivityNode node;
+
+		if ((controlFlow = sequenceFlow.getBase_ControlFlow()) != null && (node = controlFlow.getTarget()) != null) {
+			flowNode = UMLUtil.getStereotypeApplication(node, FlowNode.class);
+		}
+		return flowNode;
+	}
+}
diff --git a/org.eclipse.papyrus.bpmn/src/org/eclipse/papyrus/bpmn/BPMNProfile/impl/SequenceFlowImpl.java b/org.eclipse.papyrus.bpmn/src/org/eclipse/papyrus/bpmn/BPMNProfile/impl/SequenceFlowImpl.java
index 92f881c..fa96e49 100755
--- a/org.eclipse.papyrus.bpmn/src/org/eclipse/papyrus/bpmn/BPMNProfile/impl/SequenceFlowImpl.java
+++ b/org.eclipse.papyrus.bpmn/src/org/eclipse/papyrus/bpmn/BPMNProfile/impl/SequenceFlowImpl.java
@@ -209,13 +209,10 @@
 	/**
 	 * <!-- begin-user-doc -->
 	 * <!-- end-user-doc -->
-	 * @generated
+	 * @generated NOT
 	 */
 	public FlowNode basicGetSourceRef() {
-		// TODO: implement this method to return the 'Source Ref' reference
-		// -> do not perform proxy resolution
-		// Ensure that you remove @generated or mark it @generated NOT
-		throw new UnsupportedOperationException();
+		return SequenceFlowCustom.basicGetSourceRef(this);
 	}
 
 	/**
@@ -242,13 +239,10 @@
 	/**
 	 * <!-- begin-user-doc -->
 	 * <!-- end-user-doc -->
-	 * @generated
+	 * @generated NOT
 	 */
 	public FlowNode basicGetTargetRef() {
-		// TODO: implement this method to return the 'Target Ref' reference
-		// -> do not perform proxy resolution
-		// Ensure that you remove @generated or mark it @generated NOT
-		throw new UnsupportedOperationException();
+		return SequenceFlowCustom.basicGetTargetRef(this);
 	}
 
 	/**
@@ -275,12 +269,12 @@
 		if (false) {
 			if (diagnostics != null) {
 				diagnostics.add
-					(new BasicDiagnostic
-						(Diagnostic.ERROR,
-						 BPMNProfileValidator.DIAGNOSTIC_SOURCE,
-						 BPMNProfileValidator.SEQUENCE_FLOW__SEQUENCE_FLOWCONDITION_EXPRESSION,
-						 EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { "SequenceFlowconditionExpression", EObjectValidator.getObjectLabel(this, context) }),
-						 new Object [] { this }));
+						(new BasicDiagnostic
+								(Diagnostic.ERROR,
+										BPMNProfileValidator.DIAGNOSTIC_SOURCE,
+										BPMNProfileValidator.SEQUENCE_FLOW__SEQUENCE_FLOWCONDITION_EXPRESSION,
+										EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { "SequenceFlowconditionExpression", EObjectValidator.getObjectLabel(this, context) }),
+										new Object [] { this }));
 			}
 			return false;
 		}
@@ -300,12 +294,12 @@
 		if (false) {
 			if (diagnostics != null) {
 				diagnostics.add
-					(new BasicDiagnostic
-						(Diagnostic.ERROR,
-						 BPMNProfileValidator.DIAGNOSTIC_SOURCE,
-						 BPMNProfileValidator.SEQUENCE_FLOW__SEQUENCE_FLOWSOURCE_REF,
-						 EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { "SequenceFlowsourceRef", EObjectValidator.getObjectLabel(this, context) }),
-						 new Object [] { this }));
+						(new BasicDiagnostic
+								(Diagnostic.ERROR,
+										BPMNProfileValidator.DIAGNOSTIC_SOURCE,
+										BPMNProfileValidator.SEQUENCE_FLOW__SEQUENCE_FLOWSOURCE_REF,
+										EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { "SequenceFlowsourceRef", EObjectValidator.getObjectLabel(this, context) }),
+										new Object [] { this }));
 			}
 			return false;
 		}
@@ -325,12 +319,12 @@
 		if (false) {
 			if (diagnostics != null) {
 				diagnostics.add
-					(new BasicDiagnostic
-						(Diagnostic.ERROR,
-						 BPMNProfileValidator.DIAGNOSTIC_SOURCE,
-						 BPMNProfileValidator.SEQUENCE_FLOW__SEQUENCE_FLOWTARGET_REF,
-						 EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { "SequenceFlowtargetRef", EObjectValidator.getObjectLabel(this, context) }),
-						 new Object [] { this }));
+						(new BasicDiagnostic
+								(Diagnostic.ERROR,
+										BPMNProfileValidator.DIAGNOSTIC_SOURCE,
+										BPMNProfileValidator.SEQUENCE_FLOW__SEQUENCE_FLOWTARGET_REF,
+										EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { "SequenceFlowtargetRef", EObjectValidator.getObjectLabel(this, context) }),
+										new Object [] { this }));
 			}
 			return false;
 		}
@@ -345,20 +339,20 @@
 	@Override
 	public Object eGet(int featureID, boolean resolve, boolean coreType) {
 		switch (featureID) {
-			case BPMNProfilePackage.SEQUENCE_FLOW__BASE_CONTROL_FLOW:
-				if (resolve) return getBase_ControlFlow();
-				return basicGetBase_ControlFlow();
-			case BPMNProfilePackage.SEQUENCE_FLOW__IS_IMMEDIATE:
-				return isImmediate();
-			case BPMNProfilePackage.SEQUENCE_FLOW__CONDITION_EXPRESSION:
-				if (resolve) return getConditionExpression();
-				return basicGetConditionExpression();
-			case BPMNProfilePackage.SEQUENCE_FLOW__SOURCE_REF:
-				if (resolve) return getSourceRef();
-				return basicGetSourceRef();
-			case BPMNProfilePackage.SEQUENCE_FLOW__TARGET_REF:
-				if (resolve) return getTargetRef();
-				return basicGetTargetRef();
+		case BPMNProfilePackage.SEQUENCE_FLOW__BASE_CONTROL_FLOW:
+			if (resolve) return getBase_ControlFlow();
+			return basicGetBase_ControlFlow();
+		case BPMNProfilePackage.SEQUENCE_FLOW__IS_IMMEDIATE:
+			return isImmediate();
+		case BPMNProfilePackage.SEQUENCE_FLOW__CONDITION_EXPRESSION:
+			if (resolve) return getConditionExpression();
+			return basicGetConditionExpression();
+		case BPMNProfilePackage.SEQUENCE_FLOW__SOURCE_REF:
+			if (resolve) return getSourceRef();
+			return basicGetSourceRef();
+		case BPMNProfilePackage.SEQUENCE_FLOW__TARGET_REF:
+			if (resolve) return getTargetRef();
+			return basicGetTargetRef();
 		}
 		return super.eGet(featureID, resolve, coreType);
 	}
@@ -371,21 +365,21 @@
 	@Override
 	public void eSet(int featureID, Object newValue) {
 		switch (featureID) {
-			case BPMNProfilePackage.SEQUENCE_FLOW__BASE_CONTROL_FLOW:
-				setBase_ControlFlow((ControlFlow)newValue);
-				return;
-			case BPMNProfilePackage.SEQUENCE_FLOW__IS_IMMEDIATE:
-				setIsImmediate((Boolean)newValue);
-				return;
-			case BPMNProfilePackage.SEQUENCE_FLOW__CONDITION_EXPRESSION:
-				setConditionExpression((BPMNExpression)newValue);
-				return;
-			case BPMNProfilePackage.SEQUENCE_FLOW__SOURCE_REF:
-				setSourceRef((FlowNode)newValue);
-				return;
-			case BPMNProfilePackage.SEQUENCE_FLOW__TARGET_REF:
-				setTargetRef((FlowNode)newValue);
-				return;
+		case BPMNProfilePackage.SEQUENCE_FLOW__BASE_CONTROL_FLOW:
+			setBase_ControlFlow((ControlFlow)newValue);
+			return;
+		case BPMNProfilePackage.SEQUENCE_FLOW__IS_IMMEDIATE:
+			setIsImmediate((Boolean)newValue);
+			return;
+		case BPMNProfilePackage.SEQUENCE_FLOW__CONDITION_EXPRESSION:
+			setConditionExpression((BPMNExpression)newValue);
+			return;
+		case BPMNProfilePackage.SEQUENCE_FLOW__SOURCE_REF:
+			setSourceRef((FlowNode)newValue);
+			return;
+		case BPMNProfilePackage.SEQUENCE_FLOW__TARGET_REF:
+			setTargetRef((FlowNode)newValue);
+			return;
 		}
 		super.eSet(featureID, newValue);
 	}
@@ -398,21 +392,21 @@
 	@Override
 	public void eUnset(int featureID) {
 		switch (featureID) {
-			case BPMNProfilePackage.SEQUENCE_FLOW__BASE_CONTROL_FLOW:
-				setBase_ControlFlow((ControlFlow)null);
-				return;
-			case BPMNProfilePackage.SEQUENCE_FLOW__IS_IMMEDIATE:
-				setIsImmediate(IS_IMMEDIATE_EDEFAULT);
-				return;
-			case BPMNProfilePackage.SEQUENCE_FLOW__CONDITION_EXPRESSION:
-				setConditionExpression((BPMNExpression)null);
-				return;
-			case BPMNProfilePackage.SEQUENCE_FLOW__SOURCE_REF:
-				setSourceRef((FlowNode)null);
-				return;
-			case BPMNProfilePackage.SEQUENCE_FLOW__TARGET_REF:
-				setTargetRef((FlowNode)null);
-				return;
+		case BPMNProfilePackage.SEQUENCE_FLOW__BASE_CONTROL_FLOW:
+			setBase_ControlFlow((ControlFlow)null);
+			return;
+		case BPMNProfilePackage.SEQUENCE_FLOW__IS_IMMEDIATE:
+			setIsImmediate(IS_IMMEDIATE_EDEFAULT);
+			return;
+		case BPMNProfilePackage.SEQUENCE_FLOW__CONDITION_EXPRESSION:
+			setConditionExpression((BPMNExpression)null);
+			return;
+		case BPMNProfilePackage.SEQUENCE_FLOW__SOURCE_REF:
+			setSourceRef((FlowNode)null);
+			return;
+		case BPMNProfilePackage.SEQUENCE_FLOW__TARGET_REF:
+			setTargetRef((FlowNode)null);
+			return;
 		}
 		super.eUnset(featureID);
 	}
@@ -425,16 +419,16 @@
 	@Override
 	public boolean eIsSet(int featureID) {
 		switch (featureID) {
-			case BPMNProfilePackage.SEQUENCE_FLOW__BASE_CONTROL_FLOW:
-				return base_ControlFlow != null;
-			case BPMNProfilePackage.SEQUENCE_FLOW__IS_IMMEDIATE:
-				return isImmediate != IS_IMMEDIATE_EDEFAULT;
-			case BPMNProfilePackage.SEQUENCE_FLOW__CONDITION_EXPRESSION:
-				return conditionExpression != null;
-			case BPMNProfilePackage.SEQUENCE_FLOW__SOURCE_REF:
-				return basicGetSourceRef() != null;
-			case BPMNProfilePackage.SEQUENCE_FLOW__TARGET_REF:
-				return basicGetTargetRef() != null;
+		case BPMNProfilePackage.SEQUENCE_FLOW__BASE_CONTROL_FLOW:
+			return base_ControlFlow != null;
+		case BPMNProfilePackage.SEQUENCE_FLOW__IS_IMMEDIATE:
+			return isImmediate != IS_IMMEDIATE_EDEFAULT;
+		case BPMNProfilePackage.SEQUENCE_FLOW__CONDITION_EXPRESSION:
+			return conditionExpression != null;
+		case BPMNProfilePackage.SEQUENCE_FLOW__SOURCE_REF:
+			return basicGetSourceRef() != null;
+		case BPMNProfilePackage.SEQUENCE_FLOW__TARGET_REF:
+			return basicGetTargetRef() != null;
 		}
 		return super.eIsSet(featureID);
 	}
@@ -448,12 +442,12 @@
 	@SuppressWarnings("unchecked")
 	public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException {
 		switch (operationID) {
-			case BPMNProfilePackage.SEQUENCE_FLOW___SEQUENCE_FLOWCONDITION_EXPRESSION__DIAGNOSTICCHAIN_MAP:
-				return SequenceFlowconditionExpression((DiagnosticChain)arguments.get(0), (Map<Object, Object>)arguments.get(1));
-			case BPMNProfilePackage.SEQUENCE_FLOW___SEQUENCE_FLOWSOURCE_REF__DIAGNOSTICCHAIN_MAP:
-				return SequenceFlowsourceRef((DiagnosticChain)arguments.get(0), (Map<Object, Object>)arguments.get(1));
-			case BPMNProfilePackage.SEQUENCE_FLOW___SEQUENCE_FLOWTARGET_REF__DIAGNOSTICCHAIN_MAP:
-				return SequenceFlowtargetRef((DiagnosticChain)arguments.get(0), (Map<Object, Object>)arguments.get(1));
+		case BPMNProfilePackage.SEQUENCE_FLOW___SEQUENCE_FLOWCONDITION_EXPRESSION__DIAGNOSTICCHAIN_MAP:
+			return SequenceFlowconditionExpression((DiagnosticChain)arguments.get(0), (Map<Object, Object>)arguments.get(1));
+		case BPMNProfilePackage.SEQUENCE_FLOW___SEQUENCE_FLOWSOURCE_REF__DIAGNOSTICCHAIN_MAP:
+			return SequenceFlowsourceRef((DiagnosticChain)arguments.get(0), (Map<Object, Object>)arguments.get(1));
+		case BPMNProfilePackage.SEQUENCE_FLOW___SEQUENCE_FLOWTARGET_REF__DIAGNOSTICCHAIN_MAP:
+			return SequenceFlowtargetRef((DiagnosticChain)arguments.get(0), (Map<Object, Object>)arguments.get(1));
 		}
 		return super.eInvoke(operationID, arguments);
 	}