From f26899391cbb79b317b51d7bf0aa21e5b4a1f8a3 Mon Sep 17 00:00:00 2001 From: Anita Matei Gabriel Date: Tue, 11 Jun 2024 21:14:30 +0300 Subject: [PATCH] \#2873 fix state query for activated elements Change-Id: I25f3b0e7bdc0a33f147a3b439aa2a3638f0b0b04 Signed-off-by: Anita Matei Gabriel --- .../capella/core/model/helpers/StateExt.java | 16 ++-- .../AbstractStateParentActiveElements.java | 88 +++++++++---------- .../SemanticQueries/SemanticQueries.capella | 24 +++-- 3 files changed, 70 insertions(+), 58 deletions(-) diff --git a/core/plugins/org.polarsys.capella.core.model.helpers/src/org/polarsys/capella/core/model/helpers/StateExt.java b/core/plugins/org.polarsys.capella.core.model.helpers/src/org/polarsys/capella/core/model/helpers/StateExt.java index 021175a788..d68256883a 100644 --- a/core/plugins/org.polarsys.capella.core.model.helpers/src/org/polarsys/capella/core/model/helpers/StateExt.java +++ b/core/plugins/org.polarsys.capella.core.model.helpers/src/org/polarsys/capella/core/model/helpers/StateExt.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature.Setting; @@ -23,6 +24,7 @@ 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.Pseudostate; import org.polarsys.capella.core.data.capellacommon.Region; import org.polarsys.capella.core.data.capellacommon.State; import org.polarsys.capella.core.data.fa.AbstractFunction; @@ -93,13 +95,15 @@ public static List getActiveElements(State state) { return result; } - public static List getRecursiveSubStates(State state) { - List result = new ArrayList(); - for (Region region : state.getOwnedRegions()) { - List rStates = region.getOwnedStates(); - for(AbstractState s : rStates) { + public static List getNonPseudoRecursiveSubStates(State state) { + List result = new ArrayList(); + + for (Region region : ((State) state).getOwnedRegions()) { + List rStates = region.getOwnedStates().stream().filter(State.class::isInstance).map(State.class::cast) + .collect(Collectors.toList()); + for (State s : rStates) { result.add(s); - result.addAll(getRecursiveSubStates((State)s)); + result.addAll(getNonPseudoRecursiveSubStates(s)); } } return result; diff --git a/core/plugins/org.polarsys.capella.core.semantic.queries/src/org/polarsys/capella/core/semantic/queries/basic/queries/AbstractStateParentActiveElements.java b/core/plugins/org.polarsys.capella.core.semantic.queries/src/org/polarsys/capella/core/semantic/queries/basic/queries/AbstractStateParentActiveElements.java index 3b305d453d..2787af695a 100644 --- a/core/plugins/org.polarsys.capella.core.semantic.queries/src/org/polarsys/capella/core/semantic/queries/basic/queries/AbstractStateParentActiveElements.java +++ b/core/plugins/org.polarsys.capella.core.semantic.queries/src/org/polarsys/capella/core/semantic/queries/basic/queries/AbstractStateParentActiveElements.java @@ -1,44 +1,44 @@ -/******************************************************************************* - * Copyright (c) 2019, 2020 THALES GLOBAL SERVICES. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Thales Global Services - initial API and implementation - *******************************************************************************/ -package org.polarsys.capella.core.semantic.queries.basic.queries; - -import java.util.ArrayList; -import java.util.List; - -import org.polarsys.capella.common.helpers.query.IQuery; -import org.polarsys.capella.core.data.capellacommon.State; -import org.polarsys.capella.core.model.helpers.StateExt; - -public class AbstractStateParentActiveElements implements IQuery { - - /** - * Constructor. - */ - public AbstractStateParentActiveElements() { - } - - @Override - public List compute(Object object) { - List result = new ArrayList(); - if (object instanceof State) { - State state = (State) object; - - List subStates = StateExt.getRecursiveSubStates(state); - for (Object obj : subStates) { - result.addAll(StateExt.getActiveElements((State) obj)); - } - } - - return result; - } -} +/******************************************************************************* + * Copyright (c) 2019, 2020 THALES GLOBAL SERVICES. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Thales Global Services - initial API and implementation + *******************************************************************************/ +package org.polarsys.capella.core.semantic.queries.basic.queries; + +import java.util.ArrayList; +import java.util.List; + +import org.polarsys.capella.common.helpers.query.IQuery; +import org.polarsys.capella.core.data.capellacommon.State; +import org.polarsys.capella.core.model.helpers.StateExt; + +public class AbstractStateParentActiveElements implements IQuery { + + /** + * Constructor. + */ + public AbstractStateParentActiveElements() { + } + + @Override + public List compute(Object object) { + List result = new ArrayList(); + if (object instanceof State) { + State state = (State) object; + + List subStates = StateExt.getNonPseudoRecursiveSubStates(state); + for (Object obj : subStates) { + result.addAll(StateExt.getActiveElements((State) obj)); + } + } + + return result; + } +} diff --git a/tests/plugins/org.polarsys.capella.test.semantic.queries.ju/model/SemanticQueries/SemanticQueries.capella b/tests/plugins/org.polarsys.capella.test.semantic.queries.ju/model/SemanticQueries/SemanticQueries.capella index 3a06ea870d..d1f91fb90b 100644 --- a/tests/plugins/org.polarsys.capella.test.semantic.queries.ju/model/SemanticQueries/SemanticQueries.capella +++ b/tests/plugins/org.polarsys.capella.test.semantic.queries.ju/model/SemanticQueries/SemanticQueries.capella @@ -1685,20 +1685,24 @@ + id="384597dd-fdbc-4fc4-acae-68451e8f69e2" name="State 1" referencedStates="#de7c3db9-d166-4445-b80d-a2d6a592b3c0 #4c15290e-ac40-409e-b550-410bc766760b"> + id="a42786bc-6f51-4a8d-8b9c-900e20f2d6f3" name="region" involvedStates="#de7c3db9-d166-4445-b80d-a2d6a592b3c0 #4c15290e-ac40-409e-b550-410bc766760b"> + id="de7c3db9-d166-4445-b80d-a2d6a592b3c0" name="State 1_1" referencedStates="#7d1233e9-013f-4ae0-a692-f847f6502390 #d482e9f6-6cb7-4e07-b791-d860983a9623"> + id="947aacb8-ab3a-4555-b6f6-0a2b3f826b92" name="region" involvedStates="#7d1233e9-013f-4ae0-a692-f847f6502390 #d482e9f6-6cb7-4e07-b791-d860983a9623"> + + @@ -1708,20 +1712,24 @@ + id="69c99509-e445-46a7-93dc-ee9162790fa2" name="Mode 1" referencedStates="#8f7ce582-1a8f-499b-a589-066235ca5dfe #d068f8d0-1020-4842-9d10-a4fea81aa997"> + id="a22ff7b4-b414-4459-a080-d21f04f16eec" name="region" involvedStates="#8f7ce582-1a8f-499b-a589-066235ca5dfe #d068f8d0-1020-4842-9d10-a4fea81aa997"> + id="8f7ce582-1a8f-499b-a589-066235ca5dfe" name="Mode 1_1" referencedStates="#3bffa8df-2534-4669-8203-0ddb0f13422c #528bf34a-77ee-4adb-845f-4056e7651c9e"> + id="6a6c1472-034e-487d-9961-ac4d1e5dca44" name="region" involvedStates="#3bffa8df-2534-4669-8203-0ddb0f13422c #528bf34a-77ee-4adb-845f-4056e7651c9e"> + +