src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 55756 d48ffad997b1
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     1
/*
55204
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
     2
 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     4
 *
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    10
 *
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    15
 * accompanied this code).
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    16
 *
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    20
 *
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    23
 * questions.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    24
 */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    25
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    26
package com.sun.tools.javac.parser;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    27
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    28
import java.text.BreakIterator;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    29
import java.util.HashMap;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    30
import java.util.Map;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    31
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    32
import com.sun.source.doctree.AttributeTree.ValueKind;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    33
import com.sun.tools.javac.parser.DocCommentParser.TagParser.Kind;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    34
import com.sun.tools.javac.parser.Tokens.Comment;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    35
import com.sun.tools.javac.parser.Tokens.TokenKind;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    36
import com.sun.tools.javac.tree.DCTree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    37
import com.sun.tools.javac.tree.DCTree.DCAttribute;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    38
import com.sun.tools.javac.tree.DCTree.DCDocComment;
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
    39
import com.sun.tools.javac.tree.DCTree.DCEndElement;
17273
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 15552
diff changeset
    40
import com.sun.tools.javac.tree.DCTree.DCEndPosTree;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    41
import com.sun.tools.javac.tree.DCTree.DCErroneous;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    42
import com.sun.tools.javac.tree.DCTree.DCIdentifier;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    43
import com.sun.tools.javac.tree.DCTree.DCReference;
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
    44
import com.sun.tools.javac.tree.DCTree.DCStartElement;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    45
import com.sun.tools.javac.tree.DCTree.DCText;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    46
import com.sun.tools.javac.tree.DocTreeMaker;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    47
import com.sun.tools.javac.tree.JCTree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    48
import com.sun.tools.javac.util.DiagnosticSource;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    49
import com.sun.tools.javac.util.List;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    50
import com.sun.tools.javac.util.ListBuffer;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    51
import com.sun.tools.javac.util.Log;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    52
import com.sun.tools.javac.util.Name;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    53
import com.sun.tools.javac.util.Names;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    54
import com.sun.tools.javac.util.Position;
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
    55
import com.sun.tools.javac.util.StringUtils;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
    56
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    57
import static com.sun.tools.javac.util.LayoutCharacters.*;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    58
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    59
/**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    60
 *
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    61
 *  <p><b>This is NOT part of any supported API.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    62
 *  If you write code that depends on this, you do so at your own risk.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    63
 *  This code and its internal interfaces are subject to change or
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    64
 *  deletion without notice.</b>
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    65
 */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    66
