| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
| <html lang="en"> | |
| <head> | |
| <meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2007. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." > | |
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | |
| <meta http-equiv="Content-Style-Type" content="text/css"> | |
| <title>Moving and copying Java elements</title> | |
| <link rel="stylesheet" href="../book.css" charset="ISO-8859-1" type="text/css"> | |
| </head> | |
| <body> | |
| <h1>Moving and copying Java elements</h1> | |
| <p> In this section, you will use refactoring to move a resource between Java packages. | |
| Refactoring actions change the structure of your code without changing its | |
| semantic behavior. </p> | |
| <ol> | |
| <li> In the Package Explorer view, select the <em>MyTestCase.java</em> | |
| file from the <em>test</em> package and drag it into the <em>junit.samples</em> package. | |
| Dragging and dropping the file is similar to selecting the file and | |
| choosing <strong>Refactor > Move </strong>from the context menu. | |
| </li> | |
| <li> You will be prompted to select whether or not to update references to the | |
| file you are moving. Typically, you will want to do this to avoid compile errors. You can | |
| press the <strong>Preview </strong>button to see the list of changes that | |
| will be made as a result of the move. | |
| </li> | |
| <li> | |
| <p>Press <strong>OK</strong>. The file | |
| is moved, and its package declaration changes to reflect the new location.</p> | |
| <p> <img src="images/editor_mytestcase_moved.png" alt="File moved to junit.samples package"> | |
| </p> | |
| </li> | |
| <li><p>Use <strong>Edit > Undo Move</strong> to undo the move.</p></li> | |
| </ol> | |
| <p>The context menu is an alternative to using drag and drop. When | |
| using the menu, you must specify a target package in the Move dialog, in | |
| addition to selecting the update references options you've already seen.</p> | |
| <ol> | |
| <li> | |
| Select the <em>MyTestCase.java</em> file and from its context menu, select <strong>Refactor | |
| > Move</strong>.</li> | |
| <li> In the Move dialog, expand the hierarchy to browse the | |
| possible new locations for the resource. Select the <em>junit.samples</em> | |
| package, then click <strong>OK</strong>. The class is moved, and its | |
| package declaration is updated to the new location. | |
| <p> <img src="images/move_dialog.png" alt="Move destination dialog"> | |
| </p> | |
| </li> | |
| </ol> | |
| <P class="nav_footer" id="nav_footer">Next Section: <A href="qs-Navigate.htm">Navigate to a Java element's declaration</A> | |
| </P> | |
| <h3 class="related">Related concepts</h3> | |
| <a href="../concepts/concept-java-views.htm">Java views</a><br> | |
| <a href="../concepts/concept-refactoring.htm">Refactoring support</a> | |
| <h3 class="related">Related references</h3> | |
| <a href="../reference/ref-menu-refactor.htm">Refactoring actions</a><br> | |
| <a href="../reference/ref-wizard-refactorings.htm">Refactoring wizard</a><br> | |
| <a href="../reference/preferences/ref-preferences-java.htm">Java preferences</a> | |
| </body> | |
| </html> |