String (PsiElement context) { final Project project = context.getProject(); final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); final PsiElementFactory factory = facade.getElementFactory(); final GlobalSearchScope scope = GlobalSearchScope.allScope(project); final PsiClass iteratorClass = facade.findClass(CommonClassNames.JAVA_UTIL_ITERATOR, scope); if (iteratorClass == null) { return "iterator"; } final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project); final PsiType iteratorType = factory.createType(iteratorClass); final SuggestedNameInfo baseNameInfo = codeStyleManager.suggestVariableName( VariableKind.LOCAL_VARIABLE, null, null, iteratorType); final SuggestedNameInfo nameInfo = codeStyleManager.suggestUniqueVariableName(baseNameInfo, context, true); if (nameInfo.names.length == 0) { return "iterator"; } return nameInfo.names[0]; }