PsiVariable (String variableNameRoot, PsiExpression iteratedValue, PsiElement context) { final String variableName = createVariableName(variableNameRoot, iteratedValue); final Project project = context.getProject(); final PsiType iteratedValueType = iteratedValue.getType(); assert iteratedValueType != null; final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); final PsiDeclarationStatement declarationStatement = elementFactory.createVariableDeclarationStatement(variableName, iteratedValueType, iteratedValue); return (PsiVariable)declarationStatement.getDeclaredElements()[0]; }