langtools/test/tools/javac/doctree/DocCommentTester.java
author ksrini
Tue, 15 Aug 2017 13:16:32 -0700
changeset 46184 f1325703ea85
parent 42831 feff6f296019
permissions -rw-r--r--
8173425: Javadoc needs a new tag to specify the summary. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     1
/*
46184
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
     2
 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     4
 *
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     8
 *
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    13
 * accompanied this code).
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    14
 *
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    18
 *
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    21
 * questions.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    22
 */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    23
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    24
import java.io.File;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    25
import java.io.FileWriter;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    26
import java.io.IOException;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    27
import java.io.PrintWriter;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    28
import java.io.StringWriter;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    29
import java.io.Writer;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    30
import java.text.BreakIterator;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    31
import java.util.ArrayList;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    32
import java.util.Arrays;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    33
import java.util.List;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    34
import java.util.Locale;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    35
import java.util.regex.Matcher;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    36
import java.util.regex.Pattern;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    37
import java.util.stream.Collectors;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    38
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    39
import javax.lang.model.element.Name;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    40
import javax.tools.JavaFileObject;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    41
import javax.tools.StandardJavaFileManager;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    42
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    43
import com.sun.source.doctree.*;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    44
import com.sun.source.tree.ClassTree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    45
import com.sun.source.tree.CompilationUnitTree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    46
import com.sun.source.tree.MethodTree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    47
import com.sun.source.tree.Tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    48
import com.sun.source.tree.VariableTree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    49
import com.sun.source.util.DocTreeScanner;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    50
import com.sun.source.util.DocTrees;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    51
import com.sun.source.util.JavacTask;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    52
import com.sun.source.util.TreePath;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    53
import com.sun.source.util.TreePathScanner;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    54
import com.sun.tools.javac.api.JavacTool;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    55
import com.sun.tools.javac.tree.DCTree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    56
import com.sun.tools.javac.tree.DCTree.DCDocComment;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    57
import com.sun.tools.javac.tree.DCTree.DCErroneous;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    58
import com.sun.tools.javac.tree.DocPretty;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    59
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    60
public class DocCommentTester {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    61
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    62
    public static final String BI_MARKER = "BREAK_ITERATOR";
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    63
    public final boolean useBreakIterator;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    64
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    65
    public DocCommentTester(boolean useBreakIterator) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    66
        this.useBreakIterator = useBreakIterator;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    67
    }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    68
    public static void main(String... args) throws Exception {
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    69
        ArrayList<String> list = new ArrayList(Arrays.asList(args));
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    70
        if (!list.isEmpty() && "-useBreakIterator".equals(list.get(0))) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    71
            list.remove(0);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    72
            new DocCommentTester(true).run(list);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    73
        } else {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    74
            new DocCommentTester(false).run(list);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    75
        }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    76
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    77
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    78
    public void run(List<String> args) throws Exception {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    79
        String testSrc = System.getProperty("test.src");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    80
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    81
        List<File> files = args.stream()
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    82
                .map(arg -> new File(testSrc, arg))
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    83
                .collect(Collectors.toList());
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    84
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    85
        JavacTool javac = JavacTool.create();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    86
        StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    87
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    88
        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    89
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    90
        JavacTask t = javac.getTask(null, fm, null, null, null, fos);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    91
        final DocTrees trees = DocTrees.instance(t);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    92
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    93
        if (useBreakIterator) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    94
            // BreakIterators are locale dependent wrt. behavior
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    95
            trees.setBreakIterator(BreakIterator.getSentenceInstance(Locale.ENGLISH));
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    96
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    97
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    98
        final Checker[] checkers = {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    99
            new ASTChecker(this, trees),
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   100
            new PosChecker(this, trees),
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   101
            new PrettyChecker(this, trees)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   102
        };
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   103
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   104
        DeclScanner d = new DeclScanner() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   105
            @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   106
            public Void visitCompilationUnit(CompilationUnitTree tree, Void ignore) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   107
                for (Checker c: checkers)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   108
                    c.visitCompilationUnit(tree);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   109
                return super.visitCompilationUnit(tree, ignore);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   110
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   111
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   112
            @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   113
            void visitDecl(Tree tree, Name name) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   114
                TreePath path = getCurrentPath();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   115
                String dc = trees.getDocComment(path);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   116
                if (dc != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   117
                    for (Checker c : checkers) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   118
                        try {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   119
                            System.err.println(path.getLeaf().getKind()
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   120
                                    + " " + name
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   121
                                    + " " + c.getClass().getSimpleName());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   122
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   123
                            c.check(path, name);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   124
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   125
                            System.err.println();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   126
                        } catch (Exception e) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   127
                            error("Exception " + e);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   128
                            e.printStackTrace(System.err);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   129
                        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   130
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   131
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   132
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   133
        };
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   134
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   135
        Iterable<? extends CompilationUnitTree> units = t.parse();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   136
        for (CompilationUnitTree unit: units) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   137
            d.scan(unit, null);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   138
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   139
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   140
        if (errors > 0)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   141
            throw new Exception(errors + " errors occurred");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   142
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   143
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   144
    static abstract class DeclScanner extends TreePathScanner<Void, Void> {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   145
        abstract void visitDecl(Tree tree, Name name);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   146
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   147
        @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   148
        public Void visitClass(ClassTree tree, Void ignore) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   149
            super.visitClass(tree, ignore);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   150
            visitDecl(tree, tree.getSimpleName());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   151
            return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   152
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   153
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   154
        @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   155
        public Void visitMethod(MethodTree tree, Void ignore) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   156
            super.visitMethod(tree, ignore);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   157
            visitDecl(tree, tree.getName());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   158
            return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   159
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   160
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   161
        @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   162
        public Void visitVariable(VariableTree tree, Void ignore) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   163
            super.visitVariable(tree, ignore);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   164
            visitDecl(tree, tree.getName());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   165
            return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   166
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   167
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   168
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   169
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   170
     * Base class for checkers to check the doc comment on a declaration
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   171
     * (when present.)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   172
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   173
    abstract class Checker {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   174
        final DocTrees trees;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   175
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   176
        Checker(DocTrees trees) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   177
            this.trees = trees;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   178
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   179
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   180
        void visitCompilationUnit(CompilationUnitTree tree) { }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   181
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   182
        abstract void check(TreePath tree, Name name) throws Exception;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   183
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   184
        void error(String msg) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   185
            DocCommentTester.this.error(msg);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   186
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   187
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   188
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   189
    void error(String msg) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   190
        System.err.println("Error: " + msg);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   191
        errors++;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   192
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   193
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   194
    int errors;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   195
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   196
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   197
     * Verify the structure of the DocTree AST by comparing it against golden text.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   198
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   199
    static class ASTChecker extends Checker {
14551
a47974703e03 8003649: regression/langtools: tools/javac/doctree
jjg
parents: 14541
diff changeset
   200
        static final String NEWLINE = System.getProperty("line.separator");
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   201
        Printer printer = new Printer();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   202
        String source;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   203
        DocCommentTester test;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   204
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   205
        ASTChecker(DocCommentTester test, DocTrees t) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   206
            test.super(t);
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   207
            this.test = test;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   208
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   209
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   210
        @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   211
        void visitCompilationUnit(CompilationUnitTree tree) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   212
            try {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   213
                source = tree.getSourceFile().getCharContent(true).toString();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   214
            } catch (IOException e) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   215
                source = "";
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   216
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   217
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   218
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   219
        void check(TreePath path, Name name) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   220
            StringWriter out = new StringWriter();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   221
            DocCommentTree dc = trees.getDocCommentTree(path);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   222
            printer.print(dc, out);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   223
            out.flush();
14551
a47974703e03 8003649: regression/langtools: tools/javac/doctree
jjg
parents: 14541
diff changeset
   224
            String found = out.toString().replace(NEWLINE, "\n");
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   225
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   226
            /*
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   227
             * Look for the first block comment after the first occurrence
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   228
             * of name, noting that, block comments with BI_MARKER may
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   229
             * very well be present.
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   230
             */
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   231
            int start = test.useBreakIterator
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   232
                    ? source.indexOf("\n/*\n" + BI_MARKER + "\n", findName(source, name))
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   233
                    : source.indexOf("\n/*\n", findName(source, name));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   234
            int end = source.indexOf("\n*/\n", start);
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   235
            int startlen = start + (test.useBreakIterator ? BI_MARKER.length() + 1 : 0) + 4;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   236
            String expect = source.substring(startlen, end + 1);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   237
            if (!found.equals(expect)) {
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   238
                if (test.useBreakIterator) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   239
                    System.err.println("Using BreakIterator");
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   240
                }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   241
                System.err.println("Expect:\n" + expect);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   242
                System.err.println("Found:\n" + found);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   243
                error("AST mismatch for " + name);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   244
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   245
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   246
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   247
        /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   248
         * This main program is to set up the golden comments used by this
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   249
         * checker.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   250
         * Usage:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   251
         *     java DocCommentTester$ASTChecker -o dir file...
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   252
         * The given files are written to the output directory with their
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   253
         * golden comments updated. The intent is that the files should
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   254
         * then be compared with the originals, e.g. with meld, and if the
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   255
         * changes are approved, the new files can be used to replace the old.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   256
         */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   257
        public static void main(String... args) throws Exception {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   258
            List<File> files = new ArrayList<File>();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   259
            File o = null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   260
            for (int i = 0; i < args.length; i++) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   261
                String arg = args[i];
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   262
                if (arg.equals("-o"))
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   263
                    o = new File(args[++i]);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   264
                else if (arg.startsWith("-"))
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   265
                    throw new IllegalArgumentException(arg);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   266
                else {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   267
                    files.add(new File(arg));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   268
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   269
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   270
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   271
            if (o == null)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   272
                throw new IllegalArgumentException("no output dir specified");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   273
            final File outDir = o;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   274
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   275
            JavacTool javac = JavacTool.create();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   276
            StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   277
            Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   278
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   279
            JavacTask t = javac.getTask(null, fm, null, null, null, fos);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   280
            final DocTrees trees = DocTrees.instance(t);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   281
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   282
            DeclScanner d = new DeclScanner() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   283
                Printer p = new Printer();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   284
                String source;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   285
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   286
                @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   287
                public Void visitCompilationUnit(CompilationUnitTree tree, Void ignore) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   288
                    System.err.println("processing " + tree.getSourceFile().getName());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   289
                    try {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   290
                        source = tree.getSourceFile().getCharContent(true).toString();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   291
                    } catch (IOException e) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   292
                        source = "";
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   293
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   294
                    // remove existing gold by removing all block comments after the first '{'.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   295
                    int start = source.indexOf("{");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   296
                    while ((start = source.indexOf("\n/*\n", start)) != -1) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   297
                        int end = source.indexOf("\n*/\n");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   298
                        source = source.substring(0, start + 1) + source.substring(end + 4);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   299
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   300
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   301
                    // process decls in compilation unit
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   302
                    super.visitCompilationUnit(tree, ignore);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   303
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   304
                    // write the modified source
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   305
                    File f = new File(tree.getSourceFile().getName());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   306
                    File outFile = new File(outDir, f.getName());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   307
                    try {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   308
                        FileWriter out = new FileWriter(outFile);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   309
                        try {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   310
                            out.write(source);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   311
                        } finally {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   312
                            out.close();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   313
                        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   314
                    } catch (IOException e) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   315
                        System.err.println("Can't write " + tree.getSourceFile().getName()
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   316
                                + " to " + outFile + ": " + e);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   317
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   318
                    return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   319
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   320
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   321
                @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   322
                void visitDecl(Tree tree, Name name) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   323
                    DocTree dc = trees.getDocCommentTree(getCurrentPath());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   324
                    if (dc != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   325
                        StringWriter out = new StringWriter();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   326
                        p.print(dc, out);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   327
                        String found = out.toString();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   328
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   329
                        // Look for the empty line after the first occurrence of name
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   330
                        int pos = source.indexOf("\n\n", findName(source, name));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   331
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   332
                        // Insert the golden comment
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   333
                        source = source.substring(0, pos)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   334
                                + "\n/*\n"
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   335
                                + found
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   336
                                + "*/"
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   337
                                + source.substring(pos);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   338
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   339
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   340
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   341
            };
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   342
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   343
            Iterable<? extends CompilationUnitTree> units = t.parse();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   344
            for (CompilationUnitTree unit: units) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   345
                d.scan(unit, null);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   346
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   347
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   348
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   349
        static int findName(String source, Name name) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   350
            Pattern p = Pattern.compile("\\s" + name + "[(;]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   351
            Matcher m = p.matcher(source);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   352
            if (!m.find())
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   353
                throw new Error("cannot find " + name);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   354
            return m.start();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   355
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   356
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   357
        static class Printer implements DocTreeVisitor<Void, Void> {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   358
            PrintWriter out;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   359
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   360
            void print(DocTree tree, Writer out) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   361
                this.out = (out instanceof PrintWriter)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   362
                        ? (PrintWriter) out : new PrintWriter(out);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   363
                tree.accept(this, null);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   364
                this.out.flush();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   365
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   366
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   367
            public Void visitAttribute(AttributeTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   368
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   369
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   370
                print("name", node.getName().toString());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   371
                print("vkind", node.getValueKind().toString());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   372
                print("value", node.getValue());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   373
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   374
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   375
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   376
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   377
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   378
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   379
            public Void visitAuthor(AuthorTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   380
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   381
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   382
                print("name", node.getName());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   383
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   384
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   385
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   386
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   387
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   388
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   389
            public Void visitComment(CommentTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   390
                header(node, compress(node.getBody()));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   391
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   392
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   393
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   394
            public Void visitDeprecated(DeprecatedTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   395
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   396
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   397
                print("body", node.getBody());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   398
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   399
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   400
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   401
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   402
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   403
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   404
            public Void visitDocComment(DocCommentTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   405
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   406
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   407
                print("firstSentence", node.getFirstSentence());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   408
                print("body", node.getBody());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   409
                print("block tags", node.getBlockTags());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   410
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   411
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   412
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   413
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   414
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   415
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   416
            public Void visitDocRoot(DocRootTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   417
                header(node, "");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   418
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   419
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   420
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   421
            public Void visitEndElement(EndElementTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   422
                header(node, node.getName().toString());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   423
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   424
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   425
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   426
            public Void visitEntity(EntityTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   427
                header(node, node.getName().toString());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   428
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   429
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   430
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   431
            public Void visitErroneous(ErroneousTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   432
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   433
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   434
                print("code", ((DCErroneous) node).diag.getCode());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   435
                print("body", compress(node.getBody()));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   436
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   437
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   438
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   439
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   440
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   441
37009
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 34567
diff changeset
   442
            public Void visitHidden(HiddenTree node, Void p) {
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 34567
diff changeset
   443
                header(node);
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 34567
diff changeset
   444
                indent(+1);
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 34567
diff changeset
   445
                print("body", node.getBody());
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 34567
diff changeset
   446
                indent(-1);
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 34567
diff changeset
   447
                indent();
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 34567
diff changeset
   448
                out.println("]");
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 34567
diff changeset
   449
                return null;
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 34567
diff changeset
   450
            }
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 34567
diff changeset
   451
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   452
            public Void visitIdentifier(IdentifierTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   453
                header(node, compress(node.getName().toString()));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   454
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   455
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   456
34567
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   457
            @Override
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   458
            public Void visitIndex(IndexTree node, Void p) {
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   459
                header(node);
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   460
                indent(+1);
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   461
                print("term", node.getSearchTerm());
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   462
                print("description", node.getDescription());
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   463
                indent(-1);
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   464
                indent();
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   465
                out.println("]");
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   466
                return null;
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   467
            }
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   468
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   469
            public Void visitInheritDoc(InheritDocTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   470
                header(node, "");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   471
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   472
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   473
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   474
            public Void visitLink(LinkTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   475
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   476
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   477
                print("reference", node.getReference());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   478
                print("body", node.getLabel());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   479
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   480
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   481
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   482
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   483
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   484
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   485
            public Void visitLiteral(LiteralTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   486
                header(node, compress(node.getBody().getBody()));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   487
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   488
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   489
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   490
            public Void visitParam(ParamTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   491
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   492
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   493
                print("name", node.getName());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   494
                print("description", node.getDescription());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   495
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   496
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   497
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   498
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   499
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   500
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   501
            public Void visitProvides(ProvidesTree node, Void p) {
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   502
                header(node);
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   503
                indent(+1);
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   504
                print("serviceName", node.getServiceType());
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   505
                print("description", node.getDescription());
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   506
                indent(-1);
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   507
                indent();
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   508
                out.println("]");
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   509
                return null;
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   510
            }
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   511
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   512
            public Void visitReference(ReferenceTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   513
                header(node, compress(node.getSignature()));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   514
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   515
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   516
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   517
            public Void visitReturn(ReturnTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   518
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   519
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   520
                print("description", node.getDescription());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   521
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   522
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   523
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   524
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   525
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   526
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   527
            public Void visitSee(SeeTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   528
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   529
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   530
                print("reference", node.getReference());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   531
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   532
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   533
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   534
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   535
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   536
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   537
            public Void visitSerial(SerialTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   538
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   539
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   540
                print("description", node.getDescription());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   541
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   542
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   543
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   544
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   545
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   546
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   547
            public Void visitSerialData(SerialDataTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   548
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   549
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   550
                print("description", node.getDescription());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   551
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   552
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   553
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   554
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   555
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   556
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   557
            public Void visitSerialField(SerialFieldTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   558
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   559
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   560
                print("name", node.getName());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   561
                print("type", node.getType());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   562
                print("description", node.getDescription());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   563
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   564
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   565
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   566
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   567
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   568
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   569
            public Void visitSince(SinceTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   570
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   571
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   572
                print("body", node.getBody());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   573
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   574
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   575
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   576
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   577
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   578
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   579
            public Void visitStartElement(StartElementTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   580
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   581
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   582
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   583
                out.println("name:" + node.getName());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   584
                print("attributes", node.getAttributes());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   585
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   586
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   587
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   588
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   589
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   590
46184
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   591
            @Override
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   592
            public Void visitSummary(SummaryTree node, Void p) {
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   593
                header(node);
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   594
                indent(+1);
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   595
                print("summary", node.getSummary());
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   596
                indent(-1);
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   597
                indent();
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   598
                out.println("]");
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   599
                return null;
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   600
            }
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   601
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   602
            public Void visitText(TextTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   603
                header(node, compress(node.getBody()));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   604
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   605
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   606
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   607
            public Void visitThrows(ThrowsTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   608
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   609
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   610
                print("exceptionName", node.getExceptionName());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   611
                print("description", node.getDescription());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   612
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   613
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   614
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   615
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   616
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   617
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   618
            public Void visitUnknownBlockTag(UnknownBlockTagTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   619
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   620
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   621
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   622
                out.println("tag:" + node.getTagName());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   623
                print("content", node.getContent());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   624
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   625
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   626
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   627
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   628
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   629
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   630
            public Void visitUnknownInlineTag(UnknownInlineTagTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   631
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   632
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   633
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   634
                out.println("tag:" + node.getTagName());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   635
                print("content", node.getContent());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   636
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   637
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   638
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   639
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   640
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   641
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   642
            public Void visitUses(UsesTree node, Void p) {
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   643
                header(node);
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   644
                indent(+1);
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   645
                print("serviceName", node.getServiceType());
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   646
                print("description", node.getDescription());
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   647
                indent(-1);
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   648
                indent();
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   649
                out.println("]");
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   650
                return null;
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   651
            }
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 37009
diff changeset
   652
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   653
            public Void visitValue(ValueTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   654
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   655
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   656
                print("reference", node.getReference());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   657
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   658
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   659
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   660
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   661
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   662
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   663
            public Void visitVersion(VersionTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   664
                header(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   665
                indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   666
                print("body", node.getBody());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   667
                indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   668
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   669
                out.println("]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   670
                return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   671
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   672
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   673
            public Void visitOther(DocTree node, Void p) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   674
                throw new UnsupportedOperationException("Not supported yet.");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   675
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   676
34567
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   677
            /*
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   678
             * Use this method to start printing a multi-line representation of a
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   679
             * DocTree node. The representation should be termintated by calling
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   680
             * out.println("]").
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   681
             */
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   682
            void header(DocTree node) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   683
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   684
                out.println(simpleClassName(node) + "[" + node.getKind() + ", pos:" + ((DCTree) node).pos);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   685
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   686
34567
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   687
            /*
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   688
             * Use this method to print a single-line representation of a DocTree node.
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   689
             */
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   690
            void header(DocTree node, String rest) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   691
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   692
                out.println(simpleClassName(node) + "[" + node.getKind() + ", pos:" + ((DCTree) node).pos
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   693
                        + (rest.isEmpty() ? "" : ", " + rest)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   694
                        + "]");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   695
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   696
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   697
            String simpleClassName(DocTree node) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   698
                return node.getClass().getSimpleName().replaceAll("DC(.*)", "$1");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   699
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   700
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   701
            void print(String name, DocTree item) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   702
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   703
                if (item == null)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   704
                    out.println(name + ": null");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   705
                else {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   706
                    out.println(name + ":");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   707
                    indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   708
                    item.accept(this, null);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   709
                    indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   710
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   711
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   712
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   713
            void print(String name, String s) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   714
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   715
                out.println(name + ": " + s);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   716
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   717
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   718
            void print(String name, List<? extends DocTree> list) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   719
                indent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   720
                if (list == null)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   721
                    out.println(name + ": null");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   722
                else if (list.isEmpty())
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   723
                    out.println(name + ": empty");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   724
                else {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   725
                    out.println(name + ": " + list.size());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   726
                    indent(+1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   727
                    for (DocTree tree: list) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   728
                        tree.accept(this, null);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   729
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   730
                    indent(-1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   731
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   732
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   733
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   734
            int indent = 0;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   735
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   736
            void indent() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   737
                for (int i = 0; i < indent; i++) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   738
                    out.print("  ");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   739
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   740
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   741
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   742
            void indent(int n) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   743
                indent += n;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   744
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   745
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   746
            String compress(String s) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   747
                s = s.replace("\n", "|").replace(" ", "_");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   748
                return (s.length() < 32)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   749
                        ? s
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   750
                        : s.substring(0, 16) + "..." + s.substring(16);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   751
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   752
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   753
            String quote(String s) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   754
                if (s.contains("\""))
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   755
                    return "'" + s + "'";
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   756
                else if (s.contains("'") || s.contains(" "))
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   757
                    return '"' + s + '"';
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   758
                else
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   759
                    return s;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   760
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   761
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   762
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   763
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   764
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   765
     * Verify the reported tree positions by comparing the characters found
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   766
     * at and after the reported position with the beginning of the pretty-
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   767
     * printed text.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   768
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   769
    static class PosChecker extends Checker {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   770
        PosChecker(DocCommentTester test, DocTrees t) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   771
            test.super(t);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   772
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   773
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   774
        @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   775
        void check(TreePath path, Name name) throws Exception {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   776
            JavaFileObject fo = path.getCompilationUnit().getSourceFile();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   777
            final CharSequence cs = fo.getCharContent(true);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   778
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   779
            final DCDocComment dc = (DCDocComment) trees.getDocCommentTree(path);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   780
            DCTree t = (DCTree) trees.getDocCommentTree(path);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   781
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   782
            DocTreeScanner scanner = new DocTreeScanner<Void,Void>() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   783
                @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   784
                public Void scan(DocTree node, Void ignore) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   785
                    if (node != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   786
                        try {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   787
                            String expect = getExpectText(node);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   788
                            long pos = ((DCTree) node).getSourcePosition(dc);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   789
                            String found = getFoundText(cs, (int) pos, expect.length());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   790
                            if (!found.equals(expect)) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   791
                                System.err.println("expect: " + expect);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   792
                                System.err.println("found:  " + found);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   793
                                error("mismatch");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   794
                            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   795
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   796
                        } catch (StringIndexOutOfBoundsException e) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   797
                            error(node.getClass() + ": " + e.toString());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   798
                                e.printStackTrace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   799
                        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   800
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   801
                    return super.scan(node, ignore);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   802
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   803
            };
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   804
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   805
            scanner.scan(t, null);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   806
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   807
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   808
        String getExpectText(DocTree t) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   809
            StringWriter sw = new StringWriter();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   810
            DocPretty p = new DocPretty(sw);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   811
            try { p.print(t); } catch (IOException never) { }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   812
            String s = sw.toString();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   813
            if (s.length() <= 1)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   814
                return s;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   815
            int ws = s.replaceAll("\\s+", " ").indexOf(" ");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   816
            if (ws != -1) s = s.substring(0, ws);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   817
            return (s.length() < 5) ? s : s.substring(0, 5);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   818
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   819
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   820
        String getFoundText(CharSequence cs, int pos, int len) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   821
            return (pos == -1) ? "" : cs.subSequence(pos, Math.min(pos + len, cs.length())).toString();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   822
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   823
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   824
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   825
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   826
     * Verify the pretty printed text against a normalized form of the
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   827
     * original doc comment.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   828
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   829
    static class PrettyChecker extends Checker {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   830
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   831
        PrettyChecker(DocCommentTester test, DocTrees t) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   832
            test.super(t);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   833
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   834
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   835
        @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   836
        void check(TreePath path, Name name) throws Exception {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   837
            String raw = trees.getDocComment(path);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   838
            String normRaw = normalize(raw);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   839
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   840
            StringWriter out = new StringWriter();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   841
            DocPretty dp = new DocPretty(out);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   842
            dp.print(trees.getDocCommentTree(path));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   843
            String pretty = out.toString();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   844
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   845
            if (!pretty.equals(normRaw)) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   846
                error("mismatch");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   847
                System.err.println("*** expected:");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   848
                System.err.println(normRaw.replace(" ", "_"));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   849
                System.err.println("*** found:");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   850
                System.err.println(pretty.replace(" ", "_"));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   851
    //            throw new Error();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   852
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   853
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   854
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   855
        /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   856
         * Normalize white space in places where the tree does not preserve it.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   857
         */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   858
        String normalize(String s) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 14551
diff changeset
   859
            s = s.trim()
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   860
                    .replaceFirst("\\.\\s*\\n *@", ".\n@")
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   861
                    .replaceAll("\\{@docRoot\\s+\\}", "{@docRoot}")
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   862
                    .replaceAll("\\{@inheritDoc\\s+\\}", "{@inheritDoc}")
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   863
                    .replaceAll("(\\{@value\\s+[^}]+)\\s+(\\})", "$1$2")
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 14551
diff changeset
   864
                    .replaceAll("\n[ \t]+@", "\n@")
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 14551
diff changeset
   865
                    .replaceAll("(\\{@code)(\\x20)(\\s+.*)", "$1$3");
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 14551
diff changeset
   866
            return s;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   867
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   868
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   869
}
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   870