\"Rename\". That it is is under the \"Refactor\" su" />
开发者

How to rename a class and its corresponding file in Eclipse?

开发者 https://www.devze.com 2023-02-15 00:46 出处:网络
Cannot find any menu item to do thi开发者_如何学运维s. Is it doable?Just right click on the class in the project explorer and select \"Refactor\" -> \"Rename\". That it is is under the \"Refactor\" su

Cannot find any menu item to do thi开发者_如何学运维s. Is it doable?


Just right click on the class in the project explorer and select "Refactor" -> "Rename". That it is is under the "Refactor" submenu.


Shift + Alt + r (Right click file -> Refactor -> Rename) when cursor is on class name. The file and constructors will be also changed.


Right click file -> Refactor -> Rename.


You can rename classes or any file by hitting F2 on the filename in Eclipse. It will ask you if you want to update references. It's really as easy as that :)


Just rename the class in the source code. Eclipse will point out an error by underlining the class name with a red squiggly line. Hover on that line with your mouse pointer and eclipse will give you the option to rename compilation unit. Click on that.


Simply select the class, right click and choose rename (probably F2 will also do). You can also select the class name in the source file, right click, choose Source, Refactor and rename. In both cases, both the class and the filename will be changed.


Click on the class and press the Alt + Shift + R keys, then you can change it to the required name and the corresponding file name will also be changed.


Right click on the class->select Refactor->Rename


I found the answers above didn't give me the guidance I needed (I too expected to be in the code for the .java file, and right-click on the tab and see a Refactor option). Here's what I did:

  1. Go to the top of the .java module (ctrl+Home)
  2. Double-click on the class name that is the same name as the .java module and the class name should now be highlight
  3. Right-click the highlighted class name | Open Type Hierarchy. The Type Hierarchy should open showing the class name
  4. Right-click the class name in the Type Hierarchy | Refactor | Rename | type the new name in the popup window Rename Type


To rename file using refactoring (which also updates all occurrences of name in other scripts):

  1. Save changes to file before using refactoring/renaming
  2. In Project Explorer view, right-click file to be renamed and select Refactor | Rename -or- select it and go to Refactor | Rename from the Menu Bar. A Rename File dialog will appear.
  3. Enter the file's new name.
  4. Check the "Update references" box and click Preview.
  5. You can scroll through changes using the Select Next / Previous Change scrolling arrows.
  6. Press OK to rename file and update all occurrences of the script name in other scripts.

See "PHP Developer User Guide > Tasks > Using Refactoring > Renaming Files".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号