Skip to content

Commit f27f22e

Browse files
committed
ST6RI-829 Implemented the path() operation Element and subclasses.
- Also added a JUnit test for paths.
1 parent 2c9307b commit f27f22e

5 files changed

Lines changed: 219 additions & 3 deletions

File tree

org.omg.sysml.interactive.tests/.launch/Derived Property Test.launch renamed to org.omg.sysml.interactive.tests/.launch/Derived Property and Operation Test.launch

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
33
<stringAttribute key="bad_container_name" value="/org.omg.sysml.interactive.tests/.lau"/>
4+
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
45
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
5-
<listEntry value="/org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/DerivedPropertyTest.java"/>
6+
<listEntry value="/org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/DerivedPropertyAndOperationTest.java"/>
67
</listAttribute>
78
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
89
<listEntry value="1"/>
@@ -12,10 +13,11 @@
1213
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
1314
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
1415
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
16+
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
1517
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
1618
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
1719
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
18-
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.omg.sysml.interactive.tests.DerivedPropertyTest"/>
20+
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.omg.sysml.interactive.tests.DerivedPropertyAndOperationTest"/>
1921
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.omg.sysml.interactive.tests"/>
2022
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
2123
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -DlibraryPath=${workspace_loc:/SysML-v2-Pilot-Implementation/sysml.library}"/>

org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/DerivedPropertyTest.java renamed to org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/DerivedPropertyAndOperationTest.java

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@
3737
import org.omg.sysml.lang.sysml.Expression;
3838
import org.omg.sysml.lang.sysml.ItemUsage;
3939
import org.omg.sysml.lang.sysml.Namespace;
40+
import org.omg.sysml.lang.sysml.Relationship;
4041
import org.omg.sysml.lang.sysml.TriggerInvocationExpression;
4142
import org.omg.sysml.lang.sysml.Usage;
4243
import org.omg.sysml.lang.sysml.ViewUsage;
4344

