Collection<String> (@NotNull final PyExpression expression) { Collection<String> candidates = generateSuggestedNames(expression); Collection<String> res = new ArrayList<>(); for (String name : candidates) { if (myValidator.checkPossibleName(name, expression)) { res.add(name); } } if (res.isEmpty()) { // no available names found, generate disambiguated suggestions for (String name : candidates) { int index = 1; while (!myValidator.checkPossibleName(name + index, expression)) { index++; } res.add(name + index); } } return res; }