开发者

Having Eclipse automatically try to add imports on bunch of .java files

I know I can open a given file, and hitting CTRL + SHIFT + M, it will add the import associated with the class I have currently my cursor over.

I'm making some big refactoring over my project and I decided to replace all the references to the File class to a Filename class of my own. As the system contains maybe hundreds of classes, this is开发者_开发技巧 being a nightmare to handle. I've replaced with Search and Replace all the references of File to Filename, but now I have problems with imports all over the place.

What would be the easier way to accomplish my task other than having to open all the files and manually add the import to the Filename class while removing the old import of File ?

Also, is there an easier way to replace a used class in your project (this case, the File class) by another one other than using Search and Replace?


Don't do Search and Replace. Just select the classname declaration in the original source file and press Alt+Shift+R (or do rightclick and then choose Refactor and then Rename).

Having Eclipse automatically try to add imports on bunch of .java files


Update: If you really need to Search and Replace over the entire project or even workspace, then press Ctrl+H, choose the File Search tab, enter the keyword and then press Replace button instead of Search button.

Having Eclipse automatically try to add imports on bunch of .java files


Organize Imports

You can right-click on the root src folder, select Source and Organize Imports. This will organize the imports for all classes and interfaces in the given project. Use it carefully.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