44-
public class DerivedPropertyTest extends SysMLInteractiveTest {
45+
public class DerivedPropertyAndOperationTest extends SysMLInteractiveTest {
4546

4647
@Test
4748
public void testOwnedUsage() throws Exception {
@@ -86,5 +87,67 @@ public void testViewExpose() throws Exception {
8687
List<Element> exposed = view.getExposedElement();
8788
assertEquals(1, exposed.size());
8889
}
90+
91+
public final String pathTest =
92+
"// Path of package: TopLevel\n"
93+
+ "// Path of owning membership: TopLevel/owningMembership\n"
94+
+ "package TopLevel {\n"
95+
+ "\n"
96+
+ " // Path of classifier: TopLevel::A\n"
97+
+ " // Path of owning membership: TopLevel::A/owningMembership\n"
98+
+ " part def A;\n"
99+
+ "\n"
100+
+ " // Path of classifier: TopLevel::B\n"
101+
+ " // Path of owning membership: TopLevel::B/owningMembership\n"
102+
+ " // Path of owned subclassification: TopLevel::B/1\n"
103+
+ " part def B specializes A {\n"
104+
+ " // Path of owning membership: TopLevel::B/2\n"
105+
+ " // Path of feature: TopLevel::B/2/1\n"
106+
+ " ref;\n"
107+
+ " }\n"
108+
+ "\n"
109+
+ " // Path of owning membership: TopLevel/3\n"
110+
+ " // Path of classifier: TopLevel/3/1\n"
111+
+ " part def {\n"
112+
+ " // Path of owning membership: TopLevel/3/1/1\n"
113+
+ " // Path of feature: TopLevel/3/1/1/1\n"
114+
+ " ref f;\n"
115+
+ " }\n"
116+
+ "}";
117+
118+
@Test
119+
public void testPathOperation() throws Exception {
120+
SysMLInteractive instance = getSysMLInteractiveInstance();
121+
List<Element> elements = process(instance, pathTest);
122+
123+
Namespace TopLevel = (Namespace)elements.get(0);
124+
assertEquals("TopLevel", TopLevel.path());
125+
assertEquals("TopLevel/owningMembership", TopLevel.getOwningMembership().path());
126+
127+
Namespace A = (Namespace)TopLevel.getOwnedMember().get(0);
128+
assertEquals("TopLevel::A", A.path());
129+
assertEquals("TopLevel::A/owningMembership", A.getOwningMembership().path());
130+
131+
Namespace B = (Namespace)TopLevel.getOwnedMember().get(1);
132+
assertEquals("TopLevel::B", B.path());
133+
assertEquals("TopLevel::B/owningMembership", B.getOwningMembership().path());
134+
135+
Relationship B_1 = B.getOwnedRelationship().get(0);
136+
assertEquals("TopLevel::B/1", B_1.path());
137+
138+
Relationship B_2 = B.getOwnedRelationship().get(1);
139+
assertEquals("TopLevel::B/2", B_2.path());
140+
assertEquals("TopLevel::B/2/1", B_2.getOwnedRelatedElement().get(0).path());
141+
142+
Relationship TopLevel_3 = TopLevel.getOwnedRelationship().get(2);
143+
assertEquals("TopLevel/3", TopLevel_3.path());
144+
145+
Element TopLevel_3_1 = TopLevel_3.getOwnedRelatedElement().get(0);
146+
assertEquals("TopLevel/3/1", TopLevel_3_1.path());
147+
148+
Relationship TopLevel_3_1_1 = TopLevel_3_1.getOwnedRelationship().get(0);
149+
assertEquals("TopLevel/3/1/1", TopLevel_3_1_1.path());
150+
assertEquals("TopLevel/3/1/1/1", TopLevel_3_1_1.getOwnedRelatedElement().get(0).path());
151+
}
89152

90153
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2025 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
22+
package org.omg.sysml.delegate.invocation;
23+
24+
import java.lang.reflect.InvocationTargetException;
25+
26+
import org.eclipse.emf.common.util.EList;
27+
import org.eclipse.emf.ecore.EOperation;
28+
import org.eclipse.emf.ecore.InternalEObject;
29+
import org.eclipse.emf.ecore.util.BasicInvocationDelegate;
30+
import org.omg.sysml.lang.sysml.Element;
31+
import org.omg.sysml.lang.sysml.Relationship;
32+
33+
public class Element_path_InvocationDelegate extends BasicInvocationDelegate {
34+
35+
public Element_path_InvocationDelegate(EOperation operation) {
36+
super(operation);
37+
}
38+
39+
@Override
40+
public String dynamicInvoke(InternalEObject target, EList<?> arguments) throws InvocationTargetException {
41+
Element self = (Element) target;
42+
String qualifiedName = self.getQualifiedName();
43+
Relationship owningRelationship = self.getOwningRelationship();
44+
return qualifiedName != null? qualifiedName:
45+
owningRelationship != null?
46+
owningRelationship.path() + "/" +
47+
(owningRelationship.getOwnedRelatedElement().indexOf(self) + 1):
48+
"";
49+
}
50+
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2025 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
22+
package org.omg.sysml.delegate.invocation;
23+
24+
import java.lang.reflect.InvocationTargetException;
25+
26+
import org.eclipse.emf.common.util.EList;
27+
import org.eclipse.emf.ecore.EOperation;
28+
import org.eclipse.emf.ecore.InternalEObject;
29+
import org.omg.sysml.lang.sysml.Element;
30+
import org.omg.sysml.lang.sysml.OwningMembership;
31+
32+
public class OwningMembership_path_InvocationDelegate extends Relationship_path_InvocationDelegate {
33+
34+
public OwningMembership_path_InvocationDelegate(EOperation operation) {
35+
super(operation);
36+
}
37+
38+
@Override
39+
public String dynamicInvoke(InternalEObject target, EList<?> arguments) throws InvocationTargetException {
40+
OwningMembership self = (OwningMembership) target;
41+
Element ownedElement = self.getOwnedMemberElement();
42+
if (ownedElement != null) {
43+
String qualifiedName = ownedElement.getQualifiedName();
44+
if (qualifiedName != null) {
45+
return qualifiedName + "/owningMembership";
46+
}
47+
}
48+
return super.dynamicInvoke(target, arguments);
49+
}
50+
51+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2025 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
22+
package org.omg.sysml.delegate.invocation;
23+
24+
import java.lang.reflect.InvocationTargetException;
25+
26+
import org.eclipse.emf.common.util.EList;
27+
import org.eclipse.emf.ecore.EOperation;
28+
import org.eclipse.emf.ecore.InternalEObject;
29+
import org.omg.sysml.lang.sysml.Element;
30+
import org.omg.sysml.lang.sysml.Relationship;
31+
32+
public class Relationship_path_InvocationDelegate extends Element_path_InvocationDelegate {
33+
34+
public Relationship_path_InvocationDelegate(EOperation operation) {
35+
super(operation);
36+
}
37+
38+
@Override
39+
public String dynamicInvoke(InternalEObject target, EList<?> arguments) throws InvocationTargetException {
40+
Relationship self = (Relationship) target;
41+
Relationship owningRelationship = self.getOwningRelationship();
42+
Element owningRelatedElement = self.getOwningRelatedElement();
43+
return owningRelationship == null && owningRelatedElement != null?
44+
owningRelatedElement.path() + "/" +
45+
(owningRelatedElement.getOwnedRelationship().indexOf(self) + 1):
46+
super.dynamicInvoke(target, arguments);
47+
}
48+
49+
}

0 commit comments

Comments
 (0)