Refactor "package structure" in Eclipse to relocate a package's child package to its parent package
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.
If you switch your package representation to hierarchical
(from arrow on the top-right), you can right-click the com.animal
package and rename it to com
.
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 under com.animal
. This way Eclipse would present a separate entry for com.animal
.
Having selected com.animal
you can simply do the rename refactoring. Make sure you select the 'Rename subpackages' checkbox.
精彩评论