重构“包结构”在 Eclipse 中将包的子包重新定位到其父包
在 Eclipse 的“Package Explorer”中,假设我有一个如下所示的包列表:
- com.animal.dog
- com.animal.cat
- com.animal.frog
如果我想重构此包结构,使最终的包结构看起来像
- com .dog
- com.cat
- com.frog
因此基本上删除了父包 &将子包附加到其祖父母。我在“com.animal”包中有很多子包如果可能的话,我想避免手动执行此操作&然后也在各处更改包导入。
In Eclipse's "Package Explorer", let's say I have a list of packages like this:
- com.animal.dog
- com.animal.cat
- com.animal.frog
If I want to refactor this package structure so that the final package structure looks like
- com.dog
- com.cat
- com.frog
So essentially removing the parent package & attaching the child packages to its grandparent. I have many child packages in "com.animal" package & I would like to avoid if possible doing this manually & then also changing the package imports everywhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您将包表示形式切换为
分层
(从右上角的箭头),您可以右键单击com.animal
包并将其重命名为com
。If you switch your package representation to
hierarchical
(from arrow on the top-right), you can right-click thecom.animal
package and rename it tocom
.可能您在
com.animal
下没有任何类。您可以做的就是遵循 Bozho 的建议(并切换到分层视图)或直接在com.animal
下创建一个临时类。这样 Eclipse 就会为com.animal
提供一个单独的条目。选择 com.animal 后,您可以简单地进行重命名重构。确保选中“重命名子包”复选框。
Probably you don't have any classes directly under
com.animal
. What you can do is either follow Bozho's suggestion (and switch to hierarchical view) or create a temporary class directly undercom.animal
. This way Eclipse would present a separate entry forcom.animal
.Having selected
com.animal
you can simply do the rename refactoring. Make sure you select the 'Rename subpackages' checkbox.