diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesConfigurable.java b/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesConfigurable.java index 73868d233326..a0dcbb429518 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesConfigurable.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesConfigurable.java @@ -91,6 +91,10 @@ public class PostfixTemplatesConfigurable implements SearchableConfigurable, Edi for (LanguageExtensionPoint extension : extensions) { List postfixTemplates = ContainerUtil.newArrayList(((PostfixTemplateProvider)extension.getInstance()).getTemplates()); + if (postfixTemplates.isEmpty()) { + continue; + } + ContainerUtil.sort(postfixTemplates, TEMPLATE_COMPARATOR); templateMultiMap.putValues(extension.getKey(), postfixTemplates); diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java index 98a8d39ba5ac..2e375b7e5bef 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java @@ -110,7 +110,9 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel, C private void fillConfigurablesNames(Configurable[] configurables) { for (Configurable configurable : configurables) { - myConfigurablesNames.put(((SearchableConfigurable)configurable).getId(), configurable.getDisplayName()); + if (configurable instanceof SearchableConfigurable) { + myConfigurablesNames.put(((SearchableConfigurable)configurable).getId(), configurable.getDisplayName()); + } } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CollectionQueryCalledVisitor.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CollectionQueryCalledVisitor.java index 44400f7d4b91..688dd9976043 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CollectionQueryCalledVisitor.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CollectionQueryCalledVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,18 +48,7 @@ class CollectionQueryCalledVisitor extends JavaRecursiveElementVisitor { } super.visitForeachStatement(statement); final PsiExpression qualifier = statement.getIteratedValue(); - if (!(qualifier instanceof PsiReferenceExpression)) { - return; - } - final PsiReference referenceExpression = (PsiReference)qualifier; - final PsiElement referent = referenceExpression.resolve(); - if (referent == null) { - return; - } - if (!referent.equals(variable)) { - return; - } - queried = true; + checkExpression(qualifier); } @Override @@ -93,7 +82,7 @@ class CollectionQueryCalledVisitor extends JavaRecursiveElementVisitor { } final PsiExpression qualifier = methodExpression.getQualifierExpression(); - checkQualifier(qualifier); + checkExpression(qualifier); } @@ -104,10 +93,10 @@ class CollectionQueryCalledVisitor extends JavaRecursiveElementVisitor { if (methodName == null) { return; } - checkQualifier(expression.getQualifierExpression()); + checkExpression(expression.getQualifierExpression()); } - private void checkQualifier(PsiExpression expression) { + private void checkExpression(PsiExpression expression) { if (queried) { return; } @@ -125,17 +114,17 @@ class CollectionQueryCalledVisitor extends JavaRecursiveElementVisitor { else if (expression instanceof PsiParenthesizedExpression) { final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)expression; - checkQualifier(parenthesizedExpression.getExpression()); + checkExpression(parenthesizedExpression.getExpression()); } else if (expression instanceof PsiConditionalExpression) { final PsiConditionalExpression conditionalExpression = (PsiConditionalExpression)expression; final PsiExpression thenExpression = conditionalExpression.getThenExpression(); - checkQualifier(thenExpression); + checkExpression(thenExpression); final PsiExpression elseExpression = conditionalExpression.getElseExpression(); - checkQualifier(elseExpression); + checkExpression(elseExpression); } } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/mismatched_collection_query_update/MismatchedCollectionQueryUpdate.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/mismatched_collection_query_update/MismatchedCollectionQueryUpdate.java index 27890a09b757..373b75fcec83 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/mismatched_collection_query_update/MismatchedCollectionQueryUpdate.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/mismatched_collection_query_update/MismatchedCollectionQueryUpdate.java @@ -207,4 +207,14 @@ class MethReference { map.put(1, true); I mapper = map::get; } + + void foo(int a,Collection b) { + final ArrayList x = new ArrayList(); + x.add("1"); + + for (Object o : a>0? b : x) + { + System.out.println(o); + } + } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgWorkingCopyRevisionsCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgWorkingCopyRevisionsCommand.java index 942ef37a4cf5..263263879b79 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgWorkingCopyRevisionsCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgWorkingCopyRevisionsCommand.java @@ -25,7 +25,6 @@ import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.HgRevisionNumber; import org.zmlx.hg4idea.execution.HgCommandExecutor; import org.zmlx.hg4idea.execution.HgCommandResult; -import org.zmlx.hg4idea.execution.HgRemoteCommandExecutor; import org.zmlx.hg4idea.util.HgChangesetUtil; import org.zmlx.hg4idea.util.HgUtil; @@ -137,7 +136,7 @@ public class HgWorkingCopyRevisionsCommand { */ @NotNull public Couple identify(@NotNull VirtualFile repo) { - HgRemoteCommandExecutor commandExecutor = new HgRemoteCommandExecutor(myProject); + HgCommandExecutor commandExecutor = new HgCommandExecutor(myProject); commandExecutor.setSilent(true); HgCommandResult result = commandExecutor.executeInCurrentThread(repo, "identify", Arrays.asList("--num", "--id")); if (result == null) { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandExecutor.java b/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandExecutor.java index 4e2fe4f89b7f..7cf8f65559ea 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandExecutor.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandExecutor.java @@ -147,14 +147,15 @@ public class HgCommandExecutor { cmdLine.add(HgEncodingUtil.getNameFor(myCharset)); } - HgCommandResult result; try { String workingDir = repo != null ? repo.getPath() : null; ShellCommand shellCommand = new ShellCommand(cmdLine, workingDir, myCharset); long startTime = System.currentTimeMillis(); LOG.debug(String.format("hg %s started", operation)); - result = shellCommand.execute(myShowOutput); + HgCommandResult result = shellCommand.execute(myShowOutput); LOG.debug(String.format("hg %s finished. Took %s ms", operation, System.currentTimeMillis() - startTime)); + logResult(result); + return result; } catch (ShellCommandException e) { if (myVcs.getExecutableValidator().checkExecutableAndNotifyIfNeeded()) { @@ -168,9 +169,6 @@ public class HgCommandExecutor { LOG.info(e.getMessage(), e); return null; } - - logResult(result); - return result; } // logging to the Version Control console (without extensions and configs) diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandResult.java b/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandResult.java index 8ef1a7001540..dd9b00ed990e 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandResult.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandResult.java @@ -20,7 +20,6 @@ import java.util.List; public final class HgCommandResult { - public static final HgCommandResult EMPTY = new HgCommandResult(new StringWriter(), new StringWriter(), 0); public static final HgCommandResult CANCELLED = new HgCommandResult(new StringWriter(), new StringWriter(), 1); private final StringWriter out; @@ -29,7 +28,6 @@ public final class HgCommandResult { private List outLines; private List errLines; - private String warnings; public HgCommandResult(StringWriter out, StringWriter err, int exitValue) { this.out = out; @@ -54,7 +52,7 @@ public final class HgCommandResult { public String getRawOutput() { return out.toString(); } - + public String getRawError() { return err.toString(); } @@ -62,12 +60,4 @@ public final class HgCommandResult { public int getExitValue() { return exitValue; } - - void setWarnings(String warnings) { - this.warnings = warnings; - } - - public String getWarnings() { - return warnings; - } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgPromptCommandExecutor.java b/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgPromptCommandExecutor.java index bbb9a26209a4..b6863f21a534 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgPromptCommandExecutor.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgPromptCommandExecutor.java @@ -18,6 +18,7 @@ package org.zmlx.hg4idea.execution; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,7 +28,6 @@ import java.io.DataOutputStream; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.net.Socket; -import java.util.LinkedList; import java.util.List; public class HgPromptCommandExecutor extends HgCommandExecutor { @@ -41,61 +41,32 @@ public class HgPromptCommandExecutor extends HgCommandExecutor { public HgCommandResult executeInCurrentThread(@Nullable final VirtualFile repo, @NotNull final String operation, @Nullable final List arguments) { - - final List cmdLine = new LinkedList(); - WarningReceiver warningReceiver = new WarningReceiver(); SocketServer promptServer = new SocketServer(new PromptReceiver(new HgDeleteModifyPromptHandler())); - SocketServer warningServer = new SocketServer(warningReceiver); - - try { int promptPort = promptServer.start(); - int warningPort = warningServer.start(); - cmdLine.add("--config"); - cmdLine.add("extensions.hg4ideapromptextension=" + myVcs.getPromptHooksExtensionFile().getAbsolutePath()); - cmdLine.add("--config"); - cmdLine.add("hg4ideaprompt.port=" + promptPort); - cmdLine.add("--config"); - cmdLine.add("hg4ideawarn.port=" + warningPort); + return super.executeInCurrentThread(repo, operation, prepareArguments(arguments, promptPort)); } catch (IOException e) { showError(e); LOG.info("IOException during preparing command", e); - promptServer.stop(); - warningServer.stop(); return null; } - - if (arguments != null && arguments.size() != 0) { - cmdLine.addAll(arguments); + finally { + promptServer.stop(); } - - HgCommandResult result = super.executeInCurrentThread(repo, operation, cmdLine); - promptServer.stop(); - warningServer.stop(); - String warnings = warningReceiver.getWarnings(); - result.setWarnings(warnings); - return result; } - private static class WarningReceiver extends SocketServer.Protocol { - private StringBuffer warnings = new StringBuffer(); + private List prepareArguments(List arguments, int port) { + List cmdArguments = ContainerUtil.newArrayList(); + cmdArguments.add("--config"); + cmdArguments.add("extensions.hg4ideapromptextension=" + myVcs.getPromptHooksExtensionFile().getAbsolutePath()); + cmdArguments.add("--config"); + cmdArguments.add("hg4ideaprompt.port=" + port); - public boolean handleConnection(Socket socket) throws IOException { - //noinspection IOResourceOpenedButNotSafelyClosed - DataInputStream dataInput = new DataInputStream(socket.getInputStream()); - - int numOfWarnings = dataInput.readInt(); - for (int i = 0; i < numOfWarnings; i++) { - warnings.append(new String(readDataBlock(dataInput))); - } - return true; - } - - - public String getWarnings() { - return warnings.toString(); + if (arguments != null && arguments.size() != 0) { + cmdArguments.addAll(arguments); } + return cmdArguments; } private static class PromptReceiver extends SocketServer.Protocol { @@ -132,7 +103,7 @@ public class HgPromptCommandExecutor extends HgCommandExecutor { choicePresentationArray[i] = choices[i].toString(); } index[0] = Messages - .showDialog(message, "Hg4idea", + .showDialog(message, "Mercurial Prompt Message", choicePresentationArray, defaultChoice.getChosenIndex(), Messages.getQuestionIcon()); } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgRemoteCommandExecutor.java b/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgRemoteCommandExecutor.java index 95684de94761..fdab67fbed6f 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgRemoteCommandExecutor.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgRemoteCommandExecutor.java @@ -15,6 +15,7 @@ package org.zmlx.hg4idea.execution; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.action.HgCommandResultNotifier; @@ -24,17 +25,12 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.net.Socket; -import java.util.LinkedList; import java.util.List; public class HgRemoteCommandExecutor extends HgCommandExecutor { @Nullable private ModalityState myState; - public HgRemoteCommandExecutor(@NotNull Project project) { - this(project, null); - } - public HgRemoteCommandExecutor(@NotNull Project project, @Nullable String destination) { this(project, destination, null); } @@ -65,43 +61,49 @@ public class HgRemoteCommandExecutor extends HgCommandExecutor { } @Nullable - public HgCommandResult executeInCurrentThread(@Nullable final VirtualFile repo, + private HgCommandResult executeInCurrentThread(@Nullable final VirtualFile repo, @NotNull final String operation, @Nullable final List arguments, boolean forceAuthorization) { - final List cmdLine = new LinkedList(); PassReceiver passReceiver = new PassReceiver(myProject, forceAuthorization, myState); SocketServer passServer = new SocketServer(passReceiver); - try { int passPort = passServer.start(); - cmdLine.add("--config"); - cmdLine.add("extensions.hg4ideapromptextension=" + myVcs.getPromptHooksExtensionFile().getAbsolutePath()); - - cmdLine.add("--config"); - cmdLine.add("hg4ideapass.port=" + passPort); + HgCommandResult result = super.executeInCurrentThread(repo, operation, prepareArguments(arguments, passPort)); + if (!HgErrorUtil.isAuthorizationError(result)) { + passReceiver.saveCredentials(); + } + return result; } catch (IOException e) { showError(e); LOG.info("IOException during preparing command", e); - passServer.stop(); return null; } - if (arguments != null && arguments.size() != 0) { - cmdLine.addAll(arguments); + finally { + passServer.stop(); } - - HgCommandResult result; - - result = super.executeInCurrentThread(repo, operation, cmdLine); - if (!HgErrorUtil.isAuthorizationError(result)) { - passReceiver.saveCredentials(); - } - passServer.stop(); - return result; } + private List prepareArguments(List arguments, int port) { + List cmdArguments = ContainerUtil.newArrayList(); + cmdArguments.add("--config"); + cmdArguments.add("extensions.hg4ideapromptextension=" + myVcs.getPromptHooksExtensionFile().getAbsolutePath()); + cmdArguments.add("--config"); + cmdArguments.add("hg4ideapass.port=" + port); + + if (arguments != null && arguments.size() != 0) { + cmdArguments.addAll(arguments); + } + return cmdArguments; + } + + @Override + protected void logCommand(@NotNull String operation, @Nullable List arguments) { + //do not log arguments for remote command because of internal password port info etc + super.logCommand(operation, null); + } private static class PassReceiver extends SocketServer.Protocol { private final Project myProject; diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java index 92a525320bec..e88b1947f4a8 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java @@ -263,7 +263,8 @@ public class HgRegularUpdater implements HgUpdater { HgRevisionNumber parentBeforeUpdate = new HgWorkingCopyRevisionsCommand(project).firstParent(repo); HgUpdateCommand hgUpdateCommand = new HgUpdateCommand(project, repo); - String warningMessages = ensureSuccess(hgUpdateCommand.execute()).getWarnings(); + HgCommandResult updateResult = hgUpdateCommand.execute(); + String warningMessages = ensureSuccess(updateResult).getRawError(); handlePossibleWarning(warnings, warningMessages); HgRevisionNumber parentAfterUpdate = new HgWorkingCopyRevisionsCommand(project).firstParent(repo);