Stop eclipse renaming inside strings

大憨熊 提交于 2019-12-11 02:54:17

问题


I've been having this problem for some time and have never bothered to fix it since Eclipse has a horrible help system and I can't seem to find the right Google keywords to find what I need.

My problem is that when I refactor a class name, eclipse looks for all potential locations of that name and replaces them.

For instance, if I have a string inside a test case for the "list command" that says something like, "List - list all the users on a team", when I refactor the List.java class to something like UserListCommand.java, the expression inside the string also changes to "UserListCommand - list all the users on a team"

This is SOOO annoying! And like I said, Google is useless when you cannot even think of the right keywords to use.

Has anyone else had this problem and solved it?

Thanks in advance.


回答1:


Eclipse calls this updating textual occurrences in comments and strings. I sometimes turn this on so javadoc gets updated correctly if I didn't properly link it. But it can be a pain because it sometimes replaces substrings that match.

I've only seen this when renaming classes or interfaces (methods don't seem to do this, at least not for me),

You need to open the Rename Dialog to stop eclipse from updating textual occurrences in comments and strings:

Highlight the type you want to rename, then either:

  1. press Shift+Alt+R
  2. Right click, then go to refactor->rename.. then instead of typing the new name, there should now be a yellow context popup menu under the class name to be changed which says "Enter new name, press Enter to refactor", notice that there is a down arrow to expand the menu. If you press that instead of enter a new name a new drop down menu appears, select Open Rename Dialog...

Once the Rename Dialog is open:

uncheck "update textual occurences in comments and strings (forces preview)" and "Update fully qualified names in non-Java text files (forces preview)"

Hope that helps



来源:https://stackoverflow.com/questions/18176609/stop-eclipse-renaming-inside-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!