Description
A named element represents elements that may have a name. The name is used for identification of the named element
within the namespace in which it is defined. A named element also has a qualified name that allows it to be unambiguously identified within a hierarchy of nested namespaces. NamedElement is an abstract metaclass.
Attributes
name: String [0..1]
| The name of the NamedElement.
|
/ qualifiedName: String [0..1] | A name which allows the NamedElement to be identified within a hierarchy of nested
Namespaces. It is constructed from the names of the containing namespaces starting at the root of the hierarchy and ending with the name of the NamedElement itself. This is a derived attribute.
|
If there is no name, or one of the containing namespaces has no name, there is no qualified name.
(self.name->isEmpty() or self.allNamespaces()->select(ns | ns.name->isEmpty())->notEmpty())
implies self.qualifiedName->isEmpty()
When there is a name, and all of the containing namespaces have a name, the qualified name is constructed from the
names of the containing namespaces.
(self.name->notEmpty() and self.allNamespaces()->select(ns | ns.name->isEmpty())->isEmpty()) implies
self.qualifiedName = self.allNamespaces()->iterate( ns : Namespace; result: String = self.name |
ns.name->union(self.separator())->union(result))
The query allNamespaces() gives the sequence of namespaces in which the NamedElement is nested, working outwards.
NamedElement::allNamespaces(): Sequence(Namespace);
allNamespaces =
if self.namespace->isEmpty()
then Sequence{}
else self.namespace.allNamespaces()->prepend(self.namespace)
endif
The query isDistinguishableFrom() determines whether two NamedElements may logically co-exist within a Namespace.
By default, two named elements are distinguishable if (a) they have unrelated types or (b) they have related types but different names.
NamedElement::isDistinguishableFrom(n:NamedElement, ns: Namespace): Boolean;
isDistinguishable =
if self.oclIsKindOf(n.oclType) or n.oclIsKindOf(self.oclType)
then ns.getNamesOfMember(self)->intersection(ns.getNamesOfMember(n))->isEmpty()
else true
endif
The query separator() gives the string that is used to separate names when constructing a qualified name.
NamedElement::separator(): String;
separator = `::'
The name attribute is used for identification of the named element within namespaces where its name is accessible. Note that the attribute has a multiplicity of [ 0..1 ] which provides for the possibility of the absence of a name (which is different from the empty name).