src/jdk.compiler/share/classes/jdk/internal/shellsupport/doc/JavadocFormatter.java
author psadhukhan
Fri, 09 Nov 2018 09:29:43 +0530
changeset 52543 3853631e6a07
parent 47216 71c04702a3d5
child 55352 1357c4996b2e
permissions -rw-r--r--
8213181: Updation of ProblemList.txt for removal of passing swing test Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     1
/*
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     4
 *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    10
 *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    15
 * accompanied this code).
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    16
 *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    20
 *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    23
 * questions.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    24
 */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    25
package jdk.internal.shellsupport.doc;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    26
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    27
import java.io.IOException;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    28
import java.net.URI;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    29
import java.net.URISyntaxException;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    30
import java.util.ArrayList;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    31
import java.util.Arrays;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    32
import java.util.Collections;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    33
import java.util.IdentityHashMap;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    34
import java.util.LinkedHashMap;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    35
import java.util.List;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    36
import java.util.Map;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    37
import java.util.ResourceBundle;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    38
import java.util.Stack;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    39
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    40
import javax.lang.model.element.Name;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    41
import javax.tools.JavaFileObject.Kind;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    42
import javax.tools.SimpleJavaFileObject;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    43
import javax.tools.ToolProvider;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    44
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    45
import com.sun.source.doctree.AttributeTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    46
import com.sun.source.doctree.DocCommentTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    47
import com.sun.source.doctree.DocTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    48
import com.sun.source.doctree.EndElementTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    49
import com.sun.source.doctree.EntityTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    50
import com.sun.source.doctree.InlineTagTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    51
import com.sun.source.doctree.LinkTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    52
import com.sun.source.doctree.LiteralTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    53
import com.sun.source.doctree.ParamTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    54
import com.sun.source.doctree.ReturnTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    55
import com.sun.source.doctree.StartElementTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    56
import com.sun.source.doctree.TextTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    57
import com.sun.source.doctree.ThrowsTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    58
import com.sun.source.util.DocTreeScanner;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    59
import com.sun.source.util.DocTrees;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    60
import com.sun.source.util.JavacTask;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    61
import com.sun.tools.doclint.Entity;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    62
import com.sun.tools.doclint.HtmlTag;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    63
import com.sun.tools.javac.util.DefinedBy;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    64
import com.sun.tools.javac.util.DefinedBy.Api;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    65
import com.sun.tools.javac.util.StringUtils;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    66
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    67
/**A javadoc to plain text formatter.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    68
 *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    69
 */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    70
