Create from usage: Extracted method from getNextAvailableName.

This commit is contained in:
Jack Zhou
2013-05-28 16:57:26 -07:00
parent 12aa90f564
commit a91a2efc75
@@ -1128,14 +1128,18 @@ public class CreateFunctionFromUsageFix extends CreateFromUsageFixBase {
*/
@NotNull
private static String getNextAvailableName(@NotNull String name, @NotNull Collection<String> existingNames, @Nullable JetScope scope) {
if (existingNames.contains(name) || (scope != null && scope.getClassifier(Name.identifier(name)) != null)) {
if (isConflictingName(name, existingNames, scope)) {
int j = 1;
while (existingNames.contains(name + j) || (scope != null && scope.getClassifier(Name.identifier(name + j)) != null)) j++;
while (isConflictingName(name + j, existingNames, scope)) j++;
name += j;
}
return name;
}
private static boolean isConflictingName(@NotNull String name, @NotNull Collection<String> existingNames, @Nullable JetScope scope) {
return existingNames.contains(name) || (scope != null && scope.getClassifier(Name.identifier(name)) != null);
}
@NotNull
private static JetType[] guessTypesForExpression(@NotNull JetExpression expr, @NotNull BindingContext context) {
JetType type = context.get(BindingContext.EXPRESSION_TYPE, expr);