如何在Java项目(Eclipse或其他项目)中重命名1000个类名?

时间:2023-01-22 10:46:52

I have a Java project organized using Eclipse in linux. I want to migrate this project to Windows. But there are so many java files with only case differences in names, like AM.java, am.java, Am.java, aM.java. These four files cannot exist together in one directory under Windows. So I need to rename these files in linux before migration. like:

我在linux中有一个使用Eclipse组织的Java项目。我想把这个项目迁移到Windows。但是有太多的java文件只有大小写的区别,比如AM。java、。java、。java,aM.java。这四个文件不能同时存在于Windows下的一个目录中。所以在迁移之前,我需要在linux中重命名这些文件。如:

AM.java -> AM1.java
am.java -> am2.java
Am.java -> Am3.java
aM.java -> aM4.java

Because the java classes invoke each others, so we cannot simply rename the java file names. All references inside the files should be replaced at the same time. I know there's a rename function in Eclipse. But there are so many java classes that I cannot rename them mannually, is there a script way or program way to achieve this? based on Eclipse or other Java IDEs?

因为java类相互调用,所以我们不能简单地重命名java文件名。文件中的所有引用都应该同时替换。我知道Eclipse中有一个重命名函数。但是有这么多java类,我不能用人工重命名它们,有脚本方法或程序方法来实现吗?基于Eclipse还是其他Java ide ?

EDIT There're some classes named a.java and A.java. Also there're many variables and methods named a,A. So there will be like this:

有一些类叫做a。java和A.java。还有很多变量和方法叫做a, a。所以会是这样的:

File 1:
class A
{
...
}

File 2:
int A = 1;

File 3:
int A(int a, int b)
{
    return a + b;
}

All I wanna to change is the class A, not the variable or method A. So we cannot simply replace the whole word, a java grammer parser seems to be necessary?

我想要改变的是类A,而不是变量或方法A。所以我们不能简单地替换整个词,似乎需要一个java语法分析器?

1 个解决方案

#1


2  

Use Krusader file explorer. Use Multi Rename feature. It is based on krename.

使用Krusader文件浏览器。使用多重命名功能。它基于krename。

  • Installing on Windows
  • 在Windows上安装
  • Installing on Linux
  • 在Linux上安装

After renaming files as said above import the projects in eclipse. This shows many compiler errors as references are not updated. Use Search dialog(opens on pressing Ctrl + H) to update the references. Repeat this for all 4 cases mentioned in your post one by one.

如上所述重命名文件之后,将在eclipse中导入项目。这显示了许多编译器错误,因为引用没有更新。使用搜索对话框(按Ctrl + H打开)更新引用。在你的博文中逐一提到的4个案例中重复以上内容。

Refer this and this.

这个和这个。

Edit

After looking at your comment:

看完你的评论:

Hope you completed part 1 and its working(?). If so then,

希望您已经完成了第1部分及其工作(?)。如果是这样,

  • Just find all search term/key(Ex: AM) in entire workspace using search dialog
  • 使用搜索对话框在整个工作区中找到所有的搜索词/键(例如:AM)
  • Press Ctrl + A to select all search results.
  • 按Ctrl + A选择所有搜索结果。
  • Right click on the selection then select Replace All then enter replace word ex:AM1
  • 右键单击选择,然后选择Replace All,然后输入Replace word ex:AM1
  • Press OK
  • 按OK

Note: Don't forget to select Case Sensitive and Whole World option while searching and file extension .java. You have to do it JUST 4 times for 4 cases.

注意:在搜索和文件扩展名.java时,不要忘记选择大小写敏感和全局选项。4种情况下,你只需要做4次。

#1


2  

Use Krusader file explorer. Use Multi Rename feature. It is based on krename.

使用Krusader文件浏览器。使用多重命名功能。它基于krename。

  • Installing on Windows
  • 在Windows上安装
  • Installing on Linux
  • 在Linux上安装

After renaming files as said above import the projects in eclipse. This shows many compiler errors as references are not updated. Use Search dialog(opens on pressing Ctrl + H) to update the references. Repeat this for all 4 cases mentioned in your post one by one.

如上所述重命名文件之后,将在eclipse中导入项目。这显示了许多编译器错误,因为引用没有更新。使用搜索对话框(按Ctrl + H打开)更新引用。在你的博文中逐一提到的4个案例中重复以上内容。

Refer this and this.

这个和这个。

Edit

After looking at your comment:

看完你的评论:

Hope you completed part 1 and its working(?). If so then,

希望您已经完成了第1部分及其工作(?)。如果是这样,

  • Just find all search term/key(Ex: AM) in entire workspace using search dialog
  • 使用搜索对话框在整个工作区中找到所有的搜索词/键(例如:AM)
  • Press Ctrl + A to select all search results.
  • 按Ctrl + A选择所有搜索结果。
  • Right click on the selection then select Replace All then enter replace word ex:AM1
  • 右键单击选择,然后选择Replace All,然后输入Replace word ex:AM1
  • Press OK
  • 按OK

Note: Don't forget to select Case Sensitive and Whole World option while searching and file extension .java. You have to do it JUST 4 times for 4 cases.

注意:在搜索和文件扩展名.java时,不要忘记选择大小写敏感和全局选项。4种情况下,你只需要做4次。