Skip to content

Commit 7876769

Browse files
committed
ST6RI-830 Added resolution for global qualification
1 parent c15a0d7 commit 7876769

3 files changed

Lines changed: 73 additions & 18 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
* Contributors:
21+
* Laszlo Gati, MDS
22+
*/
23+
package org.omg.kerml.xtext.naming;
24+
25+
import org.eclipse.xtext.naming.QualifiedName;
26+
27+
public class QualifiedNamesUtil {
28+
29+
public static final String GLOBAL_CLASSIFIER_SYMBOL = "$";
30+
31+
public static boolean isGlobalNameQualification(QualifiedName qualifiedName) {
32+
return qualifiedName != null &&
33+
qualifiedName.getSegmentCount() > 0 &&
34+
GLOBAL_CLASSIFIER_SYMBOL.equals(qualifiedName.getFirstSegment());
35+
}
36+
}

org.omg.kerml.xtext/src/org/omg/kerml/xtext/scoping/KerMLGlobalScope.xtend

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import org.eclipse.xtext.scoping.impl.AbstractScope
3838
import org.omg.sysml.lang.sysml.Namespace
3939
import org.omg.sysml.lang.sysml.SysMLPackage
4040
import org.omg.sysml.lang.sysml.Element
41+
import org.omg.kerml.xtext.naming.QualifiedNamesUtil
4142

4243
class KerMLGlobalScope extends AbstractScope {
4344

@@ -78,25 +79,38 @@ class KerMLGlobalScope extends AbstractScope {
7879
}
7980

8081
override getSingleElement(QualifiedName name) {
82+
val isGlobalQualification = QualifiedNamesUtil.isGlobalNameQualification(name)
83+
val qualifiedName = isGlobalQualification? name.skipFirst(1) : name
84+
8185
var IEObjectDescription result = null
82-
if (name.segmentCount > 0) {
83-
val rootName = QualifiedName.create(name.firstSegment)
84-
val root = outer.getSingleElement(rootName)
85-
if (root !== null) {
86-
if (name.segmentCount == 1) {
87-
if (referenceType == SysMLPackage.eINSTANCE.membership) {
88-
var eObject = EcoreUtil.resolve(root.EObjectOrProxy, resource)
89-
result = if (eObject.eIsProxy) null
90-
else EObjectDescription.create(name, (eObject as Element).owningMembership)
91-
} else if (referenceType.isInstance(root.EObjectOrProxy)) {
92-
result = root;
86+
87+
if (qualifiedName.segmentCount > 0) {
88+
if (isGlobalQualification) {
89+
//search the context resource first
90+
val rootNS = resource.contents.head as Namespace
91+
result = scopeFor(rootNS).getSingleElement(qualifiedName)
92+
}
93+
94+
if (result === null) {
95+
val rootName = QualifiedName.create(qualifiedName.firstSegment)
96+
val root = outer.getSingleElement(rootName)
97+
if (root !== null) {
98+
if (qualifiedName.segmentCount == 1) {
99+
if (referenceType == SysMLPackage.eINSTANCE.membership) {
100+
var eObject = EcoreUtil.resolve(root.EObjectOrProxy, resource)
101+
result = if (eObject.eIsProxy) null
102+
else EObjectDescription.create(qualifiedName, (eObject as Element).owningMembership)
103+
} else if (referenceType.isInstance(root.EObjectOrProxy)) {
104+
result = root;
105+
}
106+
} else if (root.EObjectOrProxy instanceof Namespace) {
107+
result = scopeFor(EcoreUtil.resolve(root.EObjectOrProxy, resource) as Namespace).
108+
getSingleElement(qualifiedName.skipFirst(1)).addQualification(qualifiedName.firstSegment)
93109
}
94-
} else if (root.EObjectOrProxy instanceof Namespace) {
95-
result = scopeFor(EcoreUtil.resolve(root.EObjectOrProxy, resource) as Namespace).
96-
getSingleElement(name.skipFirst(1)).addQualification(name.firstSegment)
97110
}
98111
}
99112
}
113+
100114
return result.filter
101115
}
102116

org.omg.kerml.xtext/src/org/omg/kerml/xtext/scoping/KerMLScope.xtend

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import com.google.inject.Inject
5656
import org.eclipse.xtext.naming.IQualifiedNameConverter
5757
import org.eclipse.emf.ecore.util.EcoreUtil
5858
import org.omg.sysml.util.NamespaceUtil
59+
import org.omg.kerml.xtext.naming.QualifiedNamesUtil
5960

6061
class KerMLScope extends AbstractScope implements ISysMLScope {
6162

@@ -167,10 +168,14 @@ class KerMLScope extends AbstractScope implements ISysMLScope {
167168
}
168169

169170
override getSingleElement(QualifiedName name) {
170-
val result = resolveInScope(name, true);
171-
if (!result.isEmpty) result.get(0)
172-
else if (parent !== null && !isShadowing) parent.getSingleElement(name)
173-
else null
171+
if (QualifiedNamesUtil.isGlobalNameQualification(name)){
172+
parent.getSingleElement(name)
173+
} else {
174+
val result = resolveInScope(name, true);
175+
if (!result.isEmpty) result.get(0)
176+
else if (parent !== null && !isShadowing) parent.getSingleElement(name)
177+
else null
178+
}
174179
}
175180

176181
override getLocalElementsByName(QualifiedName name) {

0 commit comments

Comments
 (0)