Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix package names in IntelliJ?

Is it possible to fix all the package names in a given folder in 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?

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":

If I enter "com.example.xml" it won't work. 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.

like image 532
Blankman Avatar asked Mar 30 '12 14:03

Blankman


People also ask

Where is package name in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Package Search.

What is package naming?

The package name of an Android app uniquely identifies your app on the device, in Google Play Store, and in supported third-party Android stores.

How do I flatten a package in IntelliJ?

Click on the gear icon at the top right on the package view, and make sure that "Flatten Packages" and "Compact empty middle packages" are unchecked. Show activity on this post.

How do I rename a class in IntelliJ?

interfaces, enums or variable. names with ease in #IntelliJIDEA by. using Shift+F6.


2 Answers

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    -bar      -xml 

Then you can drag and drop all contents in the last "xml" to "bar" package and finally delete the last "xml". In your case it seems you won't need to rename the package just move the contents

like image 197
Jaime Hablutzel Avatar answered Oct 02 '22 17:10

Jaime Hablutzel


In project view change layout to Flatten packages. Then in same menu unselect 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, i.e. move everything ...). Delete old, unused packages

like image 29
WelcomeTo Avatar answered Oct 02 '22 16:10

WelcomeTo