博客首页 注册 建议与交流 排行榜 加入友情链接         宝宝相册的专门空间
推荐 投诉 搜索: 帮助

流水孟春

以前使用的博客 webvista.cublog.cn
lib.cublog.cn
PHP&Java文档注释
    写文档是一项乏味却不得不做的工作,而编写API级的文档更是意味着大量的重复劳动和难以保持的一致性。
    使用文档注释的PHP或JAVA文件经过工具可以产生 列出类、方法、参数、和程序员所需要了解的其他信息,还可以自动处理各个class之间的关系,并据此生成class tree
   该类工具典型的有:phpDocumentor、javadoc。
 
要点:
    1.文档注释必须要加在声明之前才有意义,其他位置的文档注释将会被忽略。
    2.文档注释应该加在下秒几种描述的前面:
        》类
        》接口
        》方法
        》域
    3.文档注释的第一行是方法/类等的简要描述,这是文档注释的一种规则。
    4.要解析文档注释,生成文档的工具会查看“/**”之后以及“*/”之间的部分,其中每个“*”都代表了一行的开始。除了第一行,工具会忽略所有加在“*”之前的空格或制表符,其后的部分会生成html文档的一部分。
    5.文档注释应该以一个项目的概述作为起始部分。
    6.可以在注释中加入HTML标记。应该找出哪些标记在文本注释中可以正常使用。一般说来,改变字体的标记是没有问题的,但改变文本结构的标记则不能在文档注释中使用。
    7.所有javadoc/phpdoc标记都是一@作为开始字符,没个标记都必须开始于一个新行。
 
标记
 