public class JavadocFormatter {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    71
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    72
    private static final String CODE_RESET = "\033[0m";
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    73
    private static final String CODE_HIGHLIGHT = "\033[1m";
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    74
    private static final String CODE_UNDERLINE = "\033[4m";
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    75
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    76
    private final int lineLimit;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    77
    private final boolean escapeSequencesSupported;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    78
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    79
    /** Construct the formatter.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    80
     *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    81
     * @param lineLimit maximum line length
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    82
     * @param escapeSequencesSupported whether escape sequences are supported
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    83
     */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    84
    public JavadocFormatter(int lineLimit, boolean escapeSequencesSupported) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    85
        this.lineLimit = lineLimit;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    86
        this.escapeSequencesSupported = escapeSequencesSupported;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    87
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    88
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    89
    private static final int MAX_LINE_LENGTH = 95;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    90
    private static final int SHORTEST_LINE = 30;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    91
    private static final int INDENT = 4;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    92
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    93
    /**Format javadoc to plain text.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    94
     *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    95
     * @param header element caption that should be used
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    96
     * @param javadoc to format
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    97
     * @return javadoc formatted to plain text
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    98
     */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    99
    public String formatJavadoc(String header, String javadoc) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   100
        try {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   101
            StringBuilder result = new StringBuilder();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   102
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   103
            result.append(escape(CODE_HIGHLIGHT)).append(header).append(escape(CODE_RESET)).append("\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   104
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   105
            if (javadoc == null) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   106
                return result.toString();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   107
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   108
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   109
            JavacTask task = (JavacTask) ToolProvider.getSystemJavaCompiler().getTask(null, null, null, null, null, null);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   110
            DocTrees trees = DocTrees.instance(task);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   111
            DocCommentTree docComment = trees.getDocCommentTree(new SimpleJavaFileObject(new URI("mem://doc.html"), Kind.HTML) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   112
                @Override @DefinedBy(Api.COMPILER)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   113
                public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   114
                    return "<body>" + javadoc + "</body>";
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   115
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   116
            });
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   117
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   118
            new FormatJavadocScanner(result, task).scan(docComment, null);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   119
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   120
            addNewLineIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   121
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   122
            return result.toString();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   123
        } catch (URISyntaxException ex) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   124
            throw new InternalError("Unexpected exception", ex);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   125
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   126
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   127
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   128
    private class FormatJavadocScanner extends DocTreeScanner<Object, Object> {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   129
        private final StringBuilder result;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   130
        private final JavacTask task;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   131
        private int reflownTo;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   132
        private int indent;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   133
        private int limit = Math.min(lineLimit, MAX_LINE_LENGTH);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   134
        private boolean pre;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   135
        private Map<StartElementTree, Integer> tableColumns;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   136
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   137
        public FormatJavadocScanner(StringBuilder result, JavacTask task) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   138
            this.result = result;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   139
            this.task = task;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   140
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   141
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   142
        @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   143
        public Object visitDocComment(DocCommentTree node, Object p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   144
            tableColumns = countTableColumns(node);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   145
            reflownTo = result.length();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   146
            scan(node.getFirstSentence(), p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   147
            scan(node.getBody(), p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   148
            reflow(result, reflownTo, indent, limit);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   149
            for (Sections current : docSections.keySet()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   150
                boolean seenAny = false;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   151
                for (DocTree t : node.getBlockTags()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   152
                    if (current.matches(t)) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   153
                        if (!seenAny) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   154
                            seenAny = true;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   155
                            if (result.charAt(result.length() - 1) != '\n')
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   156
                                result.append("\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   157
                            result.append("\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   158
                            result.append(escape(CODE_UNDERLINE))
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   159
                                  .append(docSections.get(current))
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   160
                                  .append(escape(CODE_RESET))
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   161
                                  .append("\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   162
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   163
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   164
                        scan(t, null);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   165
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   166
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   167
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   168
            return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   169
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   170
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   171
        @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   172
        public Object visitText(TextTree node, Object p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   173
            String text = node.getBody();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   174
            if (!pre) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   175
                text = text.replaceAll("[ \t\r\n]+", " ").trim();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   176
                if (text.isEmpty()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   177
                    text = " ";
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   178
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   179
            } else {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   180
                text = text.replaceAll("\n", "\n" + indentString(indent));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   181
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   182
            result.append(text);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   183
            return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   184
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   185
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   186
        @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   187
        public Object visitLink(LinkTree node, Object p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   188
            if (!node.getLabel().isEmpty()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   189
                scan(node.getLabel(), p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   190
            } else {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   191
                result.append(node.getReference().getSignature());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   192
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   193
            return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   194
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   195
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   196
        @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   197
        public Object visitParam(ParamTree node, Object p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   198
            return formatDef(node.getName().getName(), node.getDescription());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   199
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   200
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   201
        @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   202
        public Object visitThrows(ThrowsTree node, Object p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   203
            return formatDef(node.getExceptionName().getSignature(), node.getDescription());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   204
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   205
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   206
        public Object formatDef(CharSequence name, List<? extends DocTree> description) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   207
            result.append(name);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   208
            result.append(" - ");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   209
            reflownTo = result.length();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   210
            indent = name.length() + 3;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   211
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   212
            if (limit - indent < SHORTEST_LINE) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   213
                result.append("\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   214
                result.append(indentString(INDENT));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   215
                indent = INDENT;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   216
                reflownTo += INDENT;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   217
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   218
            try {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   219
                return scan(description, null);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   220
            } finally {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   221
                reflow(result, reflownTo, indent, limit);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   222
                result.append("\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   223
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   224
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   225
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   226
        @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   227
        public Object visitLiteral(LiteralTree node, Object p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   228
            return scan(node.getBody(), p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   229
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   230
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   231
        @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   232
        public Object visitReturn(ReturnTree node, Object p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   233
            reflownTo = result.length();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   234
            try {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   235
                return super.visitReturn(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   236
            } finally {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   237
                reflow(result, reflownTo, 0, limit);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   238
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   239
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   240
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   241
        Stack<Integer> listStack = new Stack<>();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   242
        Stack<Integer> defStack = new Stack<>();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   243
        Stack<Integer> tableStack = new Stack<>();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   244
        Stack<List<Integer>> cellsStack = new Stack<>();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   245
        Stack<List<Boolean>> headerStack = new Stack<>();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   246
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   247
        @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   248
        public Object visitStartElement(StartElementTree node, Object p) {
42258
a1aafd5ea6ec 8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents: 41865
diff changeset
   249
            switch (getHtmlTag(node.getName())) {
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   250
                case P:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   251
                    if (lastNode!= null && lastNode.getKind() == DocTree.Kind.START_ELEMENT &&
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   252
                        HtmlTag.get(((StartElementTree) lastNode).getName()) == HtmlTag.LI) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   253
                        //ignore
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   254
                        break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   255
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   256
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   257
                    addNewLineIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   258
                    result.append(indentString(indent));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   259
                    reflownTo = result.length();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   260
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   261
                case BLOCKQUOTE:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   262
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   263
                    indent += INDENT;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   264
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   265
                case PRE:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   266
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   267
                    pre = true;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   268
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   269
                case UL:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   270
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   271
                    listStack.push(-1);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   272
                    indent += INDENT;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   273
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   274
                case OL:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   275
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   276
                    listStack.push(1);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   277
                    indent += INDENT;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   278
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   279
                case DL:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   280
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   281
                    defStack.push(indent);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   282
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   283
                case LI:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   284
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   285
                    if (!listStack.empty()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   286
                        addNewLineIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   287
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   288
                        int top = listStack.pop();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   289
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   290
                        if (top == (-1)) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   291
                            result.append(indentString(indent - 2));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   292
                            result.append("* ");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   293
                        } else {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   294
                            result.append(indentString(indent - 3));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   295
                            result.append("" + top++ + ". ");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   296
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   297
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   298
                        listStack.push(top);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   299
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   300
                        reflownTo = result.length();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   301
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   302
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   303
                case DT:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   304
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   305
                    if (!defStack.isEmpty()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   306
                        addNewLineIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   307
                        indent = defStack.peek();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   308
                        result.append(escape(CODE_HIGHLIGHT));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   309
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   310
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   311
                case DD:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   312
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   313
                    if (!defStack.isEmpty()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   314
                        if (indent == defStack.peek()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   315
                            result.append(escape(CODE_RESET));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   316
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   317
                        addNewLineIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   318
                        indent = defStack.peek() + INDENT;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   319
                        result.append(indentString(indent));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   320
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   321
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   322
                case H1: case H2: case H3:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   323
                case H4: case H5: case H6:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   324
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   325
                    addNewLineIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   326
                    result.append("\n")
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   327
                          .append(escape(CODE_UNDERLINE));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   328
                    reflownTo = result.length();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   329
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   330
                case TABLE:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   331
                    int columns = tableColumns.get(node);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   332
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   333
                    if (columns == 0) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   334
                        break; //broken input
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   335
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   336
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   337
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   338
                    addNewLineIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   339
                    reflownTo = result.length();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   340
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   341
                    tableStack.push(limit);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   342
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   343
                    limit = (limit - 1) / columns - 3;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   344
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   345
                    for (int sep = 0; sep < (limit + 3) * columns + 1; sep++) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   346
                        result.append("-");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   347
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   348
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   349
                    result.append("\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   350
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   351
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   352
                case TR:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   353
                    if (cellsStack.size() >= tableStack.size()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   354
                        //unclosed <tr>:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   355
                        handleEndElement(node.getName());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   356
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   357
                    cellsStack.push(new ArrayList<>());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   358
                    headerStack.push(new ArrayList<>());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   359
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   360
                case TH:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   361
                case TD:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   362
                    if (cellsStack.isEmpty()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   363
                        //broken code
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   364
                        break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   365
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   366
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   367
                    result.append("\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   368
                    reflownTo = result.length();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   369
                    cellsStack.peek().add(result.length());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   370
                    headerStack.peek().add(HtmlTag.get(node.getName()) == HtmlTag.TH);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   371
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   372
                case IMG:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   373
                    for (DocTree attr : node.getAttributes()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   374
                        if (attr.getKind() != DocTree.Kind.ATTRIBUTE) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   375
                            continue;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   376
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   377
                        AttributeTree at = (AttributeTree) attr;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   378
                        if ("alt".equals(StringUtils.toLowerCase(at.getName().toString()))) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   379
                            addSpaceIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   380
                            scan(at.getValue(), null);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   381
                            addSpaceIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   382
                            break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   383
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   384
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   385
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   386
                default:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   387
                    addSpaceIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   388
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   389
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   390
            return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   391
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   392
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   393
        @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   394
        public Object visitEndElement(EndElementTree node, Object p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   395
            handleEndElement(node.getName());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   396
            return super.visitEndElement(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   397
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   398
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   399
        private void handleEndElement(Name name) {
42258
a1aafd5ea6ec 8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents: 41865
diff changeset
   400
            switch (getHtmlTag(name)) {
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   401
                case BLOCKQUOTE:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   402
                    indent -= INDENT;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   403
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   404
                case PRE:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   405
                    pre = false;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   406
                    addNewLineIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   407
                    reflownTo = result.length();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   408
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   409
                case UL: case OL:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   410
                    if (listStack.isEmpty()) { //ignore stray closing tag
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   411
                        break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   412
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   413
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   414
                    listStack.pop();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   415
                    indent -= INDENT;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   416
                    addNewLineIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   417
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   418
                case DL:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   419
                    if (defStack.isEmpty()) {//ignore stray closing tag
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   420
                        break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   421
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   422
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   423
                    if (indent == defStack.peek()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   424
                        result.append(escape(CODE_RESET));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   425
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   426
                    indent = defStack.pop();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   427
                    addNewLineIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   428
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   429
                case H1: case H2: case H3:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   430
                case H4: case H5: case H6:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   431
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   432
                    result.append(escape(CODE_RESET))
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   433
                          .append("\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   434
                    reflownTo = result.length();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   435
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   436
                case TABLE:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   437
                    if (cellsStack.size() >= tableStack.size()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   438
                        //unclosed <tr>:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   439
                        handleEndElement(task.getElements().getName("tr"));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   440
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   441
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   442
                    if (tableStack.isEmpty()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   443
                        break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   444
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   445
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   446
                    limit = tableStack.pop();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   447
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   448
                case TR:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   449
                    if (cellsStack.isEmpty()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   450
                        break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   451
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   452
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   453
                    reflowTillNow();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   454
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   455
                    List<Integer> cells = cellsStack.pop();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   456
                    List<Boolean> headerFlags = headerStack.pop();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   457
                    List<String[]> content = new ArrayList<>();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   458
                    int maxLines = 0;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   459
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   460
                    result.append("\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   461
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   462
                    while (!cells.isEmpty()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   463
                        int currentCell = cells.remove(cells.size() - 1);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   464
                        String[] lines = result.substring(currentCell, result.length()).split("\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   465
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   466
                        result.delete(currentCell - 1, result.length());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   467
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   468
                        content.add(lines);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   469
                        maxLines = Math.max(maxLines, lines.length);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   470
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   471
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   472
                    Collections.reverse(content);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   473
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   474
                    for (int line = 0; line < maxLines; line++) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   475
                        for (int column = 0; column < content.size(); column++) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   476
                            String[] lines = content.get(column);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   477
                            String currentLine = line < lines.length ? lines[line] : "";
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   478
                            result.append("| ");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   479
                            boolean header = headerFlags.get(column);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   480
                            if (header) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   481
                                result.append(escape(CODE_HIGHLIGHT));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   482
                            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   483
                            result.append(currentLine);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   484
                            if (header) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   485
                                result.append(escape(CODE_RESET));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   486
                            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   487
                            int padding = limit - currentLine.length();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   488
                            if (padding > 0)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   489
                                result.append(indentString(padding));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   490
                            result.append(" ");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   491
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   492
                        result.append("|\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   493
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   494
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   495
                    for (int sep = 0; sep < (limit + 3) * content.size() + 1; sep++) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   496
                        result.append("-");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   497
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   498
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   499
                    result.append("\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   500
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   501
                    reflownTo = result.length();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   502
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   503
                case TD:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   504
                case TH:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   505
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   506
                default:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   507
                    addSpaceIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   508
                    break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   509
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   510
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   511
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   512
        @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   513
        public Object visitEntity(EntityTree node, Object p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   514
            String name = node.getName().toString();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   515
            int code = -1;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   516
            if (name.startsWith("#")) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   517
                try {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   518
                    int v = StringUtils.toLowerCase(name).startsWith("#x")
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   519
                            ? Integer.parseInt(name.substring(2), 16)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   520
                            : Integer.parseInt(name.substring(1), 10);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   521
                    if (Entity.isValid(v)) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   522
                        code = v;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   523
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   524
                } catch (NumberFormatException ex) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   525
                    //ignore
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   526
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   527
            } else {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   528
                Entity entity = Entity.get(name);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   529
                if (entity != null) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   530
                    code = entity.code;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   531
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   532
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   533
            if (code != (-1)) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   534
                result.appendCodePoint(code);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   535
            } else {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   536
                result.append(node.toString());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   537
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   538
            return super.visitEntity(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   539
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   540
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   541
        private DocTree lastNode;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   542
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   543
        @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   544
        public Object scan(DocTree node, Object p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   545
            if (node instanceof InlineTagTree) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   546
                addSpaceIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   547
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   548
            try {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   549
                return super.scan(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   550
            } finally {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   551
                if (node instanceof InlineTagTree) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   552
                    addSpaceIfNeeded(result);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   553
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   554
                lastNode = node;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   555
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   556
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   557
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   558
        private void reflowTillNow() {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   559
            while (result.length() > 0 && result.charAt(result.length() - 1) == ' ')
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   560
                result.delete(result.length() - 1, result.length());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   561
            reflow(result, reflownTo, indent, limit);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   562
            reflownTo = result.length();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   563
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   564
    };
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   565
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   566
    private String escape(String sequence) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   567
        return this.escapeSequencesSupported ? sequence : "";
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   568
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   569
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   570
    private static final Map<Sections, String> docSections = new LinkedHashMap<>();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   571
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   572
    static {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   573
        ResourceBundle bundle =
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   574
                ResourceBundle.getBundle("jdk.internal.shellsupport.doc.resources.javadocformatter");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   575
        docSections.put(Sections.TYPE_PARAMS, bundle.getString("CAP_TypeParameters"));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   576
        docSections.put(Sections.PARAMS, bundle.getString("CAP_Parameters"));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   577
        docSections.put(Sections.RETURNS, bundle.getString("CAP_Returns"));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   578
        docSections.put(Sections.THROWS, bundle.getString("CAP_Thrown_Exceptions"));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   579
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   580
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   581
    private static String indentString(int indent) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   582
        char[] content = new char[indent];
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   583
        Arrays.fill(content, ' ');
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   584
        return new String(content);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   585
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   586
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   587
    private static void reflow(StringBuilder text, int from, int indent, int limit) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   588
        int lineStart = from;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   589
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   590
        while (lineStart > 0 && text.charAt(lineStart - 1) != '\n') {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   591
            lineStart--;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   592
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   593
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   594
        int lineChars = from - lineStart;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   595
        int pointer = from;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   596
        int lastSpace = -1;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   597
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   598
        while (pointer < text.length()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   599
            if (text.charAt(pointer) == ' ')
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   600
                lastSpace = pointer;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   601
            if (lineChars >= limit) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   602
                if (lastSpace != (-1)) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   603
                    text.setCharAt(lastSpace, '\n');
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   604
                    text.insert(lastSpace + 1, indentString(indent));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   605
                    lineChars = indent + pointer - lastSpace - 1;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   606
                    pointer += indent;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   607
                    lastSpace = -1;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   608
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   609
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   610
            lineChars++;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   611
            pointer++;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   612
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   613
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   614
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   615
    private static void addNewLineIfNeeded(StringBuilder text) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   616
        if (text.length() > 0 && text.charAt(text.length() - 1) != '\n') {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   617
            text.append("\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   618
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   619
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   620
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   621
    private static void addSpaceIfNeeded(StringBuilder text) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   622
        if (text.length() == 0)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   623
            return ;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   624
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   625
        char last = text.charAt(text.length() - 1);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   626
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   627
        if (last != ' ' && last != '\n') {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   628
            text.append(" ");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   629
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   630
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   631
42258
a1aafd5ea6ec 8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents: 41865
diff changeset
   632
    private static HtmlTag getHtmlTag(Name name) {
a1aafd5ea6ec 8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents: 41865
diff changeset
   633
        HtmlTag tag = HtmlTag.get(name);
a1aafd5ea6ec 8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents: 41865
diff changeset
   634
a1aafd5ea6ec 8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents: 41865
diff changeset
   635
        return tag != null ? tag : HtmlTag.HTML; //using HtmlTag.HTML as default no-op value
a1aafd5ea6ec 8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents: 41865
diff changeset
   636
    }
a1aafd5ea6ec 8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents: 41865
diff changeset
   637
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   638
    private static Map<StartElementTree, Integer> countTableColumns(DocCommentTree dct) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   639
        Map<StartElementTree, Integer> result = new IdentityHashMap<>();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   640
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   641
        new DocTreeScanner<Void, Void>() {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   642
            private StartElementTree currentTable;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   643
            private int currentMaxColumns;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   644
            private int currentRowColumns;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   645
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   646
            @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   647
            public Void visitStartElement(StartElementTree node, Void p) {
42258
a1aafd5ea6ec 8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents: 41865
diff changeset
   648
                switch (getHtmlTag(node.getName())) {
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   649
                    case TABLE: currentTable = node; break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   650
                    case TR:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   651
                        currentMaxColumns = Math.max(currentMaxColumns, currentRowColumns);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   652
                        currentRowColumns = 0;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   653
                        break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   654
                    case TD:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   655
                    case TH: currentRowColumns++; break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   656
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   657
                return super.visitStartElement(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   658
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   659
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   660
            @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   661
            public Void visitEndElement(EndElementTree node, Void p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   662
                if (HtmlTag.get(node.getName()) == HtmlTag.TABLE) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   663
                    closeTable();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   664
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   665
                return super.visitEndElement(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   666
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   667
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   668
            @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   669
            public Void visitDocComment(DocCommentTree node, Void p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   670
                try {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   671
                    return super.visitDocComment(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   672
                } finally {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   673
                    closeTable();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   674
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   675
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   676
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   677
            private void closeTable() {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   678
                if (currentTable != null) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   679
                    result.put(currentTable, Math.max(currentMaxColumns, currentRowColumns));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   680
                    currentTable = null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   681
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   682
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   683
        }.scan(dct, null);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   684
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   685
        return result;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   686
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   687
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   688
    private enum Sections {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   689
        TYPE_PARAMS {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   690
            @Override public boolean matches(DocTree t) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   691
                return t.getKind() == DocTree.Kind.PARAM && ((ParamTree) t).isTypeParameter();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   692
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   693
        },
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   694
        PARAMS {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   695
            @Override public boolean matches(DocTree t) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   696
                return t.getKind() == DocTree.Kind.PARAM && !((ParamTree) t).isTypeParameter();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   697
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   698
        },
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   699
        RETURNS {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   700
            @Override public boolean matches(DocTree t) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   701
                return t.getKind() == DocTree.Kind.RETURN;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   702
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   703
        },
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   704
        THROWS {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   705
            @Override public boolean matches(DocTree t) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   706
                return t.getKind() == DocTree.Kind.THROWS;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   707
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   708
        };
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   709
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   710
        public abstract boolean matches(DocTree t);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   711
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   712
}