String (String base, PsiField[] fields) { String id = base; int index = 0; while (true) { if (index > 0) { id = base + index; } index++; boolean anyEqual = false; for (PsiField equalsField : fields) { if (id.equals(equalsField.getName())) { anyEqual = true; break; } } if (!anyEqual) break; } return id; }