Skip to content

Commit fbd0a06

Browse files
froueneAxelRICHARD
authored andcommitted
[1620] Handle short names in qualified names when direct editing
Bug: #1620 Signed-off-by: Florian ROUËNÉ <florian.rouene@obeosoft.com>
1 parent dce77a1 commit fbd0a06

7 files changed

Lines changed: 556 additions & 14 deletions

File tree

CHANGELOG.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
=== Improvements
3333

34+
- https://github.com/eclipse-syson/syson/issues/1620[#1620] [services] Handle short names in qualified names when direct editing.
35+
3436
=== New features
3537

3638
- https://github.com/eclipse-syson/syson/issues/1581[#1581] [diagrams] Display inherited `PortUsages` as graphical border nodes in diagrams.

backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/diagrams/general/view/GVDirectEditTests.java

Lines changed: 355 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Obeo.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Obeo - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.syson.application.data;
14+
15+
/**
16+
* Identifiers for "GeneralView-DirectEdit" project.
17+
*
18+
* @author frouene
19+
*/
20+
public class GeneralViewDirectEditTestProjectData {
21+
22+
public static final String SCRIPT_PATH = "/scripts/database-content/GeneralView-DirectEdit.sql";
23+
24+
public static final String EDITING_CONTEXT_ID = "e13cbf2f-3817-4708-bc39-e94eb9ac0d96";
25+
26+
/**
27+
* Ids of graphical elements.
28+
*/
29+
public static class GraphicalIds {
30+
31+
public static final String DIAGRAM_ID = "7464d7ea-ba4c-4171-b534-8b86ef6caf95";
32+
33+
}
34+
35+
/**
36+
* Ids for the semantic elements.
37+
*/
38+
public static class SemanticIds {
39+
40+
public static final String PART_USAGE_ID = "8b4669e5-ac6b-41de-88c4-8d7b63fe534e";
41+
public static final String PART_DEF_1_USAGE_ELEMENT_ID = "303aa440-a031-4419-a7b5-04fb8887a495";
42+
public static final String PART_DEF_2_USAGE_ELEMENT_ID = "6866b297-0fd5-4a99-8ae3-48dd61aae575";
43+
}
44+
45+
}

backend/application/syson-application/src/test/resources/scripts/database-content/GeneralView-DirectEdit.sql

Lines changed: 100 additions & 0 deletions
Large diffs are not rendered by default.

backend/metamodel/syson-sysml-metamodel/src/main/java/org/eclipse/syson/sysml/util/ElementUtil.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -355,25 +355,33 @@ private Collection<EObject> getAllRootsInResourceSet(EObject context) {
355355

356356
/**
357357
* Check if the given element's name match the given String.
358+
* If there is no match with the name, then the short name is checked.
358359
*
359360
* @param element
360-
* the {@link Element} to check.
361+
* the {@link Element} to check.
361362
* @param name
362-
* the name to match.
363-
* @return <code>true</code> if the name match, <code>false</code> otherwise.
363+
* the name to match.
364+
* @return <code>true</code> if a match is found, <code>false</code> otherwise.
364365
*/
365366
private boolean nameMatches(Element element, String name) {
366-
boolean matches = false;
367-
if (element != null && name != null) {
368-
String elementName = element.getName();
369-
if (elementName != null) {
370-
matches = elementName.strip().equals(name.strip());
371-
if (!matches && name.startsWith("'") && name.endsWith("'")) {
372-
// We give the option to quote names, but the quotes aren't part of the model.
373-
elementName = "'" + elementName + "'";
374-
matches = elementName.strip().equals(name.strip());
375-
}
376-
}
367+
if (element == null || name == null) {
368+
return false;
369+
}
370+
if (this.equalsConsideringOptionalQuotes(element.getName(), name)) {
371+
return true;
372+
}
373+
return this.equalsConsideringOptionalQuotes(element.getShortName(), name);
374+
}
375+
376+
private boolean equalsConsideringOptionalQuotes(String candidate, String query) {
377+
if (candidate == null || query == null) {
378+
return false;
379+
}
380+
boolean matches = candidate.strip().equals(query.strip());
381+
if (!matches && query.startsWith("'") && query.endsWith("'")) {
382+
// We give the option to quote names, but the quotes aren't part of the model.
383+
candidate = "'" + candidate + "'";
384+
matches = candidate.strip().equals(query.strip());
377385
}
378386
return matches;
379387
}

backend/services/syson-services/src/main/java/org/eclipse/syson/services/UtilService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,19 @@ public <T extends Element> T findByName(EObject object, String elementName) {
439439
* @return the found element or <code>null</code>.
440440
*/
441441
public <T extends Element> T findByNameAndType(EObject object, String elementName, Class<T> elementType) {
442+
// Use the semantic scoping rule based on Namespace resolution to find the most "valid" target
443+
if (object instanceof Element element) {
444+
Membership resolvedElement;
445+
if (element instanceof Namespace namespace) {
446+
resolvedElement = namespace.resolve(elementName);
447+
} else {
448+
resolvedElement = element.getOwningNamespace().resolve(elementName);
449+
}
450+
if (resolvedElement != null && elementType.isInstance(resolvedElement.getMemberElement())) {
451+
return (T) resolvedElement.getMemberElement();
452+
}
453+
}
454+
// No semantic valid target, fallback on any matching item but it might violate some scoping validation rule
442455
return this.elementUtil.findByNameAndType(object, elementName, elementType);
443456
}
444457

doc/content/modules/user-manual/pages/release-notes/2025.12.0.adoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ requirement <'SN'> {
4444

4545
== Improvements
4646

47+
- In diagrams, when using direct edit on graphical elements, it's now possible to use _short names_ in the qualified names.
48+
If two or more `Elements` share the same _short name_, {product} will search for the best candidate based on the scope of the element.
49+
Furthermore, if an ambiguity exists between the _short name_ and the _declared name_ of two different `Elements`, the declared name will be preferred.
50+
51+
For example in:
52+
53+
```
54+
package Drone {
55+
package <LA> Drone_LogicalArchitecture {
56+
part def CommonBattery;
57+
}
58+
package <PA> Drone_PhysicalArchitecture {
59+
part def Battery :> LA::CommonBattery;
60+
}
61+
}
62+
```
63+
64+
In the example above, when using the direct edit capability to subclass the _Battery_ `Part Definition`, it is now possible to type _LA::CommonBattery_ instead of _Drone_LogicalArchitecture::CommonBattery_.
65+
4766
== Technical details
4867

4968
* For technical details on this {product} release (including breaking changes and dependency updates), please refer to https://github.com/eclipse-syson/syson/blob/main/CHANGELOG.adoc[changelog].

0 commit comments

Comments
 (0)