简体   繁体   English

Eclipse:“重构 - 重命名”完全搞砸了,替换文件中的任意字符

[英]Eclipse: “Refactor - Rename” completely messed up, replacing arbitrary characters in file

When refactoring a class name, Eclipse lately shows a very strange behavior.在重构 class 名称时,Eclipse 最近表现出非常奇怪的行为。 For example, let's look at one of our classes:例如,让我们看一下我们的一个类:

public class CampaignCSVPanel extends ContentPanel {

   private FileUploadField uploadFieldCsv = new FileUploadField();
   ...
}

and I rename it to "CampaignCsvPanel", then the following happens:我将其重命名为“CampaignCsvPanel”,然后发生以下情况:

public class CampaignCSVPanel extends ContentPanel{

   private FileUploadField uploadFielCampaignCsvPanelploadField();
   ...
}

Strange - and it happens basically every time I perform a class rename.奇怪 -基本上每次我执行 class 重命名时都会发生这种情况。 What's more:更重要的是:

  • I already created a completely new workspace (and checked out the same projects again),我已经创建了一个全新的工作区(并再次检查了相同的项目),
  • and I installed a fresh version of Eclipse (ie it happens both in Eclipse 3.6 and 3.7).我安装了新版本的 Eclipse(即它发生在 Eclipse 3.6 和 3.7 中)。

I assume, it must have something to do with the projects in the workspace, because it only happens with the projects of one company I work for - not with other sets of projects I'm working on.我认为,它一定与工作区中的项目有关,因为它只发生在我工作的一家公司的项目中——而不是我正在从事的其他项目集。 Do you have any idea, what the reason could be?你有什么想法,可能是什么原因?

(System specs: (系统规格:

  • Ubuntu Linux 11.04, 64bit Ubuntu Linux 11.04,64位
  • Eclipse 3.6/3.7 Eclipse 3.6/3.7
  • Plugins: Subversive, m2eclipse, Google (GWT) plugin.插件:Subversive、m2eclipse、Google (GWT) 插件。
  • I tried both OpenJDK and SunJDK (1.6.0_24).我尝试了 OpenJDK 和 SunJDK (1.6.0_24)。 ) )

Try this:尝试这个:

Go to Windows -> Preferences -> Java and uncheck 'Rename in editor without dialogue' Go 到 Windows -> 首选项 -> Java 并取消选中“在编辑器中重命名而不使用对话”

(I'm looking at the recent release of Eclipse Indigo, I only assume the settings are the same on previous versions) (我正在查看最近发布的 Eclipse Indigo,我只假设之前版本的设置相同)

Now you can preview all of the changes it intends to make.现在您可以预览它打算进行的所有更改。

If you can do this and verify in that dialogue that it is doing some crazy replacements, then you should most definitely file a bug with Eclipse and provide the reproducible example.如果您可以这样做并在该对话中验证它正在执行一些疯狂的替换,那么您绝对应该使用 Eclipse 提交错误并提供可重现的示例。 I would bet though, that once you look at the list of things it intends to replace you'll find some other explanation for the problem.不过我敢打赌,一旦你查看了它打算替换的东西的列表,你会发现这个问题的其他一些解释。

That's annoying.这很烦人。 Obviously the refactoring engine knows that it has to replace something but replaces characters at a wrong position... - no answer but some additional ideas/tests显然,重构引擎知道它必须替换某些东西,但会替换错误的 position 处的字符...... - 没有答案,但有一些额外的想法/测试

  1. Looks like you check out complete projects.看起来你检查了完整的项目。 Try to import sources only to a fresh project to check if the problem still occurs or if its gone.尝试仅将源导入新项目以检查问题是否仍然存在或消失。
  2. If project metadata has been checked in (it shouldn't, but we never know), clean the project right after checking the project out.如果已签入项目元数据(不应该,但我们永远不知道),请在签出项目后立即清理项目。
  3. Check the character encoding of that companies source files.检查该公司源文件的字符编码。 Maybe there's some sort of mismatch which causes the editor to replace on wrong positions.也许有某种不匹配导致编辑器替换错误的位置。 And double check the source files for strange unprintable ascii bytes... again, we never know...并仔细检查源文件中是否有奇怪的不可打印的 ascii 字节......再一次,我们永远不知道......

I found the problem: The project is using svn tags like $Date: $ When I remove them, the problem disappears.我发现了问题:该项目正在使用 svn 标签,例如$Date: $当我删除它们时,问题就消失了。 When I re-insert them manually (to make sure I don't insert invalid characters), the problem re-appears.当我手动重新插入它们(以确保我不插入无效字符)时,问题再次出现。

I experimented a little more, and the problem also disappears, when I switch the SVN connector from JavaHL to SVNKit.我进行了更多实验,当我将 SVN 连接器从 JavaHL 切换到 SVNKit 时,问题也消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM