tags:

views:

21

answers:

1

I have used file search functionality in eclipse to replace a specific occurrence of text with a replace text which contains a java method name in all files across the workspace.

But now in all those files I have to add the import statement (for the method name to resolve).

Is there an automatic way of doing this instead of manually searching and importing the package myself in all files?

P.S.: I can't use java refactoring since the text I have changed is not a java element and Organize import option will make changes to lot of files (re-ordering imports) which will be problematic when I need to commit, I again have to manually check differences to see which files have actual changes instead of just organize import statements.

+3  A: 

Instead of doing this with search and replace, try to use Refactor->rename which will do it correctly. another options is to use organize imports, you can do it for an entire project as well (source -> organize imports).

Omry
Thanks Omry. but this can't be done using Refactor->rename as the text I have changed is not a java element.Organize imports is fine, but it will re-order imports in the all files as well (and we have lot of files which have imports not organized)
Reddy
that's not so bad. in fact - it will cleanup your imports and remove unused imports. can't be a bad thing :)
Omry
You can use "organize imports" on a per file basis. You don't have to do it across the entire project. In Package Explorer, right click on the file, select source->organize imports.
Tansir1
Thanks a lot Omry. I understand it is not bad option, but just want to know if there are any other options?
Reddy
the 'correct' way to rename classes/methods in Eclipse is using refactor->rename.as Tansir1 mentioned, you can organize imports of affected files only if you choose.
Omry