public class DocCommentParser {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    67
    static class ParseException extends Exception {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    68
        private static final long serialVersionUID = 0;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    69
        ParseException(String key) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    70
            super(key);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    71
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    72
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    73
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
    74
    private enum Phase {PREAMBLE, BODY, POSTAMBLE};
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
    75
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    76
    final ParserFactory fac;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    77
    final DiagnosticSource diagSource;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    78
    final Comment comment;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    79
    final DocTreeMaker m;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    80
    final Names names;
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
    81
    final boolean isFileContent;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    82
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    83
    BreakIterator sentenceBreaker;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    84
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    85
    /** The input buffer, index of most recent character read,
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    86
     *  index of one past last character in buffer.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    87
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    88
    protected char[] buf;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    89
    protected int bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    90
    protected int buflen;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    91
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    92
    /** The current character.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    93
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    94
    protected char ch;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    95
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    96
    int textStart = -1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    97
    int lastNonWhite = -1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    98
    boolean newline = true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    99
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   100
    Map<Name, TagParser> tagParsers;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   101
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   102
    public DocCommentParser(ParserFactory fac, DiagnosticSource diagSource,
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   103
                            Comment comment, boolean isFileContent) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   104
        this.fac = fac;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   105
        this.diagSource = diagSource;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   106
        this.comment = comment;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   107
        names = fac.names;
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   108
        this.isFileContent = isFileContent;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   109
        m = fac.docTreeMaker;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   110
        initTagParsers();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   111
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   112
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   113
    public DocCommentParser(ParserFactory fac, DiagnosticSource diagSource, Comment comment) {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   114
        this(fac, diagSource, comment, false);
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   115
    }
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   116
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   117
    public DocCommentParser(ParserFactory fac) {
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   118
        this(fac, null, null, false);
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   119
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   120
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   121
    public DCDocComment parse() {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   122
        String c = comment.getText();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   123
        buf = new char[c.length() + 1];
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   124
        c.getChars(0, c.length(), buf, 0);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   125
        buf[buf.length - 1] = EOI;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   126
        buflen = buf.length - 1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   127
        bp = -1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   128
        nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   129
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   130
        List<DCTree> preamble = isFileContent ? blockContent(Phase.PREAMBLE) : List.nil();
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   131
        List<DCTree> body = blockContent(Phase.BODY);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   132
        List<DCTree> tags = blockTags();
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   133
        List<DCTree> postamble = isFileContent ? blockContent(Phase.POSTAMBLE) : List.nil();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   134
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   135
        int pos = Position.NOPOS;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   136
        if (!preamble.isEmpty())
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   137
            pos = preamble.head.pos;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   138
        else if (!body.isEmpty())
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   139
            pos = body.head.pos;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   140
        else if (!tags.isEmpty())
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   141
            pos = tags.head.pos;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   142
        else if (!postamble.isEmpty())
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   143
            pos = postamble.head.pos;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   144
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   145
        DCDocComment dc = m.at(pos).newDocCommentTree(comment, body, tags, preamble, postamble);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   146
        return dc;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   147
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   148
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   149
    void nextChar() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   150
        ch = buf[bp < buflen ? ++bp : buflen];
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   151
        switch (ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   152
            case '\f': case '\n': case '\r':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   153
                newline = true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   154
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   155
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   156
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   157
    protected List<DCTree> blockContent() {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   158
        return blockContent(Phase.BODY);
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   159
    }
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   160
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   161
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   162
     * Read block content, consisting of text, html and inline tags.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   163
     * Terminated by the end of input, or the beginning of the next block tag:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   164
     * i.e. @ as the first non-whitespace character on a line.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   165
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   166
    @SuppressWarnings("fallthrough")
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   167
    protected List<DCTree> blockContent(Phase phase) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
   168
        ListBuffer<DCTree> trees = new ListBuffer<>();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   169
        textStart = -1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   170
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   171
        loop:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   172
        while (bp < buflen) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   173
            switch (ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   174
                case '\n': case '\r': case '\f':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   175
                    newline = true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   176
                    // fallthrough
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   177
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   178
                case ' ': case '\t':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   179
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   180
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   181
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   182
                case '&':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   183
                    entity(trees);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   184
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   185
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   186
                case '<':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   187
                    newline = false;
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   188
                    if (isFileContent) {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   189
                        switch (phase) {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   190
                            case PREAMBLE:
55204
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   191
                                if (isEndPreamble()) {
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   192
                                    trees.add(html());
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   193
                                    if (textStart == -1) {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   194
                                        textStart = bp;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   195
                                        lastNonWhite = -1;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   196
                                    }
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   197
                                    // mark this as the start, for processing purposes
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   198
                                    newline = true;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   199
                                    break loop;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   200
                                }
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   201
                                break;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   202
                            case BODY:
55204
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   203
                                if (isEndBody()) {
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   204
                                    addPendingText(trees, lastNonWhite);
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   205
                                    break loop;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   206
                                }
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   207
                                break;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   208
                            default:
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   209
                                // fallthrough
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   210
                        }
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   211
                    }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   212
                    addPendingText(trees, bp - 1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   213
                    trees.add(html());
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   214
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   215
                    if (phase == Phase.PREAMBLE || phase == Phase.POSTAMBLE) {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   216
                        break; // Ignore newlines after html tags, in the meta content
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   217
                    }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   218
                    if (textStart == -1) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   219
                        textStart = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   220
                        lastNonWhite = -1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   221
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   222
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   223
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   224
                case '>':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   225
                    newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   226
                    addPendingText(trees, bp - 1);
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   227
                    trees.add(m.at(bp).newErroneousTree(newString(bp, bp + 1), diagSource, "dc.bad.gt"));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   228
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   229
                    if (textStart == -1) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   230
                        textStart = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   231
                        lastNonWhite = -1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   232
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   233
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   234
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   235
                case '{':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   236
                    inlineTag(trees);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   237
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   238
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   239
                case '@':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   240
                    if (newline) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   241
                        addPendingText(trees, lastNonWhite);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   242
                        break loop;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   243
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   244
                    // fallthrough
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   245
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   246
                default:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   247
                    newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   248
                    if (textStart == -1)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   249
                        textStart = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   250
                    lastNonWhite = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   251
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   252
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   253
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   254
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   255
        if (lastNonWhite != -1)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   256
            addPendingText(trees, lastNonWhite);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   257
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   258
        return trees.toList();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   259
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   260
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   261
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   262
     * Read a series of block tags, including their content.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   263
     * Standard tags parse their content appropriately.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   264
     * Non-standard tags are represented by {@link UnknownBlockTag}.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   265
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   266
    protected List<DCTree> blockTags() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
   267
        ListBuffer<DCTree> tags = new ListBuffer<>();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   268
        while (ch == '@')
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   269
            tags.add(blockTag());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   270
        return tags.toList();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   271
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   272
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   273
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   274
     * Read a single block tag, including its content.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   275
     * Standard tags parse their content appropriately.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   276
     * Non-standard tags are represented by {@link UnknownBlockTag}.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   277
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   278
    protected DCTree blockTag() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   279
        int p = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   280
        try {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   281
            nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   282
            if (isIdentifierStart(ch)) {
21894
3535c1819067 8028318: [doclint] doclint will reject existing user-written doc comments using custom tags that follow the recommended rules
jjg
parents: 17273
diff changeset
   283
                Name name = readTagName();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   284
                TagParser tp = tagParsers.get(name);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   285
                if (tp == null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   286
                    List<DCTree> content = blockContent();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   287
                    return m.at(p).newUnknownBlockTagTree(name, content);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   288
                } else {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   289
                    switch (tp.getKind()) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   290
                        case BLOCK:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   291
                            return tp.parse(p);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   292
                        case INLINE:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   293
                            return erroneous("dc.bad.inline.tag", p);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   294
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   295
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   296
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   297
            blockContent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   298
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   299
            return erroneous("dc.no.tag.name", p);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   300
        } catch (ParseException e) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   301
            blockContent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   302
            return erroneous(e.getMessage(), p);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   303
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   304
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   305
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   306
    protected void inlineTag(ListBuffer<DCTree> list) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   307
        newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   308
        nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   309
        if (ch == '@') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   310
            addPendingText(list, bp - 2);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   311
            list.add(inlineTag());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   312
            textStart = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   313
            lastNonWhite = -1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   314
        } else {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   315
            if (textStart == -1)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   316
                textStart = bp - 1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   317
            lastNonWhite = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   318
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   319
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   320
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   321
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   322
     * Read a single inline tag, including its content.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   323
     * Standard tags parse their content appropriately.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   324
     * Non-standard tags are represented by {@link UnknownBlockTag}.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   325
     * Malformed tags may be returned as {@link Erroneous}.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   326
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   327
    protected DCTree inlineTag() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   328
        int p = bp - 1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   329
        try {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   330
            nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   331
            if (isIdentifierStart(ch)) {
21894
3535c1819067 8028318: [doclint] doclint will reject existing user-written doc comments using custom tags that follow the recommended rules
jjg
parents: 17273
diff changeset
   332
                Name name = readTagName();
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   333
                TagParser tp = tagParsers.get(name);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   334
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   335
                if (tp == null) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   336
                    skipWhitespace();
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   337
                    DCTree text = inlineText(WhitespaceRetentionPolicy.REMOVE_ALL);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   338
                    if (text != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   339
                        nextChar();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   340
                        return m.at(p).newUnknownInlineTagTree(name, List.of(text)).setEndPos(bp);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   341
                    }
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   342
                } else {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   343
                    if (!tp.retainWhiteSpace) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   344
                        skipWhitespace();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   345
                    }
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   346
                    if (tp.getKind() == TagParser.Kind.INLINE) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   347
                        DCEndPosTree<?> tree = (DCEndPosTree<?>) tp.parse(p);
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   348
                        if (tree != null) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   349
                            return tree.setEndPos(bp);
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   350
                        }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   351
                    } else { // handle block tags (ex: @see) in inline content
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   352
                        inlineText(WhitespaceRetentionPolicy.REMOVE_ALL); // skip content
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   353
                        nextChar();
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   354
                    }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   355
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   356
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   357
            return erroneous("dc.no.tag.name", p);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   358
        } catch (ParseException e) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   359
            return erroneous(e.getMessage(), p);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   360
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   361
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   362
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   363
    private static enum WhitespaceRetentionPolicy {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   364
        RETAIN_ALL,
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   365
        REMOVE_FIRST_SPACE,
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   366
        REMOVE_ALL
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   367
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   368
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   369
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   370
     * Read plain text content of an inline tag.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   371
     * Matching pairs of { } are skipped; the text is terminated by the first
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   372
     * unmatched }. It is an error if the beginning of the next tag is detected.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   373
     */
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   374
    private DCTree inlineText(WhitespaceRetentionPolicy whitespacePolicy) throws ParseException {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   375
        switch (whitespacePolicy) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   376
            case REMOVE_ALL:
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   377
                skipWhitespace();
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   378
                break;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   379
            case REMOVE_FIRST_SPACE:
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   380
                if (ch == ' ')
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   381
                    nextChar();
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   382
                break;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   383
            case RETAIN_ALL:
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   384
            default:
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   385
                // do nothing
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   386
                break;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   387
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   388
        }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   389
        int pos = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   390
        int depth = 1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   391
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   392
        loop:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   393
        while (bp < buflen) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   394
            switch (ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   395
                case '\n': case '\r': case '\f':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   396
                    newline = true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   397
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   398
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   399
                case ' ': case '\t':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   400
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   401
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   402
                case '{':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   403
                    newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   404
                    lastNonWhite = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   405
                    depth++;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   406
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   407
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   408
                case '}':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   409
                    if (--depth == 0) {
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   410
                        return m.at(pos).newTextTree(newString(pos, bp));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   411
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   412
                    newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   413
                    lastNonWhite = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   414
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   415
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   416
                case '@':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   417
                    if (newline)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   418
                        break loop;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   419
                    newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   420
                    lastNonWhite = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   421
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   422
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   423
                default:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   424
                    newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   425
                    lastNonWhite = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   426
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   427
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   428
            nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   429
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   430
        throw new ParseException("dc.unterminated.inline.tag");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   431
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   432
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   433
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   434
     * Read Java class name, possibly followed by member
31751
ec251536a004 8080880: some docs cleanup for langtools
avstepan
parents: 29775
diff changeset
   435
     * Matching pairs of {@literal < >} are skipped. The text is terminated by the first
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   436
     * unmatched }. It is an error if the beginning of the next tag is detected.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   437
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   438
    // TODO: boolean allowMember should be enum FORBID, ALLOW, REQUIRE
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   439
    // TODO: improve quality of parse to forbid bad constructions.
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   440
    // TODO: update to use ReferenceParser
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   441
    @SuppressWarnings("fallthrough")
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   442
    protected DCReference reference(boolean allowMember) throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   443
        int pos = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   444
        int depth = 0;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   445
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   446
        // scan to find the end of the signature, by looking for the first
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   447
        // whitespace not enclosed in () or <>, or the end of the tag
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   448
        loop:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   449
        while (bp < buflen) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   450
            switch (ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   451
                case '\n': case '\r': case '\f':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   452
                    newline = true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   453
                    // fallthrough
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   454
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   455
                case ' ': case '\t':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   456
                    if (depth == 0)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   457
                        break loop;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   458
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   459
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   460
                case '(':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   461
                case '<':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   462
                    newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   463
                    depth++;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   464
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   465
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   466
                case ')':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   467
                case '>':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   468
                    newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   469
                    --depth;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   470
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   471
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   472
                case '}':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   473
                    if (bp == pos)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   474
                        return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   475
                    newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   476
                    break loop;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   477
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   478
                case '@':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   479
                    if (newline)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   480
                        break loop;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   481
                    // fallthrough
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   482
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   483
                default:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   484
                    newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   485
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   486
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   487
            nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   488
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   489
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   490
        if (depth != 0)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   491
            throw new ParseException("dc.unterminated.signature");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   492
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   493
        String sig = newString(pos, bp);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   494
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   495
        // Break sig apart into qualifiedExpr member paramTypes.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   496
        JCTree qualExpr;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   497
        Name member;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   498
        List<JCTree> paramTypes;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   499
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   500
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   501
                = new Log.DeferredDiagnosticHandler(fac.log);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   502
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   503
        try {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   504
            int hash = sig.indexOf("#");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   505
            int lparen = sig.indexOf("(", hash + 1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   506
            if (hash == -1) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   507
                if (lparen == -1) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   508
                    qualExpr = parseType(sig);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   509
                    member = null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   510
                } else {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   511
                    qualExpr = null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   512
                    member = parseMember(sig.substring(0, lparen));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   513
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   514
            } else {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   515
                qualExpr = (hash == 0) ? null : parseType(sig.substring(0, hash));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   516
                if (lparen == -1)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   517
                    member = parseMember(sig.substring(hash + 1));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   518
                else
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   519
                    member = parseMember(sig.substring(hash + 1, lparen));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   520
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   521
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   522
            if (lparen < 0) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   523
                paramTypes = null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   524
            } else {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   525
                int rparen = sig.indexOf(")", lparen);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   526
                if (rparen != sig.length() - 1)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   527
                    throw new ParseException("dc.ref.bad.parens");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   528
                paramTypes = parseParams(sig.substring(lparen + 1, rparen));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   529
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   530
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   531
            if (!deferredDiagnosticHandler.getDiagnostics().isEmpty())
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   532
                throw new ParseException("dc.ref.syntax.error");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   533
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   534
        } finally {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   535
            fac.log.popDiagnosticHandler(deferredDiagnosticHandler);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   536
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   537
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   538
        return m.at(pos).newReferenceTree(sig, qualExpr, member, paramTypes).setEndPos(bp);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   539
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   540
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   541
    JCTree parseType(String s) throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   542
        JavacParser p = fac.newParser(s, false, false, false);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   543
        JCTree tree = p.parseType();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   544
        if (p.token().kind != TokenKind.EOF)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   545
            throw new ParseException("dc.ref.unexpected.input");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   546
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   547
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   548
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   549
    Name parseMember(String s) throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   550
        JavacParser p = fac.newParser(s, false, false, false);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   551
        Name name = p.ident();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   552
        if (p.token().kind != TokenKind.EOF)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   553
            throw new ParseException("dc.ref.unexpected.input");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   554
        return name;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   555
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   556
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   557
    List<JCTree> parseParams(String s) throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   558
        if (s.trim().isEmpty())
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   559
            return List.nil();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   560
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   561
        JavacParser p = fac.newParser(s.replace("...", "[]"), false, false, false);
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
   562
        ListBuffer<JCTree> paramTypes = new ListBuffer<>();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   563
        paramTypes.add(p.parseType());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   564
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   565
        if (p.token().kind == TokenKind.IDENTIFIER)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   566
            p.nextToken();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   567
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   568
        while (p.token().kind == TokenKind.COMMA) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   569
            p.nextToken();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   570
            paramTypes.add(p.parseType());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   571
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   572
            if (p.token().kind == TokenKind.IDENTIFIER)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   573
                p.nextToken();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   574
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   575
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   576
        if (p.token().kind != TokenKind.EOF)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   577
            throw new ParseException("dc.ref.unexpected.input");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   578
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   579
        return paramTypes.toList();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   580
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   581
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   582
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   583
     * Read Java identifier
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   584
     * Matching pairs of { } are skipped; the text is terminated by the first
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   585
     * unmatched }. It is an error if the beginning of the next tag is detected.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   586
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   587
    @SuppressWarnings("fallthrough")
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   588
    protected DCIdentifier identifier() throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   589
        skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   590
        int pos = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   591
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   592
        if (isJavaIdentifierStart(ch)) {
15552
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
   593
            Name name = readJavaIdentifier();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   594
            return m.at(pos).newIdentifierTree(name);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   595
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   596
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   597
        throw new ParseException("dc.identifier.expected");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   598
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   599
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   600
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   601
     * Read a quoted string.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   602
     * It is an error if the beginning of the next tag is detected.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   603
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   604
    @SuppressWarnings("fallthrough")
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   605
    protected DCText quotedString() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   606
        int pos = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   607
        nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   608
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   609
        loop:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   610
        while (bp < buflen) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   611
            switch (ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   612
                case '\n': case '\r': case '\f':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   613
                    newline = true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   614
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   615
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   616
                case ' ': case '\t':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   617
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   618
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   619
                case '"':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   620
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   621
                    // trim trailing white-space?
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   622
                    return m.at(pos).newTextTree(newString(pos, bp));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   623
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   624
                case '@':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   625
                    if (newline)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   626
                        break loop;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   627
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   628
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   629
            nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   630
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   631
        return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   632
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   633
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   634
    /**
34567
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   635
     * Read a term ie. one word.
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   636
     * It is an error if the beginning of the next tag is detected.
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   637
     */
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   638
    @SuppressWarnings("fallthrough")
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   639
    protected DCText inlineWord() {
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   640
        int pos = bp;
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   641
        int depth = 0;
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   642
        loop:
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   643
        while (bp < buflen) {
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   644
            switch (ch) {
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   645
                case '\n':
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   646
                    newline = true;
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   647
                    // fallthrough
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   648
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   649
                case '\r': case '\f': case ' ': case '\t':
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   650
                    return m.at(pos).newTextTree(newString(pos, bp));
34567
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   651
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   652
                case '@':
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   653
                    if (newline)
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   654
                        break loop;
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   655
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   656
                case '{':
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   657
                    depth++;
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   658
                    break;
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   659
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   660
                case '}':
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   661
                    if (depth == 0 || --depth == 0)
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   662
                        return m.at(pos).newTextTree(newString(pos, bp));
34567
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   663
                    break;
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   664
            }
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   665
            newline = false;
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   666
            nextChar();
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   667
        }
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   668
        return null;
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   669
    }
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   670
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   671
    /**
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   672
     * Read general text content of an inline tag, including HTML entities and elements.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   673
     * Matching pairs of { } are skipped; the text is terminated by the first
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   674
     * unmatched }. It is an error if the beginning of the next tag is detected.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   675
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   676
    @SuppressWarnings("fallthrough")
34567
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   677
    private List<DCTree> inlineContent() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
   678
        ListBuffer<DCTree> trees = new ListBuffer<>();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   679
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   680
        skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   681
        int pos = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   682
        int depth = 1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   683
        textStart = -1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   684
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   685
        loop:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   686
        while (bp < buflen) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   687
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   688
            switch (ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   689
                case '\n': case '\r': case '\f':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   690
                    newline = true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   691
                    // fall through
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   692
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   693
                case ' ': case '\t':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   694
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   695
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   696
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   697
                case '&':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   698
                    entity(trees);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   699
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   700
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   701
                case '<':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   702
                    newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   703
                    addPendingText(trees, bp - 1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   704
                    trees.add(html());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   705
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   706
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   707
                case '{':
34567
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   708
                    if (textStart == -1)
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
   709
                        textStart = bp;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   710
                    newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   711
                    depth++;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   712
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   713
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   714
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   715
                case '}':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   716
                    newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   717
                    if (--depth == 0) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   718
                        addPendingText(trees, bp - 1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   719
                        nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   720
                        return trees.toList();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   721
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   722
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   723
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   724
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   725
                case '@':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   726
                    if (newline)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   727
                        break loop;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   728
                    // fallthrough
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   729
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   730
                default:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   731
                    if (textStart == -1)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   732
                        textStart = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   733
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   734
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   735
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   736
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   737
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 37009
diff changeset
   738
        return List.of(erroneous("dc.unterminated.inline.tag", pos));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   739
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   740
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   741
    protected void entity(ListBuffer<DCTree> list) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   742
        newline = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   743
        addPendingText(list, bp - 1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   744
        list.add(entity());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   745
        if (textStart == -1) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   746
            textStart = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   747
            lastNonWhite = -1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   748
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   749
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   750
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   751
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   752
     * Read an HTML entity.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   753
     * {@literal &identifier; } or {@literal &#digits; } or {@literal &#xhex-digits; }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   754
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   755
    protected DCTree entity() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   756
        int p = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   757
        nextChar();
15552
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
   758
        Name name = null;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   759
        if (ch == '#') {
15552
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
   760
            int namep = bp;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   761
            nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   762
            if (isDecimalDigit(ch)) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   763
                nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   764
                while (isDecimalDigit(ch))
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   765
                    nextChar();
15552
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
   766
                name = names.fromChars(buf, namep, bp - namep);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   767
            } else if (ch == 'x' || ch == 'X') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   768
                nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   769
                if (isHexDigit(ch)) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   770
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   771
                    while (isHexDigit(ch))
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   772
                        nextChar();
15552
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
   773
                    name = names.fromChars(buf, namep, bp - namep);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   774
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   775
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   776
        } else if (isIdentifierStart(ch)) {
15552
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
   777
            name = readIdentifier();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   778
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   779
15552
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
   780
        if (name == null)
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
   781
            return erroneous("dc.bad.entity", p);
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
   782
        else {
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
   783
            if (ch != ';')
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
   784
                return erroneous("dc.missing.semicolon", p);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   785
            nextChar();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   786
            return m.at(p).newEntityTree(name);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   787
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   788
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   789
55204
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   790
    /**
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   791
     * Returns whether this is the end of the preamble of an HTML file.
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   792
     * The preamble ends with start of {@code body} element followed by
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   793
     * possible whitespace and the start of a {@code main} element.
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   794
     *
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   795
     * @return whether this is the end of the preamble
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   796
     */
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   797
    boolean isEndPreamble() {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   798
        final int savedpos = bp;
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   799
        try {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   800
            if (ch == '<')
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   801
                nextChar();
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   802
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   803
            if (isIdentifierStart(ch)) {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   804
                String name = StringUtils.toLowerCase(readIdentifier().toString());
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   805
                switch (name) {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   806
                    case "body":
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   807
                        // Check if also followed by <main>
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   808
                        // 1. skip rest of <body>
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   809
                        while (ch != -1 && ch != '>') {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   810
                            nextChar();
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   811
                        }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   812
                        if (ch == '>') {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   813
                            nextChar();
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   814
                        }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   815
                        // 2. skip any whitespce
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   816
                        while (ch != -1 && Character.isWhitespace(ch)) {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   817
                            nextChar();
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   818
                        }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   819
                        // 3. check if looking at "<main..."
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   820
                        if (ch == '<') {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   821
                            nextChar();
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   822
                            if (isIdentifierStart(ch)) {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   823
                                name = StringUtils.toLowerCase(readIdentifier().toString());
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   824
                                if (name.equals("main")) {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   825
                                    return false;
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   826
                                }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   827
                            }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   828
                        }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   829
                        // if <body> is _not_ followed by <main> then this is the
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   830
                        // end of the preamble
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   831
                        return true;
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   832
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   833
                    case "main":
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   834
                        // <main> is unconditionally the end of the preamble
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   835
                        return true;
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   836
                }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   837
            }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   838
            return false;
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   839
        } finally {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   840
            bp = savedpos;
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   841
            ch = buf[bp];
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   842
        }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   843
    }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   844
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   845
    /**
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   846
     * Returns whether this is the end of the main body of the content in a standalone
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   847
     * HTML file.
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   848
     * The content ends with the closing tag for a {@code main} or {@code body} element.
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   849
     *
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   850
     * @return whether this is the end of the main body of the content
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   851
     */
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   852
    boolean isEndBody() {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   853
        final int savedpos = bp;
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   854
        try {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   855
            if (ch == '<')
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   856
                nextChar();
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   857
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   858
            if (ch == '/') {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   859
                nextChar();
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   860
                if (isIdentifierStart(ch)) {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   861
                    String name = StringUtils.toLowerCase(readIdentifier().toString());
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   862
                    switch (name) {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   863
                        case "body":
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   864
                        case "main":
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   865
                            return true;
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   866
                    }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   867
                }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   868
            }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   869
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   870
            return false;
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   871
        } finally {
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   872
            bp = savedpos;
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   873
            ch = buf[bp];
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   874
        }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   875
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   876
    }
0289438c1286 8223805: DocCommentParser should allow for <main> and </main>
jjg
parents: 52487
diff changeset
   877
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   878
    boolean peek(String s) {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   879
        final int savedpos = bp;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   880
        try {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   881
            if (ch == '<')
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   882
                nextChar();
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   883
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   884
            if (ch == '/') {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   885
                if (s.charAt(0) != ch) {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   886
                    return false;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   887
                } else {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   888
                    s = s.substring(1, s.length());
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   889
                    nextChar();
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   890
                }
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   891
            }
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   892
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   893
            if (isIdentifierStart(ch)) {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   894
                Name name = readIdentifier();
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   895
                return StringUtils.toLowerCase(name.toString()).equals(s);
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   896
            }
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   897
            return false;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   898
        } finally {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   899
            bp = savedpos;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   900
            ch = buf[bp];
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   901
        }
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   902
    }
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   903
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   904
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   905
     * Read the start or end of an HTML tag, or an HTML comment
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   906
     * {@literal <identifier attrs> } or {@literal </identifier> }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   907
     */
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   908
    private DCTree html() {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   909
        int p = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   910
        nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   911
        if (isIdentifierStart(ch)) {
15552
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
   912
            Name name = readIdentifier();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   913
            List<DCTree> attrs = htmlAttrs();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   914
            if (attrs != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   915
                boolean selfClosing = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   916
                if (ch == '/') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   917
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   918
                    selfClosing = true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   919
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   920
                if (ch == '>') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   921
                    nextChar();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   922
                    DCTree dctree = m.at(p).newStartElementTree(name, attrs, selfClosing).setEndPos(bp);
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   923
                    return dctree;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   924
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   925
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   926
        } else if (ch == '/') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   927
            nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   928
            if (isIdentifierStart(ch)) {
15552
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
   929
                Name name = readIdentifier();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   930
                skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   931
                if (ch == '>') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   932
                    nextChar();
55756
d48ffad997b1 8227923: End position of EndElementTree is -1
jlahoda
parents: 55204
diff changeset
   933
                    return m.at(p).newEndElementTree(name).setEndPos(bp);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   934
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   935
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   936
        } else if (ch == '!') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   937
            nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   938
            if (ch == '-') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   939
                nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   940
                if (ch == '-') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   941
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   942
                    while (bp < buflen) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   943
                        int dash = 0;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   944
                        while (ch == '-') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   945
                            dash++;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   946
                            nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   947
                        }
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   948
                        // Strictly speaking, a comment should not contain "--"
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   949
                        // so dash > 2 is an error, dash == 2 implies ch == '>'
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   950
                        // See http://www.w3.org/TR/html-markup/syntax.html#syntax-comments
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   951
                        // for more details.
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   952
                        if (dash >= 2 && ch == '>') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   953
                            nextChar();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   954
                            return m.at(p).newCommentTree(newString(p, bp));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   955
                        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   956
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   957
                        nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   958
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   959
                }
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   960
            } else if (isIdentifierStart(ch) && peek("doctype")) {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   961
                readIdentifier();
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   962
                nextChar();
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   963
                skipWhitespace();
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   964
                int d = bp;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   965
                while (bp < buflen) {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   966
                    if (ch == '>') {
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   967
                        int mark = bp;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   968
                        nextChar();
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   969
                        return m.at(d).newDocTypeTree(newString(d, mark));
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   970
                    }
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   971
                    nextChar();
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   972
                }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   973
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   974
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   975
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   976
        bp = p + 1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   977
        ch = buf[bp];
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   978
        return erroneous("dc.malformed.html", p);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   979
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   980
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   981
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   982
     * Read a series of HTML attributes, terminated by {@literal > }.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   983
     * Each attribute is of the form {@literal identifier[=value] }.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   984
     * "value" may be unquoted, single-quoted, or double-quoted.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   985
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   986
    protected List<DCTree> htmlAttrs() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
   987
        ListBuffer<DCTree> attrs = new ListBuffer<>();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   988
        skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   989
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   990
        loop:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   991
        while (isIdentifierStart(ch)) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   992
            int namePos = bp;
29775
dc7df633fea1 8076026: DocTree should parse hyphenated attributes correctly
bpatel
parents: 25874
diff changeset
   993
            Name name = readAttributeName();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   994
            skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   995
            List<DCTree> value = null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   996
            ValueKind vkind = ValueKind.EMPTY;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   997
            if (ch == '=') {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
   998
                ListBuffer<DCTree> v = new ListBuffer<>();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   999
                nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1000
                skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1001
                if (ch == '\'' || ch == '"') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1002
                    vkind = (ch == '\'') ? ValueKind.SINGLE : ValueKind.DOUBLE;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1003
                    char quote = ch;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1004
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1005
                    textStart = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1006
                    while (bp < buflen && ch != quote) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1007
                        if (newline && ch == '@') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1008
                            attrs.add(erroneous("dc.unterminated.string", namePos));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1009
                            // No point trying to read more.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1010
                            // In fact, all attrs get discarded by the caller
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1011
                            // and superseded by a malformed.html node because
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1012
                            // the html tag itself is not terminated correctly.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1013
                            break loop;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1014
                        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1015
                        attrValueChar(v);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1016
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1017
                    addPendingText(v, bp - 1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1018
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1019
                } else {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1020
                    vkind = ValueKind.UNQUOTED;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1021
                    textStart = bp;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1022
                    while (bp < buflen && !isUnquotedAttrValueTerminator(ch)) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1023
                        attrValueChar(v);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1024
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1025
                    addPendingText(v, bp - 1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1026
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1027
                skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1028
                value = v.toList();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1029
            }
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1030
            DCAttribute attr = m.at(namePos).newAttributeTree(name, vkind, value);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1031
            attrs.add(attr);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1032
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1033
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1034
        return attrs.toList();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1035
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1036
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1037
    protected void attrValueChar(ListBuffer<DCTree> list) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1038
        switch (ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1039
            case '&':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1040
                entity(list);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1041
                break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1042
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1043
            case '{':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1044
                inlineTag(list);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1045
                break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1046
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1047
            default:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1048
                nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1049
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1050
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1051
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1052
    protected void addPendingText(ListBuffer<DCTree> list, int textEnd) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14541
diff changeset
  1053
        if (textStart != -1) {
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14541
diff changeset
  1054
            if (textStart <= textEnd) {
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1055
                list.add(m.at(textStart).newTextTree(newString(textStart, textEnd + 1)));
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14541
diff changeset
  1056
            }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1057
            textStart = -1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1058
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1059
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1060
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1061
    protected DCErroneous erroneous(String code, int pos) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1062
        int i = bp - 1;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1063
        loop:
15552
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
  1064
        while (i > pos) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1065
            switch (buf[i]) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1066
                case '\f': case '\n': case '\r':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1067
                    newline = true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1068
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1069
                case '\t': case ' ':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1070
                    break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1071
                default:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1072
                    break loop;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1073
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1074
            i--;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1075
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1076
        textStart = -1;
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1077
        return m.at(pos).newErroneousTree(newString(pos, i + 1), diagSource, code);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1078
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1079
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1080
    protected boolean isIdentifierStart(char ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1081
        return Character.isUnicodeIdentifierStart(ch);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1082
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1083
15552
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
  1084
    protected Name readIdentifier() {
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
  1085
        int start = bp;
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
  1086
        nextChar();
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
  1087
        while (bp < buflen && Character.isUnicodeIdentifierPart(ch))
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
  1088
            nextChar();
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
  1089
        return names.fromChars(buf, start, bp - start);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1090
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1091
29775
dc7df633fea1 8076026: DocTree should parse hyphenated attributes correctly
bpatel
parents: 25874
diff changeset
  1092
    protected Name readAttributeName() {
dc7df633fea1 8076026: DocTree should parse hyphenated attributes correctly
bpatel
parents: 25874
diff changeset
  1093
        int start = bp;
dc7df633fea1 8076026: DocTree should parse hyphenated attributes correctly
bpatel
parents: 25874
diff changeset
  1094
        nextChar();
dc7df633fea1 8076026: DocTree should parse hyphenated attributes correctly
bpatel
parents: 25874
diff changeset
  1095
        while (bp < buflen && (Character.isUnicodeIdentifierPart(ch) || ch == '-'))
dc7df633fea1 8076026: DocTree should parse hyphenated attributes correctly
bpatel
parents: 25874
diff changeset
  1096
            nextChar();
dc7df633fea1 8076026: DocTree should parse hyphenated attributes correctly
bpatel
parents: 25874
diff changeset
  1097
        return names.fromChars(buf, start, bp - start);
dc7df633fea1 8076026: DocTree should parse hyphenated attributes correctly
bpatel
parents: 25874
diff changeset
  1098
    }
dc7df633fea1 8076026: DocTree should parse hyphenated attributes correctly
bpatel
parents: 25874
diff changeset
  1099
21894
3535c1819067 8028318: [doclint] doclint will reject existing user-written doc comments using custom tags that follow the recommended rules
jjg
parents: 17273
diff changeset
  1100
    protected Name readTagName() {
3535c1819067 8028318: [doclint] doclint will reject existing user-written doc comments using custom tags that follow the recommended rules
jjg
parents: 17273
diff changeset
  1101
        int start = bp;
3535c1819067 8028318: [doclint] doclint will reject existing user-written doc comments using custom tags that follow the recommended rules
jjg
parents: 17273
diff changeset
  1102
        nextChar();
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1103
        while (bp < buflen
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1104
                && (Character.isUnicodeIdentifierPart(ch) || ch == '.'
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1105
                || ch == '-' || ch == ':')) {
21894
3535c1819067 8028318: [doclint] doclint will reject existing user-written doc comments using custom tags that follow the recommended rules
jjg
parents: 17273
diff changeset
  1106
            nextChar();
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1107
        }
21894
3535c1819067 8028318: [doclint] doclint will reject existing user-written doc comments using custom tags that follow the recommended rules
jjg
parents: 17273
diff changeset
  1108
        return names.fromChars(buf, start, bp - start);
3535c1819067 8028318: [doclint] doclint will reject existing user-written doc comments using custom tags that follow the recommended rules
jjg
parents: 17273
diff changeset
  1109
    }
3535c1819067 8028318: [doclint] doclint will reject existing user-written doc comments using custom tags that follow the recommended rules
jjg
parents: 17273
diff changeset
  1110
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1111
    protected boolean isJavaIdentifierStart(char ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1112
        return Character.isJavaIdentifierStart(ch);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1113
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1114
15552
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
  1115
    protected Name readJavaIdentifier() {
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
  1116
        int start = bp;
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
  1117
        nextChar();
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
  1118
        while (bp < buflen && Character.isJavaIdentifierPart(ch))
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
  1119
            nextChar();
99e4c7eb352c 8007096: DocLint parsing problems with some comments
jjg
parents: 14952
diff changeset
  1120
        return names.fromChars(buf, start, bp - start);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1121
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1122
52487
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1123
    protected Name readSystemPropertyName() {
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1124
        int pos = bp;
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1125
        nextChar();
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1126
        while (bp < buflen && Character.isUnicodeIdentifierPart(ch) || ch == '.')
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1127
            nextChar();
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1128
        return names.fromChars(buf, pos, bp - pos);
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1129
    }
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1130
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1131
    protected boolean isDecimalDigit(char ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1132
        return ('0' <= ch && ch <= '9');
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1133
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1134
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1135
    protected boolean isHexDigit(char ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1136
        return ('0' <= ch && ch <= '9')
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1137
                || ('a' <= ch && ch <= 'f')
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1138
                || ('A' <= ch && ch <= 'F');
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1139
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1140
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1141
    protected boolean isUnquotedAttrValueTerminator(char ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1142
        switch (ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1143
            case '\f': case '\n': case '\r': case '\t':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1144
            case ' ':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1145
            case '"': case '\'': case '`':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1146
            case '=': case '<': case '>':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1147
                return true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1148
            default:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1149
                return false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1150
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1151
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1152
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1153
    protected boolean isWhitespace(char ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1154
        return Character.isWhitespace(ch);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1155
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1156
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1157
    protected void skipWhitespace() {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1158
        while (isWhitespace(ch)) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1159
            nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1160
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1161
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1162
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1163
    /**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1164
     * @param start position of first character of string
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1165
     * @param end position of character beyond last character to be included
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1166
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1167
    String newString(int start, int end) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1168
        return new String(buf, start, end - start);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1169
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1170
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1171
    static abstract class TagParser {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1172
        enum Kind { INLINE, BLOCK }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1173
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1174
        final Kind kind;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1175
        final DCTree.Kind treeKind;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1176
        final boolean retainWhiteSpace;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1177
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1178
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1179
        TagParser(Kind k, DCTree.Kind tk) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1180
            kind = k;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1181
            treeKind = tk;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1182
            retainWhiteSpace = false;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1183
        }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1184
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1185
        TagParser(Kind k, DCTree.Kind tk, boolean retainWhiteSpace) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1186
            kind = k;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1187
            treeKind = tk;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1188
            this.retainWhiteSpace = retainWhiteSpace;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1189
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1190
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1191
        Kind getKind() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1192
            return kind;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1193
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1194
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1195
        DCTree.Kind getTreeKind() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1196
            return treeKind;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1197
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1198
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1199
        abstract DCTree parse(int pos) throws ParseException;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1200
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1201
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1202
    /**
44810
448516ac7b09 8157763: update links to technotes in javadoc API
jjg
parents: 43261
diff changeset
  1203
     * @see <a href="http://docs.oracle.com/javase/8/docs/technotes/tools/unix/javadoc.html#CHDJGIJB">Javadoc Tags</a>
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1204
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1205
    private void initTagParsers() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1206
        TagParser[] parsers = {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1207
            // @author name-text
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1208
            new TagParser(Kind.BLOCK, DCTree.Kind.AUTHOR) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1209
                public DCTree parse(int pos) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1210
                    List<DCTree> name = blockContent();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1211
                    return m.at(pos).newAuthorTree(name);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1212
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1213
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1214
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1215
            // {@code text}
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1216
            new TagParser(Kind.INLINE, DCTree.Kind.CODE, true) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1217
                public DCTree parse(int pos) throws ParseException {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1218
                    DCTree text = inlineText(WhitespaceRetentionPolicy.REMOVE_FIRST_SPACE);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1219
                    nextChar();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1220
                    return m.at(pos).newCodeTree((DCText) text);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1221
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1222
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1223
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1224
            // @deprecated deprecated-text
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1225
            new TagParser(Kind.BLOCK, DCTree.Kind.DEPRECATED) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1226
                public DCTree parse(int pos) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1227
                    List<DCTree> reason = blockContent();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1228
                    return m.at(pos).newDeprecatedTree(reason);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1229
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1230
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1231
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1232
            // {@docRoot}
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1233
            new TagParser(Kind.INLINE, DCTree.Kind.DOC_ROOT) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1234
                public DCTree parse(int pos) throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1235
                    if (ch == '}') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1236
                        nextChar();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1237
                        return m.at(pos).newDocRootTree();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1238
                    }
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1239
                    inlineText(WhitespaceRetentionPolicy.REMOVE_ALL); // skip unexpected content
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1240
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1241
                    throw new ParseException("dc.unexpected.content");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1242
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1243
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1244
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1245
            // @exception class-name description
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1246
            new TagParser(Kind.BLOCK, DCTree.Kind.EXCEPTION) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1247
                public DCTree parse(int pos) throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1248
                    skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1249
                    DCReference ref = reference(false);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1250
                    List<DCTree> description = blockContent();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1251
                    return m.at(pos).newExceptionTree(ref, description);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1252
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1253
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1254
37009
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 35346
diff changeset
  1255
            // @hidden hidden-text
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 35346
diff changeset
  1256
            new TagParser(Kind.BLOCK, DCTree.Kind.HIDDEN) {
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 35346
diff changeset
  1257
                public DCTree parse(int pos) {
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 35346
diff changeset
  1258
                    List<DCTree> reason = blockContent();
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 35346
diff changeset
  1259
                    return m.at(pos).newHiddenTree(reason);
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 35346
diff changeset
  1260
                }
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 35346
diff changeset
  1261
            },
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 35346
diff changeset
  1262
34567
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1263
            // @index search-term options-description
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1264
            new TagParser(Kind.INLINE, DCTree.Kind.INDEX) {
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1265
                public DCTree parse(int pos) throws ParseException {
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1266
                    skipWhitespace();
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1267
                    if (ch == '}') {
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1268
                        throw new ParseException("dc.no.content");
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1269
                    }
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1270
                    DCTree term = ch == '"' ? quotedString() : inlineWord();
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1271
                    if (term == null) {
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1272
                        throw new ParseException("dc.no.content");
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1273
                    }
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1274
                    skipWhitespace();
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1275
                    List<DCTree> description = List.nil();
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1276
                    if (ch != '}') {
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1277
                        description = inlineContent();
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1278
                    } else {
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1279
                        nextChar();
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1280
                    }
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1281
                    return m.at(pos).newIndexTree(term, description);
34567
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1282
                }
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1283
            },
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33360
diff changeset
  1284
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1285
            // {@inheritDoc}
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1286
            new TagParser(Kind.INLINE, DCTree.Kind.INHERIT_DOC) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1287
                public DCTree parse(int pos) throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1288
                    if (ch == '}') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1289
                        nextChar();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1290
                        return m.at(pos).newInheritDocTree();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1291
                    }
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1292
                    inlineText(WhitespaceRetentionPolicy.REMOVE_ALL); // skip unexpected content
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1293
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1294
                    throw new ParseException("dc.unexpected.content");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1295
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1296
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1297
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1298
            // {@link package.class#member label}
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1299
            new TagParser(Kind.INLINE, DCTree.Kind.LINK) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1300
                public DCTree parse(int pos) throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1301
                    DCReference ref = reference(true);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1302
                    List<DCTree> label = inlineContent();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1303
                    return m.at(pos).newLinkTree(ref, label);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1304
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1305
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1306
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1307
            // {@linkplain package.class#member label}
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1308
            new TagParser(Kind.INLINE, DCTree.Kind.LINK_PLAIN) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1309
                public DCTree parse(int pos) throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1310
                    DCReference ref = reference(true);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1311
                    List<DCTree> label = inlineContent();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1312
                    return m.at(pos).newLinkPlainTree(ref, label);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1313
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1314
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1315
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1316
            // {@literal text}
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1317
            new TagParser(Kind.INLINE, DCTree.Kind.LITERAL, true) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1318
                public DCTree parse(int pos) throws ParseException {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
  1319
                    DCTree text = inlineText(WhitespaceRetentionPolicy.REMOVE_FIRST_SPACE);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1320
                    nextChar();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1321
                    return m.at(pos).newLiteralTree((DCText) text);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1322
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1323
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1324
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1325
            // @param parameter-name description
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1326
            new TagParser(Kind.BLOCK, DCTree.Kind.PARAM) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1327
                public DCTree parse(int pos) throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1328
                    skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1329
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1330
                    boolean typaram = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1331
                    if (ch == '<') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1332
                        typaram = true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1333
                        nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1334
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1335
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1336
                    DCIdentifier id = identifier();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1337
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1338
                    if (typaram) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1339
                        if (ch != '>')
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1340
                            throw new ParseException("dc.gt.expected");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1341
                        nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1342
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1343
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1344
                    skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1345
                    List<DCTree> desc = blockContent();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1346
                    return m.at(pos).newParamTree(typaram, id, desc);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1347
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1348
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1349
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1350
            // @provides service-name description
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1351
            new TagParser(Kind.BLOCK, DCTree.Kind.PROVIDES) {
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1352
                public DCTree parse(int pos) throws ParseException {
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1353
                    skipWhitespace();
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1354
                    DCReference ref = reference(true);
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1355
                    List<DCTree> description = blockContent();
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1356
                    return m.at(pos).newProvidesTree(ref, description);
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1357
                }
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1358
            },
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1359
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1360
            // @return description
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1361
            new TagParser(Kind.BLOCK, DCTree.Kind.RETURN) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1362
                public DCTree parse(int pos) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1363
                    List<DCTree> description = blockContent();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1364
                    return m.at(pos).newReturnTree(description);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1365
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1366
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1367
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1368
            // @see reference | quoted-string | HTML
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1369
            new TagParser(Kind.BLOCK, DCTree.Kind.SEE) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1370
                public DCTree parse(int pos) throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1371
                    skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1372
                    switch (ch) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1373
                        case '"':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1374
                            DCText string = quotedString();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1375
                            if (string != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1376
                                skipWhitespace();
22692
51651a2a3443 8031212: doclint incorrectly rejects some @see tags in javadoc comments
jjg
parents: 22163
diff changeset
  1377
                                if (ch == '@'
51651a2a3443 8031212: doclint incorrectly rejects some @see tags in javadoc comments
jjg
parents: 22163
diff changeset
  1378
                                        || ch == EOI && bp == buf.length - 1) {
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1379
                                    return m.at(pos).newSeeTree(List.<DCTree>of(string));
22692
51651a2a3443 8031212: doclint incorrectly rejects some @see tags in javadoc comments
jjg
parents: 22163
diff changeset
  1380
                                }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1381
                            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1382
                            break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1383
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1384
                        case '<':
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1385
                            List<DCTree> html = blockContent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1386
                            if (html != null)
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1387
                                return m.at(pos).newSeeTree(html);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1388
                            break;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1389
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14541
diff changeset
  1390
                        case '@':
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14541
diff changeset
  1391
                            if (newline)
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14541
diff changeset
  1392
                                throw new ParseException("dc.no.content");
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14541
diff changeset
  1393
                            break;
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14541
diff changeset
  1394
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14541
diff changeset
  1395
                        case EOI:
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14541
diff changeset
  1396
                            if (bp == buf.length - 1)
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14541
diff changeset
  1397
                                throw new ParseException("dc.no.content");
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14541
diff changeset
  1398
                            break;
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14541
diff changeset
  1399
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1400
                        default:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1401
                            if (isJavaIdentifierStart(ch) || ch == '#') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1402
                                DCReference ref = reference(true);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1403
                                List<DCTree> description = blockContent();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1404
                                return m.at(pos).newSeeTree(description.prepend(ref));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1405
                            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1406
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1407
                    throw new ParseException("dc.unexpected.content");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1408
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1409
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1410
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1411
            // @serialData data-description
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1412
            new TagParser(Kind.BLOCK, DCTree.Kind.SERIAL_DATA) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1413
                public DCTree parse(int pos) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1414
                    List<DCTree> description = blockContent();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1415
                    return m.at(pos).newSerialDataTree(description);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1416
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1417
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1418
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1419
            // @serialField field-name field-type description
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1420
            new TagParser(Kind.BLOCK, DCTree.Kind.SERIAL_FIELD) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1421
                public DCTree parse(int pos) throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1422
                    skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1423
                    DCIdentifier name = identifier();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1424
                    skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1425
                    DCReference type = reference(false);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1426
                    List<DCTree> description = null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1427
                    if (isWhitespace(ch)) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1428
                        skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1429
                        description = blockContent();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1430
                    }
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1431
                    return m.at(pos).newSerialFieldTree(name, type, description);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1432
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1433
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1434
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1435
            // @serial field-description | include | exclude
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1436
            new TagParser(Kind.BLOCK, DCTree.Kind.SERIAL) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1437
                public DCTree parse(int pos) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1438
                    List<DCTree> description = blockContent();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1439
                    return m.at(pos).newSerialTree(description);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1440
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1441
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1442
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1443
            // @since since-text
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1444
            new TagParser(Kind.BLOCK, DCTree.Kind.SINCE) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1445
                public DCTree parse(int pos) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1446
                    List<DCTree> description = blockContent();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1447
                    return m.at(pos).newSinceTree(description);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1448
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1449
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1450
46184
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 44810
diff changeset
  1451
            // @summary summary-text
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 44810
diff changeset
  1452
            new TagParser(Kind.INLINE, DCTree.Kind.SUMMARY) {
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 44810
diff changeset
  1453
                public DCTree parse(int pos) throws ParseException {
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 44810
diff changeset
  1454
                    List<DCTree> summary = inlineContent();
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 44810
diff changeset
  1455
                    return m.at(pos).newSummaryTree(summary);
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 44810
diff changeset
  1456
                }
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 44810
diff changeset
  1457
            },
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 44810
diff changeset
  1458
52487
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1459
            // @systemProperty property-name
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1460
            new TagParser(Kind.INLINE, DCTree.Kind.SYSTEM_PROPERTY) {
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1461
                public DCTree parse(int pos) throws ParseException {
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1462
                    skipWhitespace();
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1463
                    if (ch == '}') {
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1464
                        throw new ParseException("dc.no.content");
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1465
                    }
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1466
                    Name propertyName = readSystemPropertyName();
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1467
                    if (propertyName == null) {
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1468
                        throw new ParseException("dc.no.content");
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1469
                    }
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1470
                    skipWhitespace();
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1471
                    if (ch != '}') {
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1472
                        nextChar();
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1473
                        throw new ParseException("dc.unexpected.content");
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1474
                    } else {
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1475
                        nextChar();
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1476
                        return m.at(pos).newSystemPropertyTree(propertyName);
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1477
                    }
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1478
                }
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1479
            },
5d1d07b72f15 5076751: System properties documentation needed in javadocs
pmuthuswamy
parents: 48028
diff changeset
  1480
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1481
            // @throws class-name description
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1482
            new TagParser(Kind.BLOCK, DCTree.Kind.THROWS) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1483
                public DCTree parse(int pos) throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1484
                    skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1485
                    DCReference ref = reference(false);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1486
                    List<DCTree> description = blockContent();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1487
                    return m.at(pos).newThrowsTree(ref, description);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1488
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1489
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1490
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1491
            // @uses service-name description
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1492
            new TagParser(Kind.BLOCK, DCTree.Kind.USES) {
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1493
                public DCTree parse(int pos) throws ParseException {
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1494
                    skipWhitespace();
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1495
                    DCReference ref = reference(true);
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1496
                    List<DCTree> description = blockContent();
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1497
                    return m.at(pos).newUsesTree(ref, description);
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1498
                }
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1499
            },
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 42828
diff changeset
  1500
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1501
            // {@value package.class#field}
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1502
            new TagParser(Kind.INLINE, DCTree.Kind.VALUE) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1503
                public DCTree parse(int pos) throws ParseException {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1504
                    DCReference ref = reference(true);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1505
                    skipWhitespace();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1506
                    if (ch == '}') {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1507
                        nextChar();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1508
                        return m.at(pos).newValueTree(ref);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1509
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1510
                    nextChar();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1511
                    throw new ParseException("dc.unexpected.content");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1512
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1513
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1514
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1515
            // @version version-text
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1516
            new TagParser(Kind.BLOCK, DCTree.Kind.VERSION) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1517
                public DCTree parse(int pos) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1518
                    List<DCTree> description = blockContent();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
  1519
                    return m.at(pos).newVersionTree(description);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1520
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1521
            },
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1522
        };
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1523
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
  1524
        tagParsers = new HashMap<>();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1525
        for (TagParser p: parsers)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1526
            tagParsers.put(names.fromString(p.getTreeKind().tagName), p);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1527
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1528
    }
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
  1529
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
  1530
}