0

我在使用GroovyDocTool时遇到了困难。

无论我传入什么路径,我rootDoc都不会解析为任何包、类或方法。我不得不假设我只是在错误的道路上经过,但对于我的生活来说,我无法弄清楚要经过什么。

class TestGroovyDoclet extends GroovyDocTool{
    public TestGroovyDoclet() {
        super([
            '~/ ... /src/'
            ,'/home/ ... /src/ ... /Sample/'
            ,'/home/ ... /src/ ... /Sample/Results.groovy'
        ]);
    }
    public void Execute(){
        System.out.println('Begin Processing Javadoc');
        System.out.format(' p %d\n', rootDoc.specifiedPackages().length);
        System.out.format(' c %d\n', rootDoc.classes().length);
        System.out.println('Finished Processing Javadoc');
    }
    public static void main(String[] args){
        (new TestGroovyDoclet()).with{
            it.Execute();
        }
    }
}

什么被认为是传递给的有效参数GroovyRootDocBuilder

4

1 回答 1

0

GroovyDoc 的作者似乎打算从 Ant 中使用它。这意味着无法查找要处理的文件,因为您应该已经知道正在处理的文件。消费者必须指定要处理的单个文件,调用buildPath以实际处理这些文件。(见覆盖buildPath

对于那些只想与文档树交互的人来说,GroovyDocTool这真的没有任何价值,用户可能会更好地扩展GroovyRootDocBuilder它实际上包含处理的内容。如果你这样做,你还不如重新编写构造函数以GroovyDocTool完全隐藏起来。(参见新的构造函数)

class TestGroovyDoclet extends GroovyRootDocBuilder{
    protected def sourcepaths = [];
    public TestGroovyDoclet() {
        //HARDCODE: some test values for my testing
        this([
            '~/ ... /src/'
            ,'/home/ ... /src/ ... /Sample/'
            ,'/home/ ... /src/ ... /Sample/Results.groovy'
        ]);
    }
    public TestGroovyDoclet(String[] sourcepaths) {
        //hide the unused GroovyDocTool
        super(new GroovyDocTool(), sourcepaths, new ArrayList<LinkArgument>(), new Properties());
        this.sourcepaths = sourcepaths;
    }
    /**
     * Builds the tree by recursively searching for files
     * <p>
     * It is likely useful to override the original buildTree 
     * method as well to put some safeties in place. The parsing 
     * routines do not do a lot of validation. For those of us 
     * inheritting, it would be a good idea to override build 
     * tree ot sanitize the input list as much as possible.
     * </p>
     */
    @Override
    public void buildTree(){
        def list = [];
        // loop through the sourcepaths to recursively find the files
        for (String sourcepath : sourcepaths) {
            def root = new File(sourcepath);
            if(root.exists()){
                if(root.isFile()){
                    list << root.absolutePath;
                }
                else{
                    root.eachFileRecurse (FileType.FILES) { file -> list << file.absolutePath; };
                }
            }
        }
        buildTree(list);
    }
    /**
     * Method to actually do the processing. Sample only, does not demonstrate anything useful.
     */
    public void Execute(){
        buildTree();
        System.out.println('Begin Processing GroovyDoc');
        System.out.format(' p %d\n', rootDoc.specifiedPackages().length);
        //System.out.format(' c %d\n', rootDoc.classes().length);
        int count = 0;
        for(def p : rootDoc.specifiedPackages()){
            count += p.allClasses().length;
        }
        System.out.format(' c %d\n', count);

        System.out.println('Finished Processing GroovyDoc');
    }

    public static void main(String[] args){
        (new TestGroovyDoclet()).with{
            it.Execute();
        }
    }
}

上面的代码并不完美,也不完全是我想出的;相反,该代码旨在突出显示 OP 中包含的一些错误假设,以及解决这些假设的机制。不保证编译,因为它只是剪切/粘贴较大重写的元素。

怪异:

  1. 有趣的是GroovyRootDoc.classes总是返回null(不确定为什么)。有必要遍历每个包,并检查作为每个包子集的类。这令人惊讶,但无论如何都是理想的用法。
  2. 上面的代码仅适用于 groovy 文件,不适用于 java。我认为 GroovyDoc 对一些 java1.8 语法感到窒息(但我不确定)。
于 2016-01-31T14:59:15.297 回答