Skip to content

Commit e9d3a92

Browse files
committed
[2105] Display textual representation of expressions in the Explorer
Bug: #2105 Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
1 parent 75b6856 commit e9d3a92

7 files changed

Lines changed: 103 additions & 2 deletions

File tree

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ As a result, the following GraphQL mutations have been removed `exposeRequiremen
3030

3131
=== Improvements
3232

33+
- https://github.com/eclipse-syson/syson/issues/2105[#2105] [explorer] In the _Explorer_ view, `Expression` elements now display their full textual representation
3334

3435
=== New features
3536

backend/application/syson-application/src/test/java/org/eclipse/syson/application/controller/explorer/view/SysONExplorerTests.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.eclipse.syson.application.controller.explorer.testers.ExpandAllTreeItemTester;
5050
import org.eclipse.syson.application.controller.explorer.testers.TreeItemContextMenuTester;
5151
import org.eclipse.syson.application.controller.explorer.testers.TreePathTester;
52+
import org.eclipse.syson.application.data.ActionTransitionUsagesProjectData;
5253
import org.eclipse.syson.application.data.GeneralViewEmptyTestProjectData;
5354
import org.eclipse.syson.application.data.ProjectWithLibraryDependencyContainingCommentAndLibraryPackageTestProjectData;
5455
import org.eclipse.syson.application.data.ProjectWithLibraryDependencyContainingLibraryPackageTestProjectData;
@@ -871,4 +872,70 @@ public void sysONExplorerTreeItemContextMenuEntriesTest() {
871872
.verify(Duration.ofSeconds(10));
872873

873874
}
875+
876+
@DisplayName("GIVEN the SysON Explorer, WHEN displaying an Expression item, THEN the item's label shows the textual representation of the expression")
877+
@Sql(scripts = { ActionTransitionUsagesProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
878+
@Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
879+
@Test
880+
public void sysONExplorerTreeExpressionLabelTest() {
881+
882+
var optionalEditingContext = this.editingContextSearchService.findById(ActionTransitionUsagesProjectData.EDITING_CONTEXT_ID);
883+
TreeDescription treeDescription = optionalEditingContext
884+
.flatMap(editingContext -> this.representationDescriptionSearchService.findById(editingContext, this.sysONExplorerTreeDescriptionId))
885+
.filter(TreeDescription.class::isInstance)
886+
.map(TreeDescription.class::cast)
887+
.orElse(null);
888+
List<String> defaultFilters = this.sysonTreeFilterProvider.get(null, treeDescription).stream()
889+
.filter(TreeFilter::defaultState)
890+
.map(TreeFilter::id)
891+
.toList();
892+
893+
var expandedItemIds = List.of(
894+
ActionTransitionUsagesProjectData.SemanticIds.DOCUMENT_ID,
895+
ActionTransitionUsagesProjectData.SemanticIds.PACKAGE_1_ID,
896+
ActionTransitionUsagesProjectData.SemanticIds.A0_ID,
897+
ActionTransitionUsagesProjectData.SemanticIds.S1_ID,
898+
ActionTransitionUsagesProjectData.SemanticIds.S2_ID);
899+
900+
var explorerRepresentationId = this.representationIdBuilder.buildExplorerRepresentationId(this.sysONExplorerTreeDescriptionId, expandedItemIds, defaultFilters);
901+
var input = new ExplorerEventInput(UUID.randomUUID(), ActionTransitionUsagesProjectData.EDITING_CONTEXT_ID, explorerRepresentationId);
902+
var flux = this.explorerEventSubscriptionRunner.run(input).flux();
903+
TestTransaction.flagForCommit();
904+
TestTransaction.end();
905+
906+
var treeId = new AtomicReference<String>();
907+
Consumer<Object> initialTreeContentConsumer = assertRefreshedTreeThat(tree -> {
908+
assertThat(tree).isNotNull();
909+
treeId.set(tree.getId());
910+
assertThat(tree.getChildren()).hasSize(2);
911+
var documentItem = tree.getChildren().get(0);
912+
assertThat(documentItem.getChildren()).hasSize(1);
913+
assertThat(documentItem.getLabel().toString()).isEqualTo("ActionTransitionUsage.sysml");
914+
var packageItem = documentItem.getChildren().get(0);
915+
assertThat(packageItem.getLabel().toString()).isEqualTo("Package 1");
916+
assertThat(packageItem.getChildren()).hasSize(3);
917+
var a0Item = packageItem.getChildren().get(0);
918+
assertThat(a0Item.getLabel().toString()).isEqualTo("a0");
919+
assertThat(a0Item.getChildren()).hasSize(7);
920+
var s1Item = a0Item.getChildren().get(5);
921+
assertThat(s1Item.getLabel().toString()).isEqualTo("S1");
922+
assertThat(s1Item.getChildren()).hasSize(3);
923+
var expr1Item = s1Item.getChildren().get(0);
924+
assertThat(expr1Item.getKind()).isEqualTo("siriusComponents://semantic?domain=sysml&entity=OperatorExpression");
925+
assertThat(expr1Item.getLabel().toString()).isEqualTo("attr1 < 1");
926+
927+
var s2Item = a0Item.getChildren().get(6);
928+
assertThat(s2Item.getLabel().toString()).isEqualTo("S2");
929+
assertThat(s2Item.getChildren()).hasSize(3);
930+
var expr2Item = s2Item.getChildren().get(0);
931+
assertThat(expr2Item.getKind()).isEqualTo("siriusComponents://semantic?domain=sysml&entity=OperatorExpression");
932+
assertThat(expr2Item.getLabel().toString()).isEqualTo("attr1 < 0");
933+
934+
});
935+
936+
StepVerifier.create(flux)
937+
.consumeNextWith(initialTreeContentConsumer)
938+
.thenCancel()
939+
.verify(Duration.ofSeconds(10_000));
940+
}
874941
}

backend/application/syson-application/src/test/java/org/eclipse/syson/application/data/ActionTransitionUsagesProjectData.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2025 Obeo.
2+
* Copyright (c) 2025, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -42,6 +42,8 @@ public static final class GraphicalIds {
4242
*/
4343
public static final class SemanticIds {
4444

45+
public static final String DOCUMENT_ID = "26a78eef-bfa1-4de0-9d0a-c1f86a1b97d5";
46+
4547
public static final String PACKAGE_1_ID = "2264f62c-b223-4b9b-ae41-96dc2ba0070e";
4648

4749
public static final String A0_ID = "82a2fa10-e736-4c3e-b27a-e94f76d7456d";

backend/metamodel/syson-sysml-metamodel/src/main/java/org/eclipse/syson/sysml/helper/EMFUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ public static <T extends EObject> List<T> getAncestors(Class<T> type, EObject ob
282282
*/
283283
public static <T extends EObject> Optional<T> getFirstAncestor(Class<T> type, EObject object, Predicate<EObject> ancestorPredicate) {
284284
var current = object;
285-
List<T> results = new ArrayList<>();
286285
while (current != null) {
287286
if (type.isInstance(current) && (ancestorPredicate == null || ancestorPredicate.test(current))) {
288287
return Optional.of((T) current);

backend/services/syson-tree-services/src/main/java/org/eclipse/syson/tree/explorer/services/SysONDefaultExplorerServices.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@
3838
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.RepresentationMetadata;
3939
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.services.api.IRepresentationMetadataSearchService;
4040
import org.eclipse.syson.sysml.Element;
41+
import org.eclipse.syson.sysml.Expression;
4142
import org.eclipse.syson.sysml.Type;
43+
import org.eclipse.syson.sysml.Usage;
4244
import org.eclipse.syson.sysml.ViewUsage;
45+
import org.eclipse.syson.sysml.textual.SysMLElementSerializer;
46+
import org.eclipse.syson.sysml.textual.SysMLSerializingOptions;
47+
import org.eclipse.syson.sysml.textual.utils.FileNameDeresolver;
4348
import org.eclipse.syson.sysml.util.ElementUtil;
4449
import org.eclipse.syson.tree.explorer.fragments.KerMLStandardLibraryDirectory;
4550
import org.eclipse.syson.tree.explorer.fragments.LibrariesDirectory;
@@ -148,6 +153,8 @@ public String getLabel(Object self) {
148153
String label = "";
149154
if (self instanceof ISysONExplorerFragment fragment) {
150155
label = fragment.getLabel();
156+
} else if (self instanceof Expression expression && !(self instanceof Usage)) {
157+
label = this.getValueExpressionTextualRepresentation(expression);
151158
} else if (self instanceof Type type) {
152159
String name = type.getName();
153160
if (name != null) {
@@ -159,6 +166,25 @@ public String getLabel(Object self) {
159166
return label;
160167
}
161168

169+
private String getValueExpressionTextualRepresentation(Expression value) {
170+
String result = "";
171+
if (value != null) {
172+
SysMLSerializingOptions options = new SysMLSerializingOptions.Builder()
173+
.lineSeparator("\n")
174+
.nameDeresolver(new FileNameDeresolver())
175+
.indentation("\t")
176+
.needEscapeCharacter(false)
177+
.build();
178+
String textualFormat = new SysMLElementSerializer(options, s -> {
179+
// Do nothing for now
180+
}).doSwitch(value);
181+
if (textualFormat != null) {
182+
result = textualFormat;
183+
}
184+
}
185+
return result;
186+
}
187+
162188
private String getFallbackLabel(Object self) {
163189
StyledString styledLabel = this.labelService.getStyledLabel(self);
164190
if (styledLabel != null) {
76.6 KB
Loading

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
** Add tools to create timeslices and snapshots, available on `OccurrenceUsage`, `ItemUsage`, and `PartUsage` graphical nodes.
2626
These tools leverage a selection dialog to either create a specific timeslice/snapshot graphical node or, if no selection is made, default to a timeslice/snapshot `OccurrenceUsage` graphical node.
2727

28+
* In the _Explorer_ view:
29+
30+
** `Expression` elements now display their full textual representation:
31+
32+
image::explorer-expression-text.png[Expression textual representation]
33+
2834
== Technical details
2935

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

0 commit comments

Comments
 (0)