From aa77b2e88f6407cfa3cf0cb47fdb4cbb9548f1cd Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 24 Aug 2015 19:54:29 +0300 Subject: [PATCH] ensure sort order as chooser preserves user's selection order (EA-47464 - AIOOBE: DelegateWithDefaultParamValueIntentionAction.generateMethodPrototype) --- ...gateWithDefaultParamValueIntentionAction.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DelegateWithDefaultParamValueIntentionAction.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DelegateWithDefaultParamValueIntentionAction.java index 52c355364fd0..fdec4a6b1910 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DelegateWithDefaultParamValueIntentionAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DelegateWithDefaultParamValueIntentionAction.java @@ -43,6 +43,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.Arrays; +import java.util.Comparator; import java.util.HashSet; /** @@ -91,9 +92,18 @@ public class DelegateWithDefaultParamValueIntentionAction extends PsiElementBase prototype.getModifierList().setModifierProperty(PsiModifier.DEFAULT, true); } - for (int i = params.length - 1; i >= 0; i--) { - PsiParameter param = params[i]; - final int parameterIndex = method.getParameterList().getParameterIndex(param); + final PsiParameterList parameterList = method.getParameterList(); + Arrays.sort(params, new Comparator() { + @Override + public int compare(PsiParameter p1, PsiParameter p2) { + final int parameterIndex1 = parameterList.getParameterIndex(p1); + final int parameterIndex2 = parameterList.getParameterIndex(p2); + return parameterIndex1 > parameterIndex2 ? -1 : 1; + } + }); + + for (PsiParameter param : params) { + final int parameterIndex = parameterList.getParameterIndex(param); prototype.getParameterList().getParameters()[parameterIndex].delete(); } return prototype;