<html><head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>1.1.3. Namespace Import</title><link href="style.css" rel="stylesheet" type="text/css"><meta content="DocBook XSL Stylesheets V1.72.0" name="generator"><link rel="start" href="index.html" title="The VIATRA2 Model Transformation Framework"><link rel="up" href="sec_VtclFile.html" title="1.1. VTCL Files"><link rel="prev" href="def_NamespaceDefinition.html" title="1.1.2. Namespace Definition"><link rel="next" href="sec_MachineDefinition.html" title="1.2. Machine Definition"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><th align="center" colspan="3">1.1.3. Namespace Import</th></tr><tr><td align="left" width="20%"><a accesskey="p" href="def_NamespaceDefinition.html">Prev</a> </td><th align="center" width="60%">1.1. VTCL Files</th><td align="right" width="20%"> <a accesskey="n" href="sec_MachineDefinition.html">Next</a></td></tr></table><hr></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="def_NamespaceImport"></a>1.1.3. Namespace Import</h4></div></div></div><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip: Description"><tr><td valign="top" align="center" rowspan="2" width="25"><img alt="[Tip]" src="images/tip.png"></td><th align="left"><a name="def_NamespaceImport_Description"></a>Description</th></tr><tr><td valign="top" align="left"><p> | |
A <span class="strong"><strong>namespace import</strong></span><a name="N10161" class="indexterm"></a> | |
is part of a <a href="def_VtclFile.html" title="1.1.1. VTCL file">VTCL file</a>; 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. | |
</p></td></tr></table></div><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Important: Syntax"><tr><td valign="top" align="center" rowspan="2" width="25"><img alt="[Important]" src="images/important.png"></td><th align="left"><a name="def_NamespaceImport_Syntax"></a>Syntax</th></tr><tr><td valign="top" align="left"><p> | |
<pre class="programlisting"> | |
NamespaceImportsAST ::= $empty | |
| NamespaceImportsAST NamespaceImportAST | |
NamespaceImportAST ::= <span class="token">import</span> <a href="def_ModelElementName.html" title="5.7.1. Model Element Name">QualifiedTypeNameAST</a> <span class="token">;</span> | |
</pre> | |
</p><p> | |
Namespaces are identified by <a href="def_ModelElementName.html" title="5.7.1. Model Element Name">qualified model element names</a>. | |
Import instructions must be placed at the beginning of the file. | |
</p></td></tr></table></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note: Semantics"><tr><td valign="top" align="center" rowspan="2" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left"><a name="def_NamespaceImport_Semantics"></a>Semantics</th></tr><tr><td valign="top" align="left"><p> | |
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. | |
</p><p> | |
Namespace imports can result name clashes: | |
<div class="itemizedlist"><ul type="disc"><li><p>between a locally defined and an imported name, or</p></li><li><p>between two imported names.</p></li></ul></div> | |
</p><p> | |
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. | |
</p><p> | |
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. | |
</p><p> | |
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. | |
</p></td></tr></table></div><div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Caution: Constraints"><tr><td valign="top" align="center" rowspan="2" width="25"><img alt="[Caution]" src="images/caution.png"></td><th align="left"><a name="def_NamespaceImport_Constraints"></a>Constraints</th></tr><tr><td valign="top" align="left"><p> | |
Only an entity identifies a namespace in the model space, i.e. the | |
<a href="def_ModelElementName.html" title="5.7.1. Model Element Name">qualified model element name</a> of the import cannot be the name of a relation. | |
</p></td></tr></table></div><div class="example"><a name="def_NamespaceImport_Example"></a><p class="title"><b>Example 2.1. Sample namespace import</b></p><div class="example-contents"><p> | |
<pre class="programlisting"> | |
// 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); | |
} | |
</pre> | |
</p></div><p></p></div><br class="example-break"><div class="highlights"><a name="def_NamespaceImport_SeeAlso"></a><p><b>See also: </b> | |
<a href="def_Entity.html" title="2.2.1. Entity">Entity</a>, <a href="def_Relation.html" title="2.2.2. Relation">Relation</a> | |
</p></div></div><div class="navfooter"><hr><table summary="Navigation footer" width="100%"><tr><td align="left" width="40%"><a accesskey="p" href="def_NamespaceDefinition.html">Prev</a> </td><td align="center" width="20%"><a accesskey="u" href="sec_VtclFile.html">Up</a></td><td align="right" width="40%"> <a accesskey="n" href="sec_MachineDefinition.html">Next</a></td></tr><tr><td valign="top" align="left" width="40%">1.1.2. Namespace Definition </td><td align="center" width="20%"><a accesskey="h" href="index.html">Home</a></td><td valign="top" align="right" width="40%"> 1.2. Machine Definition</td></tr></table></div></body></html> |