blob: 350a16a8eea1e81d91fcbf9e7c56addbb1abe1e3 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>CopyTo xref</title>
<link type="text/css" rel="stylesheet" href="../../../../../../../stylesheet.css" />
</head>
<body>
<div id="overview"><a href="../../../../../../../../apidocs/org/eclipse/papyrus/designer/transformation/core/transformations/CopyTo.html">View Javadoc</a></div><pre>
<a class="jxr_linenumber" name="L1" href="#L1">1</a> <em class="jxr_javadoccomment">/**</em>
<a class="jxr_linenumber" name="L2" href="#L2">2</a> <em class="jxr_javadoccomment"> * All rights reserved. This program and the accompanying materials</em>
<a class="jxr_linenumber" name="L3" href="#L3">3</a> <em class="jxr_javadoccomment"> * are made available under the terms of the Eclipse Public License v1.0</em>
<a class="jxr_linenumber" name="L4" href="#L4">4</a> <em class="jxr_javadoccomment"> * which accompanies this distribution, and is available at</em>
<a class="jxr_linenumber" name="L5" href="#L5">5</a> <em class="jxr_javadoccomment"> * <a href="http://www.eclipse.org/legal/epl-v10.htm" target="alexandria_uri">http://www.eclipse.org/legal/epl-v10.htm</a>l</em>
<a class="jxr_linenumber" name="L6" href="#L6">6</a> <em class="jxr_javadoccomment"> */</em>
<a class="jxr_linenumber" name="L7" href="#L7">7</a> <strong class="jxr_keyword">package</strong> org.eclipse.papyrus.designer.transformation.core.transformations;
<a class="jxr_linenumber" name="L8" href="#L8">8</a>
<a class="jxr_linenumber" name="L9" href="#L9">9</a> <strong class="jxr_keyword">import</strong> org.eclipse.emf.ecore.EObject;
<a class="jxr_linenumber" name="L10" href="#L10">10</a> <strong class="jxr_keyword">import</strong> org.eclipse.emf.ecore.util.EcoreUtil.Copier;
<a class="jxr_linenumber" name="L11" href="#L11">11</a> <strong class="jxr_keyword">import</strong> org.eclipse.uml2.uml.Element;
<a class="jxr_linenumber" name="L12" href="#L12">12</a>
<a class="jxr_linenumber" name="L13" href="#L13">13</a> <em class="jxr_javadoccomment">/**</em>
<a class="jxr_linenumber" name="L14" href="#L14">14</a> <em class="jxr_javadoccomment"> * This class enables the copy from a source to a given target element.</em>
<a class="jxr_linenumber" name="L15" href="#L15">15</a> <em class="jxr_javadoccomment"> * It assumes that a copy has already been created, but will just not copy it...</em>
<a class="jxr_linenumber" name="L16" href="#L16">16</a> <em class="jxr_javadoccomment"> * Unlike the @see Copier class, the element might be copied to a different place</em>
<a class="jxr_linenumber" name="L17" href="#L17">17</a> <em class="jxr_javadoccomment"> */</em>
<a class="jxr_linenumber" name="L18" href="#L18">18</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">class</strong> <a href="../../../../../../../org/eclipse/papyrus/designer/transformation/core/transformations/CopyTo.html">CopyTo</a> {
<a class="jxr_linenumber" name="L19" href="#L19">19</a> <em class="jxr_javadoccomment">/**</em>
<a class="jxr_linenumber" name="L20" href="#L20">20</a> <em class="jxr_javadoccomment"> * Copy an element from the source to a target</em>
<a class="jxr_linenumber" name="L21" href="#L21">21</a> <em class="jxr_javadoccomment"> *</em>
<a class="jxr_linenumber" name="L22" href="#L22">22</a> <em class="jxr_javadoccomment"> * @param source</em>
<a class="jxr_linenumber" name="L23" href="#L23">23</a> <em class="jxr_javadoccomment"> * The element that should be copied</em>
<a class="jxr_linenumber" name="L24" href="#L24">24</a> <em class="jxr_javadoccomment"> * @param targetContainer</em>
<a class="jxr_linenumber" name="L25" href="#L25">25</a> <em class="jxr_javadoccomment"> * The container into which it the source should be copied</em>
<a class="jxr_linenumber" name="L26" href="#L26">26</a> <em class="jxr_javadoccomment"> * @return the copied object</em>
<a class="jxr_linenumber" name="L27" href="#L27">27</a> <em class="jxr_javadoccomment"> */</em>
<a class="jxr_linenumber" name="L28" href="#L28">28</a> @SuppressWarnings(<span class="jxr_string">"unchecked"</span>)
<a class="jxr_linenumber" name="L29" href="#L29">29</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> &lt;T <strong class="jxr_keyword">extends</strong> Element&gt; T copyTo(T source, Element targetContainer) {
<a class="jxr_linenumber" name="L30" href="#L30">30</a> Copier copier = <strong class="jxr_keyword">new</strong> Copier();
<a class="jxr_linenumber" name="L31" href="#L31">31</a> EObject sourceContainer = source.eContainer();
<a class="jxr_linenumber" name="L32" href="#L32">32</a> <strong class="jxr_keyword">if</strong> (sourceContainer != <strong class="jxr_keyword">null</strong>) {
<a class="jxr_linenumber" name="L33" href="#L33">33</a> copier.put(sourceContainer, targetContainer);
<a class="jxr_linenumber" name="L34" href="#L34">34</a> }
<a class="jxr_linenumber" name="L35" href="#L35">35</a>
<a class="jxr_linenumber" name="L36" href="#L36">36</a> EObject copy = copier.copy(source);
<a class="jxr_linenumber" name="L37" href="#L37">37</a> copier.copyAll(source.getStereotypeApplications());
<a class="jxr_linenumber" name="L38" href="#L38">38</a> copier.copyReferences();
<a class="jxr_linenumber" name="L39" href="#L39">39</a> <strong class="jxr_keyword">return</strong> (T) copy;
<a class="jxr_linenumber" name="L40" href="#L40">40</a> }
<a class="jxr_linenumber" name="L41" href="#L41">41</a> }
</pre>
<hr/>
<div id="footer">Copyright &#169; 2016&#x2013;2017 <a href="https://www.eclipse.org/">Eclipse foundation</a>. All rights reserved.</div>
</body>
</html>