diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/CreateFunctionFromUsageFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/CreateFunctionFromUsageFix.java index e5c1248c1c5..c9b11ece4da 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/CreateFunctionFromUsageFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/CreateFunctionFromUsageFix.java @@ -416,7 +416,7 @@ public class CreateFunctionFromUsageFix extends CreateFromUsageFixBase { // ensure there are no conflicts List lookupElements = new ArrayList(); for (String name : names) { - name = getNextAvailableName(name, parameterNames); + name = getNextAvailableName(name, parameterNames, null); lookupElements.add(LookupElementBuilder.create(name)); } @@ -1123,21 +1123,16 @@ public class CreateFunctionFromUsageFix extends CreateFromUsageFixBase { return typeParameters; } + /** + * Returns the given name, appended with a number if it is one of the existingNames or already exists in + * scope. For example, given "foo", returns the next non-conflicting name in the list "foo", + * "foo1", "foo2", etc. + */ @NotNull - private static String getNextAvailableName(@NotNull String name, @NotNull Collection existingNames) { - if (existingNames.contains(name)) { + private static String getNextAvailableName(@NotNull String name, @NotNull Collection existingNames, @Nullable JetScope scope) { + if (existingNames.contains(name) || (scope != null && scope.getClassifier(Name.identifier(name)) != null)) { int j = 1; - while (existingNames.contains(name + j)) j++; - name += j; - } - return name; - } - - @NotNull - private static String getNextAvailableName(@NotNull String name, @NotNull Collection existingNames, @NotNull JetScope scope) { - if (existingNames.contains(name) || scope.getClassifier(Name.identifier(name)) != null) { - int j = 1; - while (existingNames.contains(name + j) || scope.getClassifier(Name.identifier(name + j)) != null) j++; + while (existingNames.contains(name + j) || (scope != null && scope.getClassifier(Name.identifier(name + j)) != null)) j++; name += j; } return name;