简体   繁体   English

如何修复IntelliJ中的包名称?

[英]How to fix package names in IntelliJ?

Is it possible to fix all the package names in a given folder in IntelliJ? 是否可以在IntelliJ中的给定文件夹中修复所有包名称?

If files are manually imported into IntelliJ, and their package names are all wrong (including the sub-folders), how can I mass fix the package names? 如果文件被手动导入IntelliJ,并且它们的包名都错误(包括子文件夹),我该如何批量修复包名?

This has caused me a lot of grief so far.... 到目前为止,这给我带来了很多悲伤......

moving to a package or renaming a package 移动到包或重命名包

This has to be a bug. 这必须是一个错误。

Example: 例:

If I am on a package in the project explorer, and rename the package, say it is: 如果我在项目资源管理器中的软件包上,并重命名该软件包,请说:

com.example.xml.xml

Now I want to change this (and all the files under it) to: 现在我想将此(及其下的所有文件)更改为:

com.example.xml

I can't seem to do it! 我似乎无法做到!

When it says "rename package com.example.xml.xml to": 当它说“将com.example.xml.xml重命名为”时:

If I enter "com.example.xml" it won't work. 如果我输入“com.example.xml”,它将无法正常工作。 I'm not sure what it is going on, I have spent a over an hour trying this as I have more files to import/fix. 我不确定它是怎么回事,我花了一个多小时尝试这个,因为我有更多文件要导入/修复。

It seems you can't change a full package name like this one: "com.example.xml.xml", but you can change each fragment, for that you can go to "View Options" (a little wheel) in the project view, disable "compact empty middle packages" options, and do something like renaming the second "xml" from the end, so the final package could get into something like: 看起来你不能像这样更改一个完整的包名:“com.example.xml.xml”,但你可以更改每个片段,因为你可以转到项目中的“查看选项”(一个小轮子)查看,禁用“紧凑的空中间包”选项,并执行类似于从末尾重命名第二个“xml”的操作,因此最终包可能会出现类似于:

com
 -example
   -bar
     -xml

Then you can drag and drop all contents in the last "xml" to "bar" package and finally delete the last "xml". 然后,您可以将最后一个“xml”中的所有内容拖放到“bar”包中,最后删除最后一个“xml”。 In your case it seems you won't need to rename the package just move the contents 在您的情况下,似乎您不需要重命名包只需移动内容

In project view change layout to Flatten packages . 在项目视图中,将布局更改为展Flatten packages Then in same menu unselect Hide empty middle packages . 然后在同一菜单中取消选择Hide empty middle packages Then create the new package you want. 然后创建所需的新包。 And then using drag'n'drop move the root package which contains your code to a newly created package (when the pop-up appears, select the second option, ie move everything ... ). 然后使用drag'n'drop将包含代码的根包移动到新创建的包中(当出现弹出窗口时,选择第二个选项,即move everything ... )。 Delete old, unused packages 删除旧的,未使用的包

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

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