Repository navigation
ST6RI-977 Add a virtual container for detached inferred elements #823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
597 changes: 597 additions & 0 deletions
597
...omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/VirtualContainerTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file modified
BIN
-20.8 KB
(97%)
org.omg.sysml.logic.bundle/lib/org.omg.sysml.logic-0.64.0-SNAPSHOT.jar
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
org.omg.sysml.logic/src/main/java/org/omg/sysml/util/VirtualContainer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /** | ||
| * SysML 2 Pilot Implementation | ||
| * Copyright (c) 2026 Obeo | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the Eclipse Public License, version 2, as published by | ||
| * the Eclipse Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Eclipse Public License for more details. | ||
| * | ||
| * You should have received a copy of the Eclipse Public License | ||
| * along with this program. If not, see <https://www.eclipse.org/legal/epl-2.0/>. | ||
| * | ||
| * @license EPL-2.0 <http://spdx.org/licenses/EPL-2.0> | ||
| */ | ||
| package org.omg.sysml.util; | ||
|
|
||
| import org.eclipse.emf.common.notify.impl.AdapterImpl; | ||
| import org.eclipse.emf.ecore.EObject; | ||
| import org.omg.sysml.lang.sysml.Element; | ||
|
|
||
| /** | ||
| * Links an element created outside the model, such as a feature chain or a binding connector | ||
| * inferred for an implied relationship, to the model element for which it was created. | ||
| * <p> | ||
| * The specification has no detached elements: the implied Relationship is owned by the element | ||
| * being constrained, and a feature chain it targets is owned by that Relationship. KerML §8.4.3.1: | ||
| * "In all cases, the source and owningRelatedElement of the Relationship is the Element being | ||
| * constrained, with the target being as given in the last column of the table." KerML §7.3.4.6: | ||
| * "the related element specified using the feature chain notation becomes an owned related feature | ||
| * of the relationship with the feature chain as notated." The implementation creates such elements | ||
| * before the Relationship that will own them; this adapter records their future owner so that | ||
| * scope lookups can reach the model from them. It is recorded when such an element is stored as | ||
| * the target of an implied relationship: an implicit general type, an implicit featuring type or | ||
| * an implicit binding connector, whose implied relationship is its owning membership. | ||
| * <p> | ||
| * The link does not change the model. Once the element is really contained, its real container | ||
| * takes precedence: use {@link ElementUtil#getEffectiveContainer(EObject)} rather than this class. | ||
| * <p> | ||
| * Specification quotations are from KerML 1.1 Beta 2. | ||
| */ | ||
| public final class VirtualContainer extends AdapterImpl { | ||
|
|
||
| private final Element container; | ||
|
|
||
| private VirtualContainer(Element container) { | ||
| this.container = container; | ||
| } | ||
|
|
||
| /** | ||
| * Records {@code container} as the virtual container of an element that is the root of a | ||
| * detached tree: it is not a proxy, has no container and is not in a resource. Any other element | ||
| * is left unchanged, as is an element that already has a virtual container. | ||
| * <p> | ||
| * A model built without a resource has roots that are not in a resource either, and one of them | ||
| * can be stored as the target of an implied relationship owned by one of its own members, such | ||
| * as the featuring type of a nested feature. The link is not recorded when {@code element} is | ||
| * already an effective container of {@code container}, so that effective containers never form | ||
| * a cycle and {@link ElementUtil#getClosestElementInResource(EObject)} terminates. | ||
| * | ||
| * @param <T> the type of the element | ||
| * @param element the element stored as the target of an implied relationship | ||
| * @param container the model element that owns the implied relationship | ||
| * @return {@code element} | ||
| */ | ||
| public static <T extends EObject> T attach(T element, Element container) { | ||
| if (isDetachedRoot(element) && container != null && getVirtualContainer(element) == null | ||
| && !isEffectiveContainerOf(element, container)) { | ||
| element.eAdapters().add(new VirtualContainer(container)); | ||
| } | ||
| return element; | ||
| } | ||
|
|
||
| private static boolean isDetachedRoot(EObject element) { | ||
| return element != null && !element.eIsProxy() && element.eContainer() == null && element.eResource() == null; | ||
| } | ||
|
|
||
| private static boolean isEffectiveContainerOf(EObject ancestor, EObject element) { | ||
| for (EObject current = element; current != null; current = ElementUtil.getEffectiveContainer(current)) { | ||
| if (current == ancestor) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the virtual container recorded for an element. | ||
| * | ||
| * @param element the element to inspect | ||
| * @return the recorded container, or {@code null} when none was recorded | ||
| */ | ||
| public static Element getVirtualContainer(EObject element) { | ||
| if (element == null) { | ||
| return null; | ||
| } | ||
| for (var adapter : element.eAdapters()) { | ||
| if (adapter instanceof VirtualContainer virtual) { | ||
| return virtual.container; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } |
Binary file modified
BIN
-10.9 KB
(99%)
org.omg.sysml.model.bundle/lib/org.omg.sysml.model-0.64.0-SNAPSHOT.jar
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.