Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refactor "package structure" in Eclipse to relocate a package's child package to its parent package

Tags:

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.

like image 444
Chantz Avatar asked May 11 '11 20:05

Chantz


People also ask

How do I refactor a package in Eclipse?

Refactoring using EclipseRight clicking on a Java element in the Package Explorer view and selecting Refactor menu item. Right clicking on a Java element in the Java editor and selecting Refactor menu item. Selecting a Java element in either the Package Explorer view or Java Editor and clicking Shift + Alt + T.

How do I move a package from one package to another in Eclipse?

Right-click the package you want to move, and select " Refactor/Rename..." -- NOT " Move "! Modify the name of the package to reflect its desired new position in the package hierarchy, e.g. Prepend any new parent package name(s) if you are moving the package to downwards in the package hierarchy.

How do I fix package explorer in Eclipse?

You could try holding down Ctrl + F7 to see a list of all views, then up/down arrow to the View. If Package Explorer is in the list it has been minimised or something. If you select it and still can't see it, try Window → Reset Perspective... to restore all views to their defaults.


1 Answers

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.

like image 171
Bozho Avatar answered Sep 28 '22 02:09

Bozho