Why can't I change package name in intellij idea?
I want to change "java" package to something else, for example "junit" or "jtests":
But when I select Refactor -> Rename I wind up with the dialog window:
then I select Rename current, in the next window I enter desired package name:
and then, no matters whether I click Refactor or Preview button, nothing happens. Nothing at all: no errors, no warnings, no actions. Why can't I rename this package?
It seems to be a bug of IntelliJ IDEA. I found the solution on JetBrains forum. By invalidating the cache and restarting, I got the ability to rename this package.
For me invalidation didn't work. I made a new package and temporarily moved the classes out of the package I wanted to rename. It would disapear when I would rename them, so I would create them again.
Just a bug in intellij. Invalidate the caches and restart. Here's how, it's easy.
Only folders under java are part of the package qualified name.
Example:
If you have a file in a folder located under app/src/main/java/com/my/package then the package will be com.my.package
So, you only want to change folders under java.
However, regarding the "com" folder, the IDE does not provide an option to refactor package name. In this case, you need to manually rename all code occurrences of the old folder and invalidate the cache after renaming the folder.
File > Invalidate caches... > Clear system
For me it was due to memory problem, after increasing memory (heap size) it solved.
Related
I have intelliJ already setup to "compact empty middle packages"
When I do refactor -> rename, the only dialog will only actually rename the directory (even when I have it search for occurances), resulting in my code that uses the package throughout the project, still using the original name.
I'm sure there used to be a way to "rename package" and not just the directory, did the mechanism for this change? I really need to rename my package.
Please don't mark this as a duplicate, because the other places I see this being asked, the solution is to first "compact empty middle packages" - which I have already done... and I still can't get it to work.
Try to open a class that is in that package, then right click on the package xyz.abc line (should be the first line in that file) and choose Refactor -> Rename from the context menu.
For some reason when I try to do a rename refactor, idea picks up code that is not even remotely close to my project. Furthermore, this code is read-only and I can't edit it! And Non-Project Access dialog is almost mockingly "ultimate" in its options: I can only choose whether I want to edit the non-project files this time or I want to do this ALWAYS. No option to skip these files altogether.
I tried to add these folders as a content root and exclude them - it didn't help. And I can't remove them, since they actually don't show up as files in the refactor preview (they are not referenced anywhere in the project view either), only {m} functions/method do with no option to remove them.
So the refactor rightfully fails because it can't edit RO files. So how would I solve this?
I am trying to exclude a particular file in my project from being compiled.
According to the Intellij IDEA documentation you do this by "marking the file as plain text".
However, the context menu in the project view where this functionality is supposedly located has no such action. I am using version 13.02 of Intellij. Here is what my context menu looks like:
Under File > Settings > Build, Execution, Deployment > Compiler > Excludes, add an entry.
Any attempts to run a path specified here will result in a ClassNotFoundException, and a very important class indicator as well.
Just to compound on Makoto's answer (would comment but don't have reputation), it looks like this feature does not apply to classes (.java) or assets (images)...for these types of files, it looks like you will need to actually go to the compiler and explicitly state that the file(s) should be excluded.
However, for .htm, .xml, or really anything that isn't a class or asset you will find and can use the 'Mark as plain text' option.
Edit: It looks like you can also go to the 'Messages Make' error / warnings view and Exclude from there, a little less work IMHO.
The answer that #Makoto has given is pretty much the way to go, but in case that you are like me and you get easily both distracted and frustrated looking for that menu, you could use this shortcut:
press ctrl + shift + a , and in the input box that appears type excludes, and select the first item that appears.
Somehow, I managed to break my refactoring capabilities in Intellij IDEA 12. I have somehow disabled it for my project. Renaming a member through Shift+F6 doesn't work. The inline edit box is not drawn, nothing happens.
I know of the refactoring settings in Settings -> Editor, Enable in-place mode and Preselect old name are both checked.
It has to be some kind of project setting. I checked by creating a test project, adding some member and renaming it, which works perfectly.
What setting am I looking for? Or could my project be broken?
There is no way to turn refactoring off in the settings. My guess is that the project's cache/indexes are corrupted. I had a case once where refactoring, especially renames, stopped working. A re-index solved it for me. Go to File >Invalidate Caches, invalidate your caches, restart IDEA, and let IDEA re-index the project (progress is shown in the bottom status bar right of center). Then try the refactoring.
If that does not solve it, take a look in the logs (Help > Show Log) and see if there is any indication in there as to the cause of the issue.
Fo all the MacOS users, do not forget to access Settings -> Keyboard and turn on the flag for the option Use all F1, F2, etc. keys as standard function keys. E.g.:
Otherwise IntelliJ will not get the focus to use the F4 key.
Following step worked for me:
From your IDE, go to: Preferences -> Project Structure -> Add Content Root, then select the folder you want to use.
None of the above steps worked for me in IDEA 2021.2.4 (Ultimate Edition). I got the following error message when trying to rename a file and its usages:
Cannot perform refactoring. Selected file is not located inside the project.
Instead, I had to create a new module.
File > Project Structure > Modules > Add (+) > Import module > Select <root_folder_of_your_project>
This reindexed the whole project, which took a couple of minutes, and restored the Refactor > Rename functionality.
waite for some time it can be due to running Indexing
I have just upgraded to the new Xcode 4 and the code is not colored has it should be.
I am trying to use a project that I created on Xcode 3.
For instance, the string 'NSString' is not colored in my custom code, but when I switch to Apple's code (NSString.h for ex.) everything is well colored.
How can I fix that?
Thanks a lot,
Martin
Open the Organizer (Window > Organizer) and select the Projects mode. Select your project in the left-hand view and then click the Deleteā¦ button for the project's Derived Data.
This will delete the code sense index for the project and force Xcode to rebuild the index, which should fix the problem.
I got it to work by prefixing all my project search paths with "$(SOURCE_ROOT)/" instead of just using a project relative path. Eg "Include" becomes "$(SOURCE_ROOT)/Include".
Do this and then force a rebuild of the index by deleting the projects derived data from the organizer.
After trying most, if not all, of the steps above, I have succeeded in restoring my colorful Xcode eye candy by finding and deleting (in Finder) all of the derived data created from my project (there were several folders for my project that were lingering even after deletion from the Window > Organizer menu).
My project's folders that needed deletion were located in ~Library/Developer/Xcode/DerivedData
Also try this, select all(command + A) from your Prefix.pch file -> cut it(command + X) -> Build(command + B)(don't worry for error) -> paste(whatever you copy from Prefic.pch file in that file only)(commmand + V) -> Build again (command + B).
Try Product -> Clean and then Product -> Build
Remove the files from your project (just remove, don't delete them!) and re-import them.
Its possible that the permissions on the folder where Xcode stores the code-sense cache is broken. If the cache cannot be correctly written or read when you launch Xcode, it will behave as you describe.
Try locating the folder (you can locate it in the organizer. Hit the arrow next to the path.) and reset its permissions in the Get Info dialog.
There is another cause for this issue, it had been happening to me with beta versions of Xcode, you need to check that the .m file is added to the target in order to make it add color to the classes and enable the autocompletion.
You can check it out in the Xcode inspector
Hope this helps,
best regards,
Jorge.