@@ -38,6 +38,7 @@ import org.eclipse.xtext.scoping.impl.AbstractScope
3838import org.omg.sysml.lang.sysml.Namespace
3939import org.omg.sysml.lang.sysml.SysMLPackage
4040import org.omg.sysml.lang.sysml.Element
41+ import org.omg.kerml.xtext.naming.QualifiedNamesUtil
4142
4243class 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
0 commit comments