ElementImport

An element import identifies an element in another package, and allows the element to be referenced using its name
without a qualifier.

Description
An element import is defined as a directed relationship between an importing namespace and a packageable element. The
name of the packageable element or its alias is to be added to the namespace of the importing namespace. It is also
possible to control whether the imported element can be further imported.

Attributes

visibility: VisibilityKind Specifies the visibility of the imported PackageableElement within the importing Package.
The default visibility is the same as that of the imported element. If the imported element
does not have a visibility, it is possible to add visibility to the element import.
alias: String [0..1] Specifies the name that should be added to the namespace of the importing Package in lieu
of the name of the imported PackagableElement. The aliased name must not clash with
any other member name in the importing Package. By default, no alias is used.

Associations

importedElement: PackageableElement [1]Specifies the PackageableElement whose name is to be added to a Namespace.
Subsets DirectedRelationship::target.
importingNamespace: Namespace [1]Specifies the Namespace that imports a PackageableElement from another Package.
Subsets DirectedRelationship::source and Element::owner.

Constraints

  1. The visibility of an ElementImport is either public or private.

    self.visibility = #public or self.visibility = #private

  2. An importedElement has either public visibility or no visibility at all.

    self.importedElement.visibility.notEmpty() implies self.importedElement.visibility = #public

Additional Operations

  1. The query getName() returns the name under which the imported PackageableElement will be known in the importing
    namespace.
    ElementImport::getName(): String;
    getName =
    if self.alias->notEmpty() then
    self.alias
    else
    self.importedElement.name
    endif

Semantics
An element import adds the name of a packageable element from a package to the importing namespace. It works by
reference, which means that it is not possible to add features to the element import itself, but it is possible to modify the
referenced element in the namespace from which it was imported. An element import is used to selectively import
individual elements without relying on a package import.

In case of a nameclash with an outer name (an element that is defined in an enclosing namespace is available using its
unqualified name in enclosed namespaces) in the importing namespace, the outer name is hidden by an ele-ment import,
and the unqualified name refers to the imported element. The outer name can be accessed using its qual-ified name.

If more than one element with the same name would be imported to a namespace as a consequence of element imports or
package imports, the names of the imported elements must be qualified in order to be used and the elements are not added
to the importing namespace. If the name of an imported element is the same as the name of an element owned by the
importing namespace, the name of the imported element must be qualified in order to be used and is not added to the
importing namespace.

An imported element can be further imported by other namespaces using either element or member imports.

The visibility of the ElementImport may be either the same or more restricted than that of the imported element.

Notation
An element import is shown using a dashed arrow with an open arrowhead from the importing namespace to the imported
element. The keyword «import» is shown near the dashed arrow if the visibility is public, otherwise the key-word
«access» is shown.

If an element import has an alias, this is used in lieu of the name of the imported element. The aliased name may be
shown after or below the keyword «import».

Presentation Options
If the imported element is a package, the keyword may optionally be preceded by element, i.e., «element import».

As an alternative to the dashed arrow, it is possible to show an element import by having a text that uniquely identifies
the imported element within curly brackets either below or after the name of the namespace. The textual syntax is then:

{element import <qualifiedName>} or {element access <qualifiedName>}

Optionally, the aliased name may be show as well:

{element import <qualifiedName> as <alias>} or {element access <qualifiedName> as <alias>}

Examples
The element import that isshown in Figure 90 allows elements in the package Program to refer to the type Time in Types
without qualification. However, they still need to refer explicitly to Types::Integer, since this element is not imported.

In Figure 91, the element import is combined with aliasing, meaning that the type Types::Real will be referred to as
Double in the package Shapes.