@Override public String suggestUniqueVariableName(String baseName, PsiElement place, boolean lookForward) { int index = 0; PsiElement scope = PsiTreeUtil.getNonStrictParentOfType( place, PsiStatement.class, PsiCodeBlock.class, PsiMethod.class); NextName: while (true) { String name = baseName; if (index > 0) { name += index; } index++; if (PsiUtil.isVariableNameUnique(name, place)) { if (lookForward) { final String name1 = name; PsiElement run = scope; while (run != null) { class CancelException extends RuntimeException {} try { run.accept( new JavaRecursiveElementWalkingVisitor() { @Override public void visitAnonymousClass(final PsiAnonymousClass aClass) {} @Override public void visitVariable(PsiVariable variable) { if (name1.equals(variable.getName())) { throw new CancelException(); } } }); } catch (CancelException e) { continue NextName; } run = run.getNextSibling(); if (scope instanceof PsiMethod) { // do not check next member for param name conflict break; } } } return name; } } }