Showing posts with label IntelliJ. Show all posts
Showing posts with label IntelliJ. Show all posts

Thursday, 13 November 2025

Rename .java to .kt

So, I've suddenly recently noticed that whenever I commit a change into Git in IntelliJ that contains a conversion of a .java file into a .kt (Kotlin) file, IntelliJ will automatically make a previous commit containing the comment "Rename .java to .kt" which contains ONLY the renaming of the file.

I thought this was odd, but the reason behind it is that this commit helps Git to bind the two files together in the History.

If you do not have this single commit, (for example, if you're merging this to your integration branch or whatever and you squash your commits), you lose the history. It means Git will see the .java file as a file that has been deleted and the .kt file as a new file that has been added.

Some people complain, but it really depends on what is important to you:

  • do you want to preserve your history in Git for a file
  • or
  • do you want to see the changing the filename as belonging to your commit (and your ticketnumber in de comments)

Ideally, you should bear in mind IntelliJ does this, so you can at least edit the Commit Message of the renaming to include your ticketnr and original comment and such.

Settings

Can you turn this setting off? Yes, you can. There's a checkbox in the settings of the Git Commit dialog.

Unfortunately, this interesting setting only appears when you have indeed converted a Java file into a Kotlin file.

References

Kotlinlang - slack-chats
https://slack-chats.kotlinlang.org/t/465094/hi-i-ve-discovered-to-my-surprise-that-the-java-to-kotlin-co

Thursday, 26 December 2024

Reinitializing IntelliJ

Every once in a while, you get into trouble, serious trouble, and the only solution is to clear out all your stuff and start again.

This recently happened to me when my IntelliJ started misbehaving. I didn't have time to fix it, so I just bore with it, but now it's time to fix it.

In order to remove all the settings of IntelliJ (That I thought were the problem), I found the link at [2] via [1] which helped a lot!

And since I'm using a MacBook M2, perhaps I should write them down here:

Configuration (idea.config.path): ~/Library/Application Support/JetBrains/IntelliJIdea2022.2
Plugins (idea.plugins.path): ~/Library/Application Support/JetBrains/IntelliJIdea2022.2/plugins
System (idea.system.path): ~/Library/Caches/JetBrains/IntelliJIdea2022.2
Logs (idea.log.path): ~/Library/Logs/JetBrains/IntelliJIdea2022.2
Preferences (~/Library/Preferences/com.jetbrains.*)

Above are the directories that you should either remove or move somewhere safe (in case you want to reuse settings, like for example database connection properties).

Removing installed applications

JetBrains Toolbox

I found a good reference to it in [4].

Removing IntelliJ settings from a Project

So, if I've done the above, good idea to also remove the settings that are project specific.

This should be as simple as finding the ".idea" directory in your project and removing it entirely. But an alternate way is just removing all unversioned files and changes from your version management system, that'll work too.

I found a good way of doing it using the Git versioning system and described it in [3].

Then what?

Well, unfortunately, after all that it's time to reimport your project into IntelliJ and configuring all your IntelliJ settings again.

Preferably by hand, to prevent the same problem that torpedoed your Intellij from happening again.

References

[1] StackOverflow - In IntelliJ on OS X, how do you clear out all global setting info, licensing etc. (external to any project)
https://stackoverflow.com/questions/2774315/in-intellij-on-os-x-how-do-you-clear-out-all-global-setting-info-licensing-etc
[2] IntelliJ Support - Directories used by the IDE to store settings, caches, plugins and logs
https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs
[3] Git: Adding your own commands
https://randomthoughtsonjavaprogramming.blogspot.com/2024/10/git-adding-your-own-commands.html
[4] iBoostUp - How To Uninstall JetBrains Toolbox
https://www.iboostup.com/how-to-uninstall/com.jetbrains.apps.activator

Thursday, 23 April 2020

Keyboard problems in Linux with IntelliJ

Numpad arrow keys

So the numpad arrow keys do not work in my IntelliJ editor under Fedora Core 31.

I read about similar issues on the Internet.

One of the solutions that worked for me, was to change the file /usr/share/X11/xkb/symbols/keypad.

First off copying the original file seems like a good idea, something like keypad.original.

Then replace all occurrences of KP_Up, KP_Down, KP_Left, KP_Right with Up, Down, Left, Right respectively.

Either rebooting or executing a setxkbmap should do the trick.

Ctrl-Alt-Left and Ctrl-Alt-Right

I use these to go to the next or previous call in Intellij. Linux just wants to switch Workspaces, when I do that.

The shortcuts could not be found using the standard Settings tool.

But I found a solution at [2].

gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-up []
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-down []
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-left []
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-right []

With a reset if I decide to need it like:

gsettings reset org.gnome.desktop.wm.keybindings switch-to-workspace-up
gsettings reset org.gnome.desktop.wm.keybindings switch-to-workspace-down
gsettings reset org.gnome.desktop.wm.keybindings switch-to-workspace-left
gsettings reset org.gnome.desktop.wm.keybindings switch-to-workspace-right

References

Medium.com - A simple, humble but comprehensive guide to XKB for linux
https://medium.com/@damko/a-simple-humble-but-comprehensive-guide-to-xkb-for-linux-6f1ad5e13450
[2] Ubuntu - How to disable the keyboard shortcut to switch between workspaces
https://askubuntu.com/questions/744214/how-to-disable-the-keyboard-shortcut-to-switch-between-workspaces

Thursday, 9 March 2017

Git Stash

This little blog post is just for me to remember my favorite "git stash" commands. It took me a little while to actually use the stash, but that is because IntelliJ provides a similar functionality called "shelving", which I had used all this time.

I use branches a lot when using Git, and the problem there is that Git usually complains if I wish to change branches, while I still have uncommitted changes in my current branch. Therefore the "stash" command is for me very valuable.

Stash your current uncommitted changes:
$ git stash

Get your uncommitted changes back from the stash:
$ git stash apply

Get a list of your current stashes:
$ git stash list
stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051 Revert "added file_size"
stash@{2}: WIP on master: 21d80a5 added number to log
Remove a no longer needed stash:
$ git stash drop stash@{0}
Dropped stash@{0} (364e91f3f268f0900bc3ee613f9f733e82aaed43)
One command I particularly like is this one that does both an apply of your stash and once done automatically removes it from the list of stashes:
git stash pop

The stash has a lot of similarities to your standard Stack implementation (or Dequeue, depending on your point of view.)

I notice that if I do not clean up the place or use the "pop" subcommand, that my list of stashes tends to grow quite long unobtrusively.

View a stash without applying:

git stash show

Actually showing the contents of the stash in diff format is:

git stash show -p

The commands above work on the latest stash in your list.

References

6.3 Git Tools - Stashing
https://git-scm.com/book/en/v1/Git-Tools-Stashing
Atlassian Tutorials - Git Stash
https://www.atlassian.com/git/tutorials/git-stash
Ariejan De Vroom - GIT: Using the stash
https://ariejan.net/2008/04/23/git-using-the-stash/
Git Stash - Man Page
https://git-scm.com/docs/git-stash

Update: added the showing of stashes without applying.

Thursday, 15 December 2016

New feature in IntelliJ


In the User Interface in the new version of IntelliJ1, version 2016.32, a new feature popped up called "Parameter hints"3.

My colleague at work has some strong feelings about it.

He feels that the feature provides the lazy programmer with an excuse not to provide properly typed parameters in a method definition (too many String/Boolean/Long and not enough OrderedItem for example). It also would allow the lazy programmer to create methods with 5 parameters or more, as the IDE helps you identify what they are.

Uncle Bob4 mentions that anything over three requires some serious soul searching.

My colleague and I both feel that a few of the methods in our software are suffering from an excess of parameters. Even worse, that a lot of these parameters are Booleans that function as switches to alter the behaviour of the method in some way. A code smell, to be sure.

Some solutions, although this blog post does not actually focus on it, is using either a configuration object that contains the parameters4 or perhaps a builder.

References

[1] IntelliJ IDEA the Java IDE
https://www.jetbrains.com/idea/
[2] What's New in IntelliJ IDEA 2016.3
https://www.jetbrains.com/idea/whatsnew/
[3] Parameter Hints in IntelliJ IDEA 2016.3 - YouTube
https://www.youtube.com/watch?v=ZfYOddEmaRw&feature=youtu.be
[4] Clean Code, page 40
Robert C. Martin
[5] Introduce parameter object
https://sourcemaking.com/refactoring/introduce-parameter-object