Skip to content

Commit

Permalink
[2243] Modes and States can be mixed on T4C
Browse files Browse the repository at this point in the history
Updated Junit accordingly. Tests were runned with preference Mixed Mode
& State which is not the default case

Bug: 2243
Change-Id: If2511904255ca1249f9d2bf80508599093cfc3db
Signed-off-by: Philippe DUL <philippe.dul@thalesgroup.com>
  • Loading branch information
pdulth committed Oct 23, 2018
1 parent 1f118ce commit 247ff38
Show file tree
Hide file tree
Showing 14 changed files with 367 additions and 372 deletions.
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* 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
Expand All @@ -11,7 +11,10 @@

package org.polarsys.capella.core.model.helpers;

import org.eclipse.emf.ecore.EObject;
import org.polarsys.capella.core.data.capellacommon.CapellacommonFactory;
import org.polarsys.capella.core.data.capellacommon.FinalState;
import org.polarsys.capella.core.data.capellacommon.Mode;
import org.polarsys.capella.core.data.capellacommon.Region;
import org.polarsys.capella.core.data.capellacommon.State;
import org.polarsys.capella.core.model.helpers.naming.NamingConstants;
Expand Down Expand Up @@ -40,4 +43,24 @@ public static Region getPrimaryRegion(State state, boolean create) {
return state.getOwnedRegions().get(0);
}

/**
* Returns whether the given object is a pure State (a State with no special kinds like Final State or Mode).
*/
public static boolean isStrictState(EObject state) {
return (state instanceof State) && !(state instanceof Mode) && !(state instanceof FinalState);
}

/**
* Returns whether the given object is a Mode (a State with kind Mode).
*/
public static boolean isMode(EObject state) {
return (state instanceof Mode);
}

/**
* Returns whether the given object is strictly a State or a Mode (it excludes other special kind Final State)
*/
public static boolean isStrictModeState(EObject state) {
return ((state instanceof State) || (state instanceof Mode)) && !(state instanceof FinalState);
}
}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2017 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* 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
Expand Down Expand Up @@ -36,8 +36,6 @@
import org.polarsys.capella.core.data.capellacommon.Region;
import org.polarsys.capella.core.data.capellacommon.State;
import org.polarsys.capella.core.data.capellacommon.StateMachine;
import org.polarsys.capella.core.data.capellacommon.impl.ModeImpl;
import org.polarsys.capella.core.data.capellacommon.impl.StateImpl;
import org.polarsys.capella.core.data.capellacore.ModellingArchitecture;
import org.polarsys.capella.core.data.cs.BlockArchitecture;
import org.polarsys.capella.core.data.cs.Component;
Expand Down Expand Up @@ -71,6 +69,7 @@
import org.polarsys.capella.core.model.helpers.BlockArchitectureExt;
import org.polarsys.capella.core.model.helpers.CapellaElementExt;
import org.polarsys.capella.core.model.helpers.InterfaceExt;
import org.polarsys.capella.core.model.helpers.StateExt;
import org.polarsys.capella.core.model.preferences.CapellaModelPreferencesPlugin;

/**
Expand Down Expand Up @@ -360,15 +359,16 @@ public boolean canMoveModeState(State source, Region targetElement) {

if (targetElement.eContainer() != null && !(source instanceof FinalState)) {
EObject targetContainer = targetElement.eContainer();

if (!CapellaModelPreferencesPlugin.getDefault().isMixedModeStateAllowed()) {
boolean isSameType = true;
// Check source/target type compatibility if target is a Mode/State
if (targetContainer instanceof State) {
isSameType = targetContainer.eClass() == source.eClass();

} else if (targetContainer instanceof StateMachine) {
isSameType = getAllModeState(((StateMachine) targetContainer).getOwnedRegions().get(0)).size() > 0 ? getAllModeState(
((StateMachine) targetContainer).getOwnedRegions().get(0)).get(0).eClass() == source.eClass()
: true;
List<State> states = getAllModeState(((StateMachine) targetContainer).getOwnedRegions().get(0));
isSameType = !states.isEmpty() ? states.get(0).eClass() == source.eClass() : true;
}
// Move is allowed only when source and target are not mixed
return isSameType && !isDownwardModeStateHierarchyMixed(source) && !isModeStateHierarchyMixed(targetContainer);
Expand Down Expand Up @@ -423,15 +423,16 @@ public static boolean isDownwardModeStateHierarchyMixed(State inputState) {
* @return
*/
public static List<State> getModeStateHierarchy(EObject container) {
List<State> stateModeLst = new ArrayList<State>();
List<State> stateModeLst = new ArrayList<>();
if (container instanceof State) {
// Add contained modes/states
Iterator<EObject> iter = EcoreUtil.getAllContents(container, true);

while (iter.hasNext()) {
EObject eObj = iter.next();
if ((eObj.getClass() == StateImpl.class) || (eObj.getClass() == ModeImpl.class))
if (StateExt.isStrictModeState(eObj)) {
stateModeLst.add((State) eObj);
}
}

// Add itself
Expand All @@ -443,14 +444,16 @@ public static List<State> getModeStateHierarchy(EObject container) {
stateModeLst.add((State) parentState);
parentState = EcoreUtil2.getFirstContainer(parentState, CapellacommonPackage.eINSTANCE.getState());
}

} else if (container instanceof StateMachine) {
// Add contained modes/states only
Iterator<EObject> iter = EcoreUtil.getAllContents(container, true);

while (iter.hasNext()) {
EObject eObj = iter.next();
if ((eObj.getClass() == StateImpl.class) || (eObj.getClass() == ModeImpl.class))
if (StateExt.isStrictModeState(eObj)) {
stateModeLst.add((State) eObj);
}
}
}
return stateModeLst;
Expand All @@ -463,14 +466,15 @@ public static List<State> getModeStateHierarchy(EObject container) {
* @return
*/
public static List<State> getDownwardModeStateHierarchy(State state) {
List<State> stateModeLst = new ArrayList<State>();
List<State> stateModeLst = new ArrayList<>();
// Add contained modes/states
Iterator<EObject> iter = EcoreUtil.getAllContents(state, true);

while (iter.hasNext()) {
EObject eObj = iter.next();
if ((eObj.getClass() == StateImpl.class) || (eObj.getClass() == ModeImpl.class))
if (StateExt.isStrictModeState(eObj)) {
stateModeLst.add((State) eObj);
}
}

// Add itself
Expand All @@ -485,14 +489,15 @@ public static List<State> getDownwardModeStateHierarchy(State state) {
* @return list of Modes/States
*/
public static List<State> getAllModeState(Region region) {
List<State> stateModeLst = new ArrayList<State>();
List<State> stateModeLst = new ArrayList<>();
// Add contained modes/states only
Iterator<EObject> iter = EcoreUtil.getAllContents(region, true);

while (iter.hasNext()) {
EObject eObj = iter.next();
if ((eObj.getClass() == StateImpl.class) || (eObj.getClass() == ModeImpl.class))
if (StateExt.isStrictModeState(eObj)) {
stateModeLst.add((State) eObj);
}
}

return stateModeLst;
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* 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
Expand Down Expand Up @@ -739,15 +739,11 @@ private boolean isUndoublonLink(DSemanticDecorator sourceElement, DSemanticDecor
public boolean canCreateMode(EObject context, EObject containerView) {
Region testedRegion = getRegionFromView(containerView);
if (testedRegion != null) {
if (!CapellaModelPreferencesPlugin.getDefault().isMixedModeStateAllowed())
if (!CapellaModelPreferencesPlugin.getDefault().isMixedModeStateAllowed()) {
return MoveHelper.getInstance().canMoveModeState(CapellacommonFactory.eINSTANCE.createMode(), testedRegion);

for (IState st : getStatesOfRegion(testedRegion)) {
if ((st instanceof State) && !(st instanceof Mode) && !(st instanceof FinalState)) {
return false;
}
}
return true;
//If there is a State, then can't create a Mode
return getStatesOfRegion(testedRegion).stream().noneMatch(StateExt::isStrictState);
}
return false;
}
Expand Down Expand Up @@ -815,15 +811,12 @@ private Region getRegionFromView(EObject containerView) {
public boolean canCreateState(EObject context, EObject containerView) {
Region testedRegion = getRegionFromView(containerView);
if (testedRegion != null) {
if (!CapellaModelPreferencesPlugin.getDefault().isMixedModeStateAllowed())
if (!CapellaModelPreferencesPlugin.getDefault().isMixedModeStateAllowed()) {
return MoveHelper.getInstance().canMoveModeState(CapellacommonFactory.eINSTANCE.createState(), testedRegion);

for (IState st : getStatesOfRegion(testedRegion)) {
if (st instanceof Mode) {
return false;
}
}
return true;

//If there is a Mode, then can't create a State
return getStatesOfRegion(testedRegion).stream().noneMatch(StateExt::isMode);
}
return false;
}
Expand Down

0 comments on commit 247ff38

Please sign in to comment.