Skip to content

Commit e83c8e7

Browse files
adaussyAxelRICHARD
authored andcommitted
[1083] Fix resolution of "unescape" name
Bug: #1083 Signed-off-by: Arthur Daussy <arthur.daussy@obeo.fr>
1 parent 2b03e63 commit e83c8e7

File tree

5 files changed

+49
-19
lines changed

5 files changed

+49
-19
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
=== Bug fixes
1919

2020
- https://github.com/eclipse-syson/syson/issues/870[#870] Fix an issue while computing the name of `VariantMembership`.
21+
- https://github.com/eclipse-syson/syson/issues/1083[#1083] Fix an issue where resolving against "unrestricted" name did not work
2122

2223
=== Improvements
2324

backend/application/syson-application/src/test/java/org/eclipse/syson/application/export/ImportExportTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,19 @@ public void checkSuccessionAsUsageExplicitSourceTest() throws IOException {
178178
this.checker.check(input, input);
179179
}
180180

181+
@Test
182+
@DisplayName("Given a model with unrestricted names, when importing and exporting the model, then the exported text file should be the same as the imported one.")
183+
public void checkUnrestrictedNamesResolution() throws IOException {
184+
var input = """
185+
package p1 {
186+
package 'p 2' {
187+
action def 'A 1';
188+
}
189+
action 'a 2' : 'p 2'::'A 1';
190+
}""";
191+
192+
this.checker.check(input, input);
193+
}
181194
/**
182195
* Test import/export on test file UseCaseTest.sysml. The content of UseCaseTest.sysml that have been copied below
183196
* is under LGPL-3.0-only license. The LGPL-3.0-only license is accessible at the root of this repository, in the

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024 Obeo.
2+
* Copyright (c) 2024, 2025 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
@@ -63,7 +63,10 @@ public static String escapeString(String str) {
6363
* @return
6464
*/
6565
public static String unescapeString(String str) {
66-
return StringEscapeUtils.unescapeJava(str);
66+
if (str != null && str.length() > 1 && str.startsWith("'") && str.endsWith("'")) {
67+
return str.substring(1, str.length() - 1);
68+
}
69+
return str;
6770
}
6871

6972
/**

backend/metamodel/syson-sysml-metamodel/src/test/java/org/eclipse/syson/sysml/impl/NamespaceImplTest.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024 Obeo.
2+
* Copyright (c) 2024, 2025 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
@@ -45,11 +45,11 @@ public class NamespaceImplTest {
4545
* package p1 {
4646
* part def def1;
4747
* package p1x1 {
48-
* part def def1x1;
48+
* part def 'def 1x1';
4949
* package p1x1x1 {
50-
* part def def1x1x1 :> def4;
50+
* part def def1x1x1 :> 'def 4';
5151
* }
52-
* private part def privatedef1x1 :> p4::def4;
52+
* private part def privatedef1x1 :> 'p 4'::'def 4';
5353
* }
5454
*
5555
* package p1x2 {
@@ -73,8 +73,8 @@ public class NamespaceImplTest {
7373
* private part def privateDef3
7474
* }
7575
*
76-
* package p4 {
77-
* part def def4;
76+
* package 'p 4' {
77+
* part def 'def 4';
7878
* }
7979
* }
8080
* </pre>
@@ -149,7 +149,7 @@ private void build() {
149149
this.def1 = this.builder.createInWithName(PartDefinition.class, this.p1, "Def1");
150150

151151
this.p1x1 = this.builder.createInWithName(Package.class, this.p1, "p1x1");
152-
this.def1x1 = this.builder.createInWithName(PartDefinition.class, this.p1x1, "def1x1");
152+
this.def1x1 = this.builder.createInWithName(PartDefinition.class, this.p1x1, "def 1x1");
153153
this.privatedef1x1 = this.builder.createInWithName(PartDefinition.class, this.p1x1, "privatedef1x1");
154154
this.privatedef1x1.getOwningMembership().setVisibility(VisibilityKind.PRIVATE);
155155

@@ -176,8 +176,8 @@ private void build() {
176176

177177

178178
this.root2 = this.builder.createWithName(Namespace.class, null);
179-
this.p4 = this.builder.createInWithName(Package.class, this.root2, "p9");
180-
this.def4 = this.builder.createInWithName(PartDefinition.class, this.p4, "def9");
179+
this.p4 = this.builder.createInWithName(Package.class, this.root2, "p 4");
180+
this.def4 = this.builder.createInWithName(PartDefinition.class, this.p4, "def 4");
181181

182182
this.builder.addSubclassification(this.def1x1x1, this.def4);
183183
this.builder.createIn(NamespaceImport.class, this.p1x1x1).setImportedNamespace(this.def4);
@@ -470,7 +470,7 @@ public void resolveLocalSimpleTest() {
470470
var testModel = new TestModel();
471471

472472
/* package p1x1 {
473-
* part def def1x1;
473+
* part def 'def 1x1';
474474
* package p1x1x1 {
475475
* part def def1x1x1;
476476
* }
@@ -500,13 +500,14 @@ public void resolveLocalSimpleTest() {
500500
assertEquals(testModel.p1, testModel.p1.resolveLocal(testModel.p1.getName()).getMemberElement());
501501
}
502502

503+
503504
@DisplayName("Test resolveVisible")
504505
@Test
505506
public void resolveVisibleTest() {
506507
var testModel = new TestModel();
507508

508509
/* package p1x1 {
509-
* part def def1x1;
510+
* part def 'def 1x1';
510511
* package p1x1x1 {
511512
* part def def1x1x1;
512513
* }
@@ -531,7 +532,7 @@ public void resolveTest() {
531532
* package p1 {
532533
* part def def1;
533534
* package p1x1 {
534-
* part def def1x1;
535+
* part def 'def 1x1';
535536
* package p1x1x1 {
536537
* part def def1x1x1;
537538
* }
@@ -568,16 +569,16 @@ public void resolveGlobalTest() {
568569

569570
/*
570571
* package p1x1 {
571-
* part def def1x1;
572+
* part def 'def 1x1';
572573
* package p1x1x1 {
573574
* import p4::*;
574-
* part def def1x1x1 :> def4;
575+
* part def def1x1x1 :> 'def 4';
575576
* }
576-
* private part def privatedef1x1 :> p4::def4;
577+
* private part def privatedef1x1 :> 'p 4'::'def 4';
577578
* }
578579
*
579-
* package p4 {
580-
* part def def4;
580+
* package 'p 4' {
581+
* part def 'def 4';
581582
* }
582583
*/
583584

@@ -601,7 +602,9 @@ public void unqualifiedNameOfTest() {
601602

602603
assertEquals("test 1", testModel.p1.unqualifiedNameOf("test 1"));
603604
assertEquals("test 2", testModel.p1.unqualifiedNameOf("test 1::test 2"));
605+
assertEquals("test 2", testModel.p1.unqualifiedNameOf("'test 1'::test 2"));
604606
assertEquals("test 3", testModel.p1.unqualifiedNameOf("test 1::test 2::test 3"));
607+
assertEquals("test 3", testModel.p1.unqualifiedNameOf("test 1::test 2::'test 3'"));
605608

606609
}
607610

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ In such cases, delete the `SuccessionUsage` graphical node and recreate it graph
1010

1111
- Fix an issue while computing the name of `VariantMembership`.
1212
This has an impact on name resolution against `Element` contained in `VariantMembership` during the textual import process (e.g. for `EnumerationUsage` literals in `EnumerationDefinition`).
13+
- Fix resolution of "unrestricted" names. For example, while importing the following model, the reference to _'p 2'::'A 1'_ is now properly resolved.
14+
15+
```
16+
package p1 {
17+
package 'p 2' {
18+
action def 'A 1';
19+
}
20+
action 'a 2' : 'p 2'::'A 1';
21+
}
22+
```
1323

1424
== New features
1525

0 commit comments

Comments
 (0)