| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <meta name="GENERATOR" content="Microsoft FrontPage 4.0"> |
| <meta name="Author" content="MAe"> |
| <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 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>Finish</strong>. The file |
| is moved, and its package declaration changes to reflect the new location.</p> |
| <p> <img src="../images/qs-44.gif" width=489 height=196 alt="File moved to junit.samples package"> |
| </p> |
| </li> |
| <li> Select the <em>MyTestCase.java</em> file and drag it into the root |
| directory of the JUnit project. Once again, a dialog pops up letting the user decide to preview the changes. After you have pressed <strong>OK </strong>(or |
| <strong>Finish </strong>from the preview window), a default package is created to contain the |
| class, and the package declaration is removed to reflect the file's location |
| in the default package. |
| If you move a file to a default package the system additionally pops up a warning dialog, |
| informing the user about reference updates when moving to the default package. If you |
| don't want to see the dialog everytime you move a file to the default package, check the |
| <strong>Don't show this message again</strong> checkbox.<p> <img src="../images/qs-45.gif" width=530 height=181 alt="File moved to default package"> |
| </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/qs-46.gif" width=404 height=491 alt="Move destination dialog"> |
| </p> |
| </li> |
| </ol> |
| <img src="../images/ngrelc.gif" width=159 height=27 alt="Related concepts" border="0"> |
| <p> <a href="../tasks/tasks-6.htm">Java views</a><br> |
| <a href="../concepts/concepts-9.htm">Refactoring support</a> </p> |
| <p> <img src="../images/ngrelt.gif" width=159 height=27 alt="Related tasks" border="0"> |
| </p> |
| <p> <a href="../tasks/tasks-80.htm">Refactoring</a><br> |
| <a href="../tasks/tasks-85.htm">Copying and moving Java elements</a><br> |
| <a href="../tasks/tasks-51.htm">Moving folders, packages and files</a> </p> |
| <p> <img src="../images/ngrelr.gif" width=159 height=27 alt="Related reference" border="0"> |
| </p> |
| <p> <a href="../reference/ref-menu-refactor.htm">Refactoring actions</a><br> |
| <a href="../reference/ref-117.htm">Refactoring wizard</a><br> |
| <a href="../reference/ref-23.htm">Refactoring preferences</a> </p> |
| <p> <a href="../hglegal2003.htm"><img src="../images/ngibmcpy2003.gif" alt="Copyright (c) 2000, 2003 IBM Corporation and others. All Rights Reserved." border="0" height="14" width="324"></a> |
| </p> |
| </body> |
| </html> |
| |