You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- switch (keyBinding.get()) {- case DELETE_ENTRY:- new DeleteFileAction(dialogService, preferencesService, databaseContext,- viewModel, listView).execute();- event.consume();- break;- default:- // Pass other keys to children+ if (keyBinding.get() == KeyBinding.DELETE_ENTRY) {+ new DeleteFileAction(dialogService, preferencesService, databaseContext,+ viewModel, listView).execute();+ event.consume();+ } else {
Expected:
if (keyBinding.get() == KeyBinding.DELETE_ENTRY) {
newDeleteFileAction(dialogService, preferencesService, databaseContext,
viewModel, listView).execute();
event.consume();
} else {
// Pass other keys to children
@koppor The recipe could certainly try to preserve more of the comments. AFAICT any comments before or after the break would currently get lost. In your case it appears that you have a default case with only a comment in it.
I just checked what IntelliJ IDEA does in this case: It generates an if statement without else and drops the comment. I think we should either do that or generate an else with only the comment in it. Personally I would opt for IntelliJ's behavior, as I think an otherwise empty else block looks rather strange (IntelliJ, for example, would annotate it with a warning marker). As a developer you could still decide if you think you need to add that comment before or after the if before integrating the change. What do you think?
I personally like to have comments very close to the logical position. If an else branch is matched and nothing is done here for a reason, I sometimes put comments there. Pass other keys to children is a perfect example there.
However, I am in the minority here - and it is OK for me to have these comments somewhere else.
When the comments are deleted, there is manual investigation needed to restore the comments based on the git diff. Therefore, this is the least good option for me.
Activity
knutwannheden commentedon May 6, 2023
@koppor The recipe could certainly try to preserve more of the comments. AFAICT any comments before or after the
breakwould currently get lost. In your case it appears that you have a default case with only a comment in it.I just checked what IntelliJ IDEA does in this case: It generates an if statement without else and drops the comment. I think we should either do that or generate an else with only the comment in it. Personally I would opt for IntelliJ's behavior, as I think an otherwise empty else block looks rather strange (IntelliJ, for example, would annotate it with a warning marker). As a developer you could still decide if you think you need to add that comment before or after the if before integrating the change. What do you think?
koppor commentedon May 6, 2023
I personally like to have comments very close to the logical position. If an
elsebranch is matched and nothing is done here for a reason, I sometimes put comments there.Pass other keys to childrenis a perfect example there.However, I am in the minority here - and it is OK for me to have these comments somewhere else.
When the comments are deleted, there is manual investigation needed to restore the comments based on the git diff. Therefore, this is the least good option for me.
Fix switch-related recipe bugs (#6, #9, #14, #687)
Fix switch-related recipe bugs (#6, #9, #14, #687)
Fix switch-related recipe bugs (#6, #9, #14, #687) (#852)