1.1.3. Namespace Import

[Tip]Description

A namespace import is part of a VTCL file; it makes typing of model elements easier since the elements of the model subtree determined by the namespace can be referenced relative to the namespace when using them as types.

[Important]Syntax

NamespaceImportsAST ::= $empty 
                      | NamespaceImportsAST NamespaceImportAST
NamespaceImportAST ::= import QualifiedTypeNameAST ;
			

Namespaces are identified by qualified model element names. Import instructions must be placed at the beginning of the file.

[Note]Semantics

The result of importing a namespace to a file is that all model elements defined in or below the model element identified by the namespace can be referenced inside of all the machines defined in the given file with their local names or qualified names local to the given namespace.

Namespace imports can result name clashes:

  • between a locally defined and an imported name, or

  • between two imported names.

In the first case local (short) name always refers to the locally defined element (entity, relation, function, variable, rule etc.), whereas the imported element can be referred by its fully qualified name. In addition a compile-time warning is issued when a namespace is imported that has a conflicting element with a local name.

When two different imported namespace contains elements with the same name then these elements can be referred by their fully qualified names. A compile-time error occurs when such an element is referred by its local name.

A name clash can occur between a locally defined element and an element in the root namespace; in this case root element can be reached, but the element in the imported name space not. In this case a warning is issued by the compiler.

[Caution]Constraints

Only an entity identifies a namespace in the model space, i.e. the qualified model element name of the import cannot be the name of a relation.

Example 2.1. Sample namespace import

// All elements below the entity uml2.metamodel will become available as types 			
import uml2.metamodel;

// Now the type uml2.metamodel.Classifier of C can be shortened 
pattern myPattern(C) = {
 Classifier(C);
}			
			


See also:  Entity, Relation