From 7a42ca211d4f441b1e2924c3df67e5ac9e43bab4 Mon Sep 17 00:00:00 2001 From: Jack Zhou Date: Sun, 21 Apr 2013 16:56:11 -0400 Subject: [PATCH] Create from usage: Changed type order to prefer substituted versions. --- .../quickfix/CreateMethodFromUsageFix.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/CreateMethodFromUsageFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/CreateMethodFromUsageFix.java index 9e05f4fc930..61083bad78d 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/CreateMethodFromUsageFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/CreateMethodFromUsageFix.java @@ -174,8 +174,8 @@ public class CreateMethodFromUsageFix extends CreateFromUsageFixBase { } @NotNull - private Collection getPossibleTypes(BindingContext context) { - Collection types = new ArrayList(); + private List getPossibleTypes(BindingContext context) { + List types = new ArrayList(); if (isType()) { assert type != null : "!isType() means type == null && expressionOfType != null"; types.add(type); @@ -208,7 +208,8 @@ public class CreateMethodFromUsageFix extends CreateFromUsageFixBase { @NotNull TypeSubstitution[] substitutions, @NotNull JetScope scope ) { - Collection types = getPossibleTypes(context); + List types = getPossibleTypes(context); + Collections.reverse(types); // reverse and reverse back later, so that things added below are added at the front Set newTypes = new LinkedHashSet(types); for (TypeSubstitution substitution : substitutions) { // each substitution can be applied or not, so we offer all options @@ -229,13 +230,11 @@ public class CreateMethodFromUsageFix extends CreateFromUsageFixBase { newTypes.add(KotlinBuiltIns.getInstance().getAnyType()); } - types = newTypes; - - typeCandidates = new TypeCandidate[types.size()]; - int i = 0; - for (JetType type : types) { + typeCandidates = new TypeCandidate[newTypes.size()]; + int i = typeCandidates.length - 1; // reverse order (see explanation above) + for (JetType type : newTypes) { typeCandidates[i] = new TypeCandidate(type, scope); - i++; + i--; } }