@author  作者 默认忽略
@version 版本 默认忽略
@param   参数
@return  返回
@see     查看相关  @see 包.类名|@see 包.类名#域名|@see 包.类名#方法名(参数列表) php为 参考函数
{@link 名称标记}   内联超文本链接  {@link #link to}  => <a href="myclass.html#link">to</a>
@since   源自  源自≈php4|php5.1 说明当前代码从哪个版本开始可用
@deprecate 反对  用于描述那些只在早期版本中可用的包、类或方法,而目前由于他人还在使用,因此不能删除这些,这些在将来不可用。或 不建议使用的API
@var     类成员变量
@static  静态变量
@global  全局变量
@const   define定义的常量
 
@public
@private
@protected 
 
@serial 域描述
@serialField 域名 域类型 域描述
@serialData  数据描述
@abstract   to declare a method, class variable, or class that must be re-defined in a child class to be valid.
@access
@copyright
@example
@final
@filesource
@ignore
@license
@name
@internal
@staticvar
@subpackage
@package
@todo
@tutorial
@uses
 
 
例子
 
 

<?php
/**
 * File and input handling routines
 *
 * This class parses command-line options, and works with files to
 * generate lists of files to parse based on the ignore/include options
 *
 * phpDocumentor :: automatic documentation generator
 *
 * PHP versions 4 and 5
 *
 * Copyright (c) 2000-2006 Joshua Eichorn, Gregory Beaver
 *
 * LICENSE:
 *
 * This library is free software; you can redistribute it
 * and/or modify it under the terms of the GNU Lesser General
 * Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any
 * later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * @package phpDocumentor
 * @author Joshua Eichorn <jeichorn@phpdoc.org>
 * @author Gregory Beaver <cellog@php.net>
 * @copyright 2000-2006 Joshua Eichorn, Gregory Beaver
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @version CVS: $Id: Io.inc,v 1.12 2006/05/23 13:09:26 cellog Exp $
 * @filesource
 * @link http://www.phpdoc.org
 * @link http://pear.php.net/PhpDocumentor
 * @since 0.1
 */

/**
 * Class to handle file and user io opperations
 *
 * @author Joshua Eichorn <jeichorn@phpdoc.org>
 * @author Gregory Beaver <cellog@php.net>
 * @version $Id: Io.inc,v 1.12 2006/05/23 13:09:26 cellog Exp $
 * @package phpDocumentor
 */

class Io
{
    
    /**
     * Holds all the options that are avaible to the cmd line interface
     * and to the different web interfaces
     */

    var $phpDocOptions;
    /**
     * Format: array(array(regexp-ready string to search for whole path,
     * regexp-ready string to search for basename of ignore strings),...)
     * @var false|array
     */

    var $ignore = false;
 
    /**
     * creates an array $this->phpDocOptions and sets program options in it.
     * Array is in the format of:
     * <pre>
     * [filename][tag][] = "f";
     * [filename][tag][] = "-file";
     * [filename][desc] "name of file to parse"
     * </pre>
     */

    function Io()
    {
        $this->phpDocOptions['filename']['tag'] = array( "-f", "--filename");
        $this->phpDocOptions['filename']['desc'] = "name of file(s) to parse ',' file1,file2. Can contain complete path and * ? wildcards";
        $this->phpDocOptions['filename']['type'] = "path";
 
        $this->phpDocOptions['directory']['tag'] = array( "-d", "--directory");
        $this->phpDocOptions['directory']['desc'] = "name of a directory(s) to parse directory1,directory2";
        $this->phpDocOptions['directory']['type'] = "path";
 
        $this->phpDocOptions['examplesdir']['tag'] = array( "-ed", "--examplesdir");
        $this->phpDocOptions['examplesdir']['desc'] = "full path of the directory to look for example files from @example tags";
        $this->phpDocOptions['examplesdir']['type'] = "path";
 
        $this->phpDocOptions['templatebase']['tag'] = array( "-tb", "--templatebase");
        $this->phpDocOptions['templatebase']['desc'] = "base location of all templates for this parse.";
        $this->phpDocOptions['templatebase']['type'] = "path";
 
        $this->phpDocOptions['target']['tag'] = array("-t", "--target");
        $this->phpDocOptions['target']['desc'] = "path where to save the generated files";
        $this->phpDocOptions['target']['type'] = "path";
        
        $this->phpDocOptions['ignore']['tag'] = array("-i", "--ignore");
        $this->phpDocOptions['ignore']['desc'] = "file(s) that will be ignored, multiple separated by ','. Wildcards * and ? are ok";
        $this->phpDocOptions['ignore']['type'] = "path";
 
        $this->phpDocOptions['ignoretags']['tag'] = array("-it", "--ignore-tags");
        $this->phpDocOptions['ignoretags']['desc'] = "tags to ignore for this parse. @package, @subpackage, @access and @ignore may not be ignored.";
        $this->phpDocOptions['ignoretags']['type'] = "value";
 
        $this->phpDocOptions['hidden']['tag'] = array("-dh", "--hidden");
        $this->phpDocOptions['hidden']['desc'] = "set equal to on (-dh on) to descend into hidden directories (directories starting with '.'), default is off";
        $this->phpDocOptions['hidden']['type'] = "set";
        $this->phpDocOptions['hidden']['validvalues'] = array('on', 'off');
 
        $this->phpDocOptions['quiet']['tag'] = array("-q", "--quiet");
        $this->phpDocOptions['quiet']['desc'] = "do not display parsing/conversion messages. Useful for cron jobs on/off default off";
        $this->phpDocOptions['quiet']['type'] = "set";
        $this->phpDocOptions['quiet']['validvalues'] = array('on', 'off');
 
        $this->phpDocOptions['title']['tag'] = array("-ti","--title");
        $this->phpDocOptions['title']['desc'] = "title of generated documentation, default is 'Generated Documentation'";
        $this->phpDocOptions['title']['type'] = "value";
 
        $this->phpDocOptions['help']['tag'] = array("-h", "--help");
        $this->phpDocOptions['help']['desc'] = " show this help message";
 
        $this->phpDocOptions['useconfig']['tag'] = array("-c","--useconfig");
        $this->phpDocOptions['useconfig']['desc'] = "Use a Config file in the users/ subdirectory for all command-line options";
        $this->phpDocOptions['useconfig']['type'] = "value";
 
        $this->phpDocOptions['parseprivate']['tag'] = array("-pp","--parseprivate");
        $this->phpDocOptions['parseprivate']['desc'] = "parse @internal and elements marked private with @access. Use on/off, default off";
        $this->phpDocOptions['parseprivate']['type'] = "set";
        $this->phpDocOptions['parseprivate']['validvalues'] = array('on', 'off');
 
        $this->phpDocOptions['packageoutput']['tag'] = array("-po","--packageoutput");
        $this->phpDocOptions['packageoutput']['desc'] = "output documentation only for selected packages. Use a comma-delimited list";
        $this->phpDocOptions['packageoutput']['type'] = "value";
 
        $this->phpDocOptions['defaultpackagename']['tag'] = array("-dn","--defaultpackagename");
        $this->phpDocOptions['defaultpackagename']['desc'] = "name to use for the default package. If not specified, uses 'default'";
        $this->phpDocOptions['defaultpackagename']['type'] = "value";
 
        $this->phpDocOptions['defaultcategoryname']['tag'] = array("-dc","--defaultcategoryname");
        $this->phpDocOptions['defaultcategoryname']['desc'] = "name to use for the default category. If not specified, uses 'default'";
        $this->phpDocOptions['defaultcategoryname']['type'] = "value";
 
        $this->phpDocOptions['output']['tag'] = array("-o","--output");
        $this->phpDocOptions['output']['desc'] = "output information to use separated by ','. Format: output:converter:templatedir like \"HTML:frames:phpedit\"";
        $this->phpDocOptions['output']['type'] = "value";
 
        $this->phpDocOptions['converterparams']['tag'] = array("-cp","--converterparams");
        $this->phpDocOptions['converterparams']['desc'] = "dynamic parameters for a converter, separate values with commas";
        $this->phpDocOptions['converterparams']['type'] = "value";
 
        $this->phpDocOptions['customtags']['tag'] = array("-ct","--customtags");
        $this->phpDocOptions['customtags']['desc'] = "custom tags, will be recognized and put in tags[] instead of unknowntags[]";
        $this->phpDocOptions['customtags']['type'] = "value";
 
        $this->phpDocOptions['sourcecode']['tag'] = array("-s","--sourcecode");
        $this->phpDocOptions['sourcecode']['desc'] = "generate highlighted sourcecode for every parsed file (PHP 4.3.0+ only) on/off default off";
        $this->phpDocOptions['sourcecode']['type'] = "set";
        $this->phpDocOptions['sourcecode']['validvalues'] = array('on', 'off');
 
        $this->phpDocOptions['javadocdesc']['tag'] = array("-j","--javadocdesc");
        $this->phpDocOptions['javadocdesc']['desc'] = "JavaDoc-compliant description parsing. Use on/off, default off (more flexibility)";
        $this->phpDocOptions['javadocdesc']['type'] = "set";
        $this->phpDocOptions['javadocdesc']['validvalues'] = array('on', 'off');
 
        $this->phpDocOptions['pear']['tag'] = array("-p","--pear");
        $this->phpDocOptions['pear']['desc'] = "Parse a PEAR-style repository (package is directory, _members are @access private) on/off default off";
        $this->phpDocOptions['pear']['type'] = "set";
        $this->phpDocOptions['pear']['validvalues'] = array('on', 'off');
 
        $this->phpDocOptions['readmeinstallchangelog']['tag'] = array("-ric","--readmeinstallchangelog");
        $this->phpDocOptions['readmeinstallchangelog']['desc'] = "Specify custom filenames to parse like README, INSTALL or CHANGELOG files";
        $this->phpDocOptions['readmeinstallchangelog']['type'] = "value";
 
        $this->phpDocOptions['general']['message'] ="You can have multiple directories and multiple files, as well as a combination of both options";
    }
 
    
    /**
     * create the help message for display on the command-line
     * @return string a string containing a help message
     */

    function displayHelpMsg()
    {
        unset($ret);
        $ret = "\n";
        foreach($this->phpDocOptions as $data)
        {
            unset($tag);
            $tag = "";
            if (isset($data['tag']))
            {
                if (is_array($data['tag'])) {
                    foreach($data['tag'] as $param) {
                        $tag .= "$param ";
                    }
                }
        $taglen = 34;
        $outputwidth = 79;
        $tagspace = str_repeat(" ",$taglen);
                $tmp = " ".trim($tag).$tagspace;
                $tmp = substr($tmp,0,$taglen);
                $d = wordwrap(ltrim($data['desc']),($outputwidth-$taglen));
        $dt = explode("\n",$d);
        $dt[0] = $tmp .$dt[0];
        for($i=1;$i<count($dt);$i++)
        {
            $dt[$i] = $tagspace.$dt[$i];
        }
        $ret .= implode("\n",$dt)."\n\n";
        
            }
        }
        $ret .= "\n".wordwrap($data['message'],$outputwidth)."\n";
        return $ret;
    }
    
    /**
     * calls {@link file_exists()} for each value in include_path,
     * then calls {@link is_readable()} when it finds the file
     * @param string
     * @return boolean
     */

    function isIncludeable($filename)
    {
        $test = realpath($filename);
        if ($test && is_readable($test)) {
            return true; // for absolute paths

        }
        $ip = get_include_path();
        if (PHPDOCUMENTOR_WINDOWS)
        {
            $ip = explode(';', $ip);
        } else {
            $ip = explode(':', $ip)