From f0aba00a5a61709864d1cd3d0bc6df33b01197f8 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 5 Mar 2014 15:05:03 +0400 Subject: [PATCH] style: ternary operator used instead of several if-statements; comment added; unnecessary pool thread removed --- .../hg4idea/action/HgBranchPopupActions.java | 3 +- .../src/org/zmlx/hg4idea/action/HgMerge.java | 3 +- .../action/HgRunConflictResolverAction.java | 21 +++----------- .../hg4idea/ui/HgCommonDialogWithChoices.java | 5 +--- .../src/org/zmlx/hg4idea/ui/HgPushDialog.java | 28 ++++++------------- 5 files changed, 16 insertions(+), 44 deletions(-) diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopupActions.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopupActions.java index 5d107d1d3320..26abb5115c2f 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopupActions.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopupActions.java @@ -335,7 +335,8 @@ public class HgBranchPopupActions { public void actionPerformed(AnActionEvent e) { final UpdatedFiles updatedFiles = UpdatedFiles.create(); final HgMergeCommand hgMergeCommand = new HgMergeCommand(myProject, mySelectedRepository.getRoot()); - hgMergeCommand.setRevision(myBranchName); + hgMergeCommand.setRevision(myBranchName);//there is no difference between branch or revision or bookmark as parameter to merge, + // we need just a string final HgCommandResultNotifier notifier = new HgCommandResultNotifier(myProject); new Task.Backgroundable(myProject, "Merging changes...") { @Override diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgMerge.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgMerge.java index 127ca63ea2cb..87c907d76d59 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgMerge.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgMerge.java @@ -68,8 +68,7 @@ public class HgMerge extends HgAbstractGlobalAction { hgMergeCommand.setRevision(targetValue); try { - new HgHeadMerger(project, hgMergeCommand) - .merge(repo); + new HgHeadMerger(project, hgMergeCommand).merge(repo); new HgConflictResolver(project, updatedFiles).resolve(repo); } catch (VcsException e) { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgRunConflictResolverAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgRunConflictResolverAction.java index 0a183e32a1c2..938413e95356 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgRunConflictResolverAction.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgRunConflictResolverAction.java @@ -15,6 +15,7 @@ package org.zmlx.hg4idea.action; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.HgVcsMessages; @@ -28,16 +29,8 @@ public class HgRunConflictResolverAction extends HgAbstractGlobalAction { @Override public void execute(@NotNull final Project project, @NotNull Collection repositories, @Nullable HgRepository selectedRepo) { - final HgRepository repository; - if (repositories.size() > 1) { - repository = letUserSelectRepository(project, repositories, selectedRepo); - } - else if (repositories.size() == 1) { - repository = repositories.iterator().next(); - } - else { - repository = null; - } + final HgRepository repository = repositories.size() > 1 ? letUserSelectRepository(project, repositories, selectedRepo) : + ContainerUtil.getFirstItem(repositories); if (repository != null) { new Task.Backgroundable(project, HgVcsMessages.message("action.hg4idea.run.conflict.resolver.description")) { @@ -50,17 +43,11 @@ public class HgRunConflictResolverAction extends HgAbstractGlobalAction { } } - @Nullable private static HgRepository letUserSelectRepository(@NotNull Project project, @NotNull Collection repositories, @Nullable HgRepository selectedRepo) { HgRunConflictResolverDialog dialog = new HgRunConflictResolverDialog(project, repositories, selectedRepo); dialog.show(); - if (dialog.isOK()) { - return dialog.getRepository(); - } - else { - return null; - } + return dialog.isOK() ? dialog.getRepository() : null; } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCommonDialogWithChoices.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCommonDialogWithChoices.java index 35fa34b441bd..ddd92fdfe609 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCommonDialogWithChoices.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCommonDialogWithChoices.java @@ -144,9 +144,6 @@ public class HgCommonDialogWithChoices extends DialogWrapper { protected ValidationInfo doValidate() { String message = "You have to specify appropriate name or revision."; - if (StringUtil.isEmptyOrSpaces(getTargetValue())) { - return new ValidationInfo(message, myBranchesBorderPanel); - } - return null; + return StringUtil.isEmptyOrSpaces(getTargetValue()) ? new ValidationInfo(message, myBranchesBorderPanel) : null; } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.java index 250485959399..892bbb933a06 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.java @@ -13,8 +13,6 @@ package org.zmlx.hg4idea.ui; import com.intellij.dvcs.DvcsRememberedInputs; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.editor.event.DocumentAdapter; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; @@ -151,24 +149,14 @@ public class HgPushDialog extends DialogWrapper { } public void updateRepository() { - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - @Override - public void run() { - final HgRepository repo = hgRepositorySelectorComponent.getRepository(); - final String defaultPath = HgUtil.getRepositoryDefaultPushPath(repo); - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - addPathsFromHgrc(repo.getRoot()); - if (defaultPath != null) { - updateRepositoryUrlText(HgUtil.removePasswordIfNeeded(defaultPath)); - myCurrentRepositoryUrl = defaultPath; - } - updateComboBoxes(repo); - } - }, ModalityState.stateForComponent(getRootPane())); - } - }); + HgRepository repo = hgRepositorySelectorComponent.getRepository(); + String defaultPath = HgUtil.getRepositoryDefaultPushPath(repo); + addPathsFromHgrc(repo.getRoot()); + if (defaultPath != null) { + updateRepositoryUrlText(HgUtil.removePasswordIfNeeded(defaultPath)); + myCurrentRepositoryUrl = defaultPath; + } + updateComboBoxes(repo); } private void updateComboBoxes(HgRepository repo) {