langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DocTreeMaker.java
author ksrini
Tue, 15 Aug 2017 13:16:32 -0700
changeset 46184 f1325703ea85
parent 42831 feff6f296019
permissions -rw-r--r--
8173425: Javadoc needs a new tag to specify the summary. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     1
/*
46184
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
     2
 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     4
 *
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  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.tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    27
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    28
import java.text.BreakIterator;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    29
import java.util.ArrayList;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    30
import java.util.Collection;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    31
import java.util.EnumSet;
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    32
import java.util.List;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    33
import java.util.ListIterator;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    34
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    35
import javax.lang.model.element.Name;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    36
import javax.tools.Diagnostic;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    37
import javax.tools.JavaFileObject;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    38
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    39
import com.sun.source.doctree.AttributeTree.ValueKind;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    40
import com.sun.source.doctree.DocTree;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    41
import com.sun.source.doctree.DocTree.Kind;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    42
import com.sun.source.doctree.EndElementTree;
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    43
import com.sun.source.doctree.IdentifierTree;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    44
import com.sun.source.doctree.ReferenceTree;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    45
import com.sun.source.doctree.StartElementTree;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    46
import com.sun.source.doctree.TextTree;
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
    47
import com.sun.source.doctree.ProvidesTree;
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
    48
import com.sun.source.doctree.UsesTree;
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    49
import com.sun.source.util.DocTreeFactory;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    50
import com.sun.tools.doclint.HtmlTag;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    51
import com.sun.tools.javac.api.JavacTrees;
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    52
import com.sun.tools.javac.parser.ParserFactory;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    53
import com.sun.tools.javac.parser.ReferenceParser;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    54
import com.sun.tools.javac.parser.Tokens.Comment;
36276
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
    55
import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    56
import com.sun.tools.javac.tree.DCTree.DCAttribute;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    57
import com.sun.tools.javac.tree.DCTree.DCAuthor;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    58
import com.sun.tools.javac.tree.DCTree.DCComment;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    59
import com.sun.tools.javac.tree.DCTree.DCDeprecated;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    60
import com.sun.tools.javac.tree.DCTree.DCDocComment;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    61
import com.sun.tools.javac.tree.DCTree.DCDocRoot;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    62
import com.sun.tools.javac.tree.DCTree.DCEndElement;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    63
import com.sun.tools.javac.tree.DCTree.DCEntity;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    64
import com.sun.tools.javac.tree.DCTree.DCErroneous;
37009
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36276
diff changeset
    65
import com.sun.tools.javac.tree.DCTree.DCHidden;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    66
import com.sun.tools.javac.tree.DCTree.DCIdentifier;
34567
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
    67
import com.sun.tools.javac.tree.DCTree.DCIndex;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    68
import com.sun.tools.javac.tree.DCTree.DCInheritDoc;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    69
import com.sun.tools.javac.tree.DCTree.DCLink;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    70
import com.sun.tools.javac.tree.DCTree.DCLiteral;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    71
import com.sun.tools.javac.tree.DCTree.DCParam;
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
    72
import com.sun.tools.javac.tree.DCTree.DCProvides;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    73
import com.sun.tools.javac.tree.DCTree.DCReference;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    74
import com.sun.tools.javac.tree.DCTree.DCReturn;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    75
import com.sun.tools.javac.tree.DCTree.DCSee;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    76
import com.sun.tools.javac.tree.DCTree.DCSerial;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    77
import com.sun.tools.javac.tree.DCTree.DCSerialData;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    78
import com.sun.tools.javac.tree.DCTree.DCSerialField;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    79
import com.sun.tools.javac.tree.DCTree.DCSince;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    80
import com.sun.tools.javac.tree.DCTree.DCStartElement;
46184
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
    81
import com.sun.tools.javac.tree.DCTree.DCSummary;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    82
import com.sun.tools.javac.tree.DCTree.DCText;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    83
import com.sun.tools.javac.tree.DCTree.DCThrows;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    84
import com.sun.tools.javac.tree.DCTree.DCUnknownBlockTag;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    85
import com.sun.tools.javac.tree.DCTree.DCUnknownInlineTag;
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
    86
import com.sun.tools.javac.tree.DCTree.DCUses;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    87
import com.sun.tools.javac.tree.DCTree.DCValue;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    88
import com.sun.tools.javac.tree.DCTree.DCVersion;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    89
import com.sun.tools.javac.util.Context;
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    90
import com.sun.tools.javac.util.DefinedBy;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    91
import com.sun.tools.javac.util.DefinedBy.Api;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    92
import com.sun.tools.javac.util.DiagnosticSource;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    93
import com.sun.tools.javac.util.JCDiagnostic;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    94
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    95
import com.sun.tools.javac.util.ListBuffer;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    96
import com.sun.tools.javac.util.Pair;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    97
import com.sun.tools.javac.util.Position;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    98
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    99
import static com.sun.tools.doclint.HtmlTag.*;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   100
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   101
/**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   102
 *
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   103
 *  <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
   104
 *  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
   105
 *  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
   106
 *  deletion without notice.</b>
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   107
 */
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   108
public class DocTreeMaker implements DocTreeFactory {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   109
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   110
    /** The context key for the tree factory. */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14541
diff changeset
   111
    protected static final Context.Key<DocTreeMaker> treeMakerKey = new Context.Key<>();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   112
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   113
    // A subset of block tags, which acts as sentence breakers, appearing
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   114
    // anywhere but the zero'th position in the first sentence.
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   115
    final EnumSet<HtmlTag> sentenceBreakTags;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   116
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   117
    /** Get the TreeMaker instance. */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   118
    public static DocTreeMaker instance(Context context) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   119
        DocTreeMaker instance = context.get(treeMakerKey);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   120
        if (instance == null)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   121
            instance = new DocTreeMaker(context);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   122
        return instance;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   123
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   124
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   125
    /** The position at which subsequent trees will be created.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   126
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   127
    public int pos = Position.NOPOS;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   128
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   129
    /** Access to diag factory for ErroneousTrees. */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   130
    private final JCDiagnostic.Factory diags;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   131
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   132
    private final JavacTrees trees;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   133
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   134
    /** Utility class to parse reference signatures. */
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   135
    private final ReferenceParser referenceParser;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   136
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   137
    /** Create a tree maker with NOPOS as initial position.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   138
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   139
    protected DocTreeMaker(Context context) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   140
        context.put(treeMakerKey, this);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   141
        diags = JCDiagnostic.Factory.instance(context);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   142
        this.pos = Position.NOPOS;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   143
        trees = JavacTrees.instance(context);
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   144
        referenceParser = new ReferenceParser(ParserFactory.instance(context));
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   145
        sentenceBreakTags = EnumSet.of(H1, H2, H3, H4, H5, H6, PRE, P);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   146
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   147
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   148
    /** Reassign current position.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   149
     */
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   150
    @Override @DefinedBy(Api.COMPILER_TREE)
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   151
    public DocTreeMaker at(int pos) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   152
        this.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   153
        return this;
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
    /** Reassign current position.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   157
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   158
    public DocTreeMaker at(DiagnosticPosition pos) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   159
        this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   160
        return this;
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
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   163
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   164
    public DCAttribute newAttributeTree(javax.lang.model.element.Name name, ValueKind vkind, java.util.List<? extends DocTree> value) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   165
        DCAttribute tree = new DCAttribute(name, vkind, cast(value));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   166
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   167
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   168
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   169
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   170
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   171
    public DCAuthor newAuthorTree(java.util.List<? extends DocTree> name) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   172
        DCAuthor tree = new DCAuthor(cast(name));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   173
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   174
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   175
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   176
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   177
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   178
    public DCLiteral newCodeTree(TextTree text) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   179
        DCLiteral tree = new DCLiteral(Kind.CODE, (DCText) text);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   180
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   181
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   182
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   183
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   184
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   185
    public DCComment newCommentTree(String text) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   186
        DCComment tree = new DCComment(text);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   187
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   188
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   189
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   190
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   191
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   192
    public DCDeprecated newDeprecatedTree(List<? extends DocTree> text) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   193
        DCDeprecated tree = new DCDeprecated(cast(text));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   194
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   195
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   196
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   197
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   198
    public DCDocComment newDocCommentTree(Comment comment, List<? extends DocTree> fullBody, List<? extends DocTree> tags) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   199
        Pair<List<DCTree>, List<DCTree>> pair = splitBody(fullBody);
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   200
        DCDocComment tree = new DCDocComment(comment, cast(fullBody), pair.fst, pair.snd, cast(tags));
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   201
        tree.pos = pos;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   202
        return tree;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   203
    }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   204
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   205
    /*
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   206
     * Primarily to produce a DocCommenTree when given a
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   207
     * first sentence and a body, this is useful, in cases
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   208
     * where the trees are being synthesized by a tool.
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   209
     */
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   210
    @Override @DefinedBy(Api.COMPILER_TREE)
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 37009
diff changeset
   211
    public DCDocComment newDocCommentTree(List<? extends DocTree> fullBody, List<? extends DocTree> tags) {
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   212
        ListBuffer<DCTree> lb = new ListBuffer<>();
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 37009
diff changeset
   213
        lb.addAll(cast(fullBody));
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 37009
diff changeset
   214
        List<DCTree> fBody = lb.toList();
36276
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   215
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   216
        // A dummy comment to keep the diagnostics logic happy.
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   217
        Comment c = new Comment() {
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   218
            @Override
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   219
            public String getText() {
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   220
                return null;
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   221
            }
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   222
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   223
            @Override
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   224
            public int getSourcePos(int index) {
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   225
                return Position.NOPOS;
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   226
            }
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   227
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   228
            @Override
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   229
            public CommentStyle getStyle() {
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   230
                return CommentStyle.JAVADOC;
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   231
            }
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   232
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   233
            @Override
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   234
            public boolean isDeprecated() {
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   235
                return false;
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   236
            }
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   237
        };
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 37009
diff changeset
   238
        Pair<List<DCTree>, List<DCTree>> pair = splitBody(fullBody);
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 37009
diff changeset
   239
        DCDocComment tree = new DCDocComment(c, fBody, pair.fst, pair.snd, cast(tags));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   240
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   241
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   242
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   243
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   244
    public DCDocRoot newDocRootTree() {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   245
        DCDocRoot tree = new DCDocRoot();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   246
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   247
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   248
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   249
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   250
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   251
    public DCEndElement newEndElementTree(Name name) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   252
        DCEndElement tree = new DCEndElement(name);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   253
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   254
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   255
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   256
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   257
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   258
    public DCEntity newEntityTree(Name name) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   259
        DCEntity tree = new DCEntity(name);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   260
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   261
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   262
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   263
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   264
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   265
    public DCErroneous newErroneousTree(String text, Diagnostic<JavaFileObject> diag) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   266
        DCErroneous tree = new DCErroneous(text, (JCDiagnostic) diag);
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   267
        tree.pos = pos;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   268
        return tree;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   269
    }
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   270
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   271
    public DCErroneous newErroneousTree(String text, DiagnosticSource diagSource, String code, Object... args) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   272
        DCErroneous tree = new DCErroneous(text, diags, diagSource, code, args);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   273
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   274
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   275
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   276
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   277
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   278
    public DCThrows newExceptionTree(ReferenceTree name, List<? extends DocTree> description) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   279
        // TODO: verify the reference is just to a type (not a field or method)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   280
        DCThrows tree = new DCThrows(Kind.EXCEPTION, (DCReference) name, cast(description));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   281
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   282
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   283
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   284
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   285
    @Override @DefinedBy(Api.COMPILER_TREE)
37009
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36276
diff changeset
   286
    public DCHidden newHiddenTree(List<? extends DocTree> text) {
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36276
diff changeset
   287
        DCHidden tree = new DCHidden(cast(text));
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36276
diff changeset
   288
        tree.pos = pos;
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36276
diff changeset
   289
        return tree;
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36276
diff changeset
   290
    }
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36276
diff changeset
   291
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36276
diff changeset
   292
    @Override @DefinedBy(Api.COMPILER_TREE)
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   293
    public DCIdentifier newIdentifierTree(Name name) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   294
        DCIdentifier tree = new DCIdentifier(name);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   295
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   296
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   297
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   298
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   299
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   300
    public DCIndex newIndexTree(DocTree term, List<? extends DocTree> description) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   301
        DCIndex tree = new DCIndex((DCTree) term, cast(description));
34567
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   302
        tree.pos = pos;
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   303
        return tree;
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   304
    }
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   305
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   306
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   307
    public DCInheritDoc newInheritDocTree() {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   308
        DCInheritDoc tree = new DCInheritDoc();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   309
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   310
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   311
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   312
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   313
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   314
    public DCLink newLinkTree(ReferenceTree ref, List<? extends DocTree> label) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   315
        DCLink tree = new DCLink(Kind.LINK, (DCReference) ref, cast(label));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   316
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   317
        return tree;
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
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   320
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   321
    public DCLink newLinkPlainTree(ReferenceTree ref, List<? extends DocTree> label) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   322
        DCLink tree = new DCLink(Kind.LINK_PLAIN, (DCReference) ref, cast(label));
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   323
        tree.pos = pos;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   324
        return tree;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   325
    }
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   326
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   327
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   328
    public DCLiteral newLiteralTree(TextTree text) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   329
        DCLiteral tree = new DCLiteral(Kind.LITERAL, (DCText) text);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   330
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   331
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   332
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   333
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   334
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   335
    public DCParam newParamTree(boolean isTypeParameter, IdentifierTree name, List<? extends DocTree> description) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   336
        DCParam tree = new DCParam(isTypeParameter, (DCIdentifier) name, cast(description));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   337
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   338
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   339
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   340
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   341
    @Override @DefinedBy(Api.COMPILER_TREE)
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
   342
    public DCProvides newProvidesTree(ReferenceTree name, List<? extends DocTree> description) {
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
   343
        DCProvides tree = new DCProvides((DCReference) name, cast(description));
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
   344
        tree.pos = pos;
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
   345
        return tree;
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
   346
    }
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
   347
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
   348
    @Override @DefinedBy(Api.COMPILER_TREE)
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   349
    public DCReference newReferenceTree(String signature) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   350
        try {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   351
            ReferenceParser.Reference ref = referenceParser.parse(signature);
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   352
            DCReference tree = new DCReference(signature, ref.qualExpr, ref.member, ref.paramTypes);
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   353
            tree.pos = pos;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   354
            return tree;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   355
        } catch (ReferenceParser.ParseException e) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   356
            throw new IllegalArgumentException("invalid signature", e);
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   357
        }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   358
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   359
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   360
    public DCReference newReferenceTree(String signature, JCTree qualExpr, Name member, List<JCTree> paramTypes) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   361
        DCReference tree = new DCReference(signature, qualExpr, member, paramTypes);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   362
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   363
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   364
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   365
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   366
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   367
    public DCReturn newReturnTree(List<? extends DocTree> description) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   368
        DCReturn tree = new DCReturn(cast(description));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   369
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   370
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   371
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   372
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   373
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   374
    public DCSee newSeeTree(List<? extends DocTree> reference) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   375
        DCSee tree = new DCSee(cast(reference));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   376
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   377
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   378
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   379
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   380
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   381
    public DCSerial newSerialTree(List<? extends DocTree> description) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   382
        DCSerial tree = new DCSerial(cast(description));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   383
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   384
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   385
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   386
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   387
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   388
    public DCSerialData newSerialDataTree(List<? extends DocTree> description) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   389
        DCSerialData tree = new DCSerialData(cast(description));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   390
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   391
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   392
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   393
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   394
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   395
    public DCSerialField newSerialFieldTree(IdentifierTree name, ReferenceTree type, List<? extends DocTree> description) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   396
        DCSerialField tree = new DCSerialField((DCIdentifier) name, (DCReference) type, cast(description));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   397
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   398
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   399
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   400
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   401
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   402
    public DCSince newSinceTree(List<? extends DocTree> text) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   403
        DCSince tree = new DCSince(cast(text));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   404
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   405
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   406
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   407
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   408
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   409
    public DCStartElement newStartElementTree(Name name, List<? extends DocTree> attrs, boolean selfClosing) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   410
        DCStartElement tree = new DCStartElement(name, cast(attrs), selfClosing);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   411
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   412
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   413
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   414
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   415
    @Override @DefinedBy(Api.COMPILER_TREE)
46184
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   416
    public DCSummary newSummaryTree(List<? extends DocTree> text) {
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   417
        DCSummary tree = new DCSummary(cast(text));
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   418
        tree.pos = pos;
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   419
        return tree;
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   420
    }
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   421
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   422
    @Override @DefinedBy(Api.COMPILER_TREE)
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   423
    public DCText newTextTree(String text) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   424
        DCText tree = new DCText(text);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   425
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   426
        return tree;
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
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   429
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   430
    public DCThrows newThrowsTree(ReferenceTree name, List<? extends DocTree> description) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   431
        // TODO: verify the reference is just to a type (not a field or method)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   432
        DCThrows tree = new DCThrows(Kind.THROWS, (DCReference) name, cast(description));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   433
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   434
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   435
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   436
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   437
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   438
    public DCUnknownBlockTag newUnknownBlockTagTree(Name name, List<? extends DocTree> content) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   439
        DCUnknownBlockTag tree = new DCUnknownBlockTag(name, cast(content));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   440
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   441
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   442
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   443
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   444
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   445
    public DCUnknownInlineTag newUnknownInlineTagTree(Name name, List<? extends DocTree> content) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   446
        DCUnknownInlineTag tree = new DCUnknownInlineTag(name, cast(content));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   447
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   448
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   449
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   450
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   451
    @Override @DefinedBy(Api.COMPILER_TREE)
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
   452
    public DCUses newUsesTree(ReferenceTree name, List<? extends DocTree> description) {
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
   453
        DCUses tree = new DCUses((DCReference) name, cast(description));
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
   454
        tree.pos = pos;
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
   455
        return tree;
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
   456
    }
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
   457
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 41452
diff changeset
   458
    @Override @DefinedBy(Api.COMPILER_TREE)
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   459
    public DCValue newValueTree(ReferenceTree ref) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   460
        // TODO: verify the reference is to a constant value
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   461
        DCValue tree = new DCValue((DCReference) ref);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   462
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   463
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   464
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   465
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   466
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   467
    public DCVersion newVersionTree(List<? extends DocTree> text) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   468
        DCVersion tree = new DCVersion(cast(text));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   469
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   470
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   471
    }
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   472
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   473
    @Override @DefinedBy(Api.COMPILER_TREE)
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   474
    public java.util.List<DocTree> getFirstSentence(java.util.List<? extends DocTree> list) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   475
        Pair<List<DCTree>, List<DCTree>> pair = splitBody(list);
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   476
        return new ArrayList<>(pair.fst);
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   477
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   478
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   479
    /*
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   480
     * Breaks up the body tags into the first sentence and its successors.
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   481
     * The first sentence is determined with the presence of a period,
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   482
     * block tag, or a sentence break, as returned by the BreakIterator.
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   483
     * Trailing whitespaces are trimmed.
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   484
     */
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   485
    private Pair<List<DCTree>, List<DCTree>> splitBody(Collection<? extends DocTree> list) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   486
        // pos is modified as we create trees, therefore
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   487
        // we save the pos and restore it later.
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   488
        final int savedpos = this.pos;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   489
        try {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   490
            ListBuffer<DCTree> body = new ListBuffer<>();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   491
            // split body into first sentence and body
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   492
            ListBuffer<DCTree> fs = new ListBuffer<>();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   493
            if (list.isEmpty()) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   494
                return new Pair<>(fs.toList(), body.toList());
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   495
            }
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   496
            boolean foundFirstSentence = false;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   497
            ArrayList<DocTree> alist = new ArrayList<>(list);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   498
            ListIterator<DocTree> itr = alist.listIterator();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   499
            while (itr.hasNext()) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   500
                boolean isFirst = !itr.hasPrevious();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   501
                DocTree dt = itr.next();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   502
                int spos = ((DCTree) dt).pos;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   503
                if (foundFirstSentence) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   504
                    body.add((DCTree) dt);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   505
                    continue;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   506
                }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   507
                switch (dt.getKind()) {
46184
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   508
                    case SUMMARY:
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   509
                        foundFirstSentence = true;
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 42831
diff changeset
   510
                        break;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   511
                    case TEXT:
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   512
                        DCText tt = (DCText) dt;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   513
                        String s = tt.getBody();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   514
                        DocTree peekedNext = itr.hasNext()
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   515
                                ? alist.get(itr.nextIndex())
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   516
                                : null;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   517
                        int sbreak = getSentenceBreak(s, peekedNext);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   518
                        if (sbreak > 0) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   519
                            s = removeTrailingWhitespace(s.substring(0, sbreak));
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   520
                            DCText text = this.at(spos).newTextTree(s);
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   521
                            fs.add(text);
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   522
                            foundFirstSentence = true;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   523
                            int nwPos = skipWhiteSpace(tt.getBody(), sbreak);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   524
                            if (nwPos > 0) {
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   525
                                DCText text2 = this.at(spos + nwPos).newTextTree(tt.getBody().substring(nwPos));
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   526
                                body.add(text2);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   527
                            }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   528
                            continue;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   529
                        } else if (itr.hasNext()) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   530
                            // if the next doctree is a break, remove trailing spaces
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   531
                            peekedNext = alist.get(itr.nextIndex());
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   532
                            boolean sbrk = isSentenceBreak(peekedNext, false);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   533
                            if (sbrk) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   534
                                DocTree next = itr.next();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   535
                                s = removeTrailingWhitespace(s);
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   536
                                DCText text = this.at(spos).newTextTree(s);
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   537
                                fs.add(text);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   538
                                body.add((DCTree) next);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   539
                                foundFirstSentence = true;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   540
                                continue;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   541
                            }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   542
                        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   543
                        break;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   544
                    default:
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   545
                        if (isSentenceBreak(dt, isFirst)) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   546
                            body.add((DCTree) dt);
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   547
                            foundFirstSentence = true;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   548
                            continue;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   549
                        }
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   550
                        break;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   551
                }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   552
                fs.add((DCTree) dt);
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   553
            }
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   554
            return new Pair<>(fs.toList(), body.toList());
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   555
        } finally {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   556
            this.pos = savedpos;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   557
        }
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   558
    }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   559
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   560
    private boolean isTextTree(DocTree tree) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   561
        return tree.getKind() == Kind.TEXT;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   562
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   563
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   564
    /*
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   565
     * Computes the first sentence break, a simple dot-space algorithm.
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   566
     */
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   567
    private int defaultSentenceBreak(String s) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   568
        // scan for period followed by whitespace
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   569
        int period = -1;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   570
        for (int i = 0; i < s.length(); i++) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   571
            switch (s.charAt(i)) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   572
                case '.':
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   573
                    period = i;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   574
                    break;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   575
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   576
                case ' ':
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   577
                case '\f':
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   578
                case '\n':
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   579
                case '\r':
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   580
                case '\t':
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   581
                    if (period >= 0) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   582
                        return i;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   583
                    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   584
                    break;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   585
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   586
                default:
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   587
                    period = -1;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   588
                    break;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   589
            }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   590
        }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   591
        return -1;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   592
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   593
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   594
    /*
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   595
     * Computes the first sentence, if using a default breaker,
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   596
     * the break is returned, if not then a -1, indicating that
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   597
     * more doctree elements are required to be examined.
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   598
     *
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   599
     * BreakIterator.next points to the the start of the following sentence,
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   600
     * and does not provide an easy way to disambiguate between "sentence break",
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   601
     * "possible sentence break" and "not a sentence break" at the end of the input.
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   602
     * For example, BreakIterator.next returns the index for the end
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   603
     * of the string for all of these examples,
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   604
     * using vertical bars to delimit the bounds of the example text
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   605
     * |Abc|        (not a valid end of sentence break, if followed by more text)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   606
     * |Abc.|       (maybe a valid end of sentence break, depending on the following text)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   607
     * |Abc. |      (maybe a valid end of sentence break, depending on the following text)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   608
     * |"Abc." |    (maybe a valid end of sentence break, depending on the following text)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   609
     * |Abc.  |     (definitely a valid end of sentence break)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   610
     * |"Abc."  |   (definitely a valid end of sentence break)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   611
     * Therefore, we have to probe further to determine whether
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   612
     * there really is a sentence break or not at the end of this run of text.
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   613
     */
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   614
    private int getSentenceBreak(String s, DocTree dt) {
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   615
        BreakIterator breakIterator = trees.getBreakIterator();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   616
        if (breakIterator == null) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   617
            return defaultSentenceBreak(s);
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   618
        }
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   619
        breakIterator.setText(s);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   620
        final int sbrk = breakIterator.next();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   621
        // This is the last doctree, found the droid we are looking for
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   622
        if (dt == null) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   623
            return sbrk;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   624
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   625
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   626
        // If the break is well within the span of the string ie. not
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   627
        // at EOL, then we have a clear break.
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   628
        if (sbrk < s.length() - 1) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   629
            return sbrk;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   630
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   631
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   632
        if (isTextTree(dt)) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   633
            // Two adjacent text trees, a corner case, perhaps
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   634
            // produced by a tool synthesizing a doctree. In
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   635
            // this case, does the break lie within the first span,
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   636
            // then we have the droid, otherwise allow the callers
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   637
            // logic to handle the break in the adjacent doctree.
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   638
            TextTree ttnext = (TextTree) dt;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   639
            String combined = s + ttnext.getBody();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   640
            breakIterator.setText(combined);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   641
            int sbrk2 = breakIterator.next();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   642
            if (sbrk < sbrk2) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   643
                return sbrk;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   644
            }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   645
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   646
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   647
        // Is the adjacent tree a sentence breaker ?
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   648
        if (isSentenceBreak(dt, false)) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   649
            return sbrk;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   650
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   651
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   652
        // At this point the adjacent tree is either a javadoc tag ({@..),
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   653
        // html tag (<..) or an entity (&..). Perform a litmus test, by
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   654
        // concatenating a sentence, to validate the break earlier identified.
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   655
        String combined = s + "Dummy Sentence.";
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   656
        breakIterator.setText(combined);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   657
        int sbrk2 = breakIterator.next();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   658
        if (sbrk2 <= sbrk) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   659
            return sbrk2;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   660
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   661
        return -1; // indeterminate at this time
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   662
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   663
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   664
    private boolean isSentenceBreak(javax.lang.model.element.Name tagName) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   665
        return sentenceBreakTags.contains(get(tagName));
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   666
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   667
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   668
    private boolean isSentenceBreak(DocTree dt, boolean isFirstDocTree) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   669
        switch (dt.getKind()) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   670
            case START_ELEMENT:
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   671
                    StartElementTree set = (StartElementTree)dt;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   672
                    return !isFirstDocTree && ((DCTree) dt).pos > 1 && isSentenceBreak(set.getName());
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   673
            case END_ELEMENT:
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   674
                    EndElementTree eet = (EndElementTree)dt;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   675
                    return !isFirstDocTree && ((DCTree) dt).pos > 1 && isSentenceBreak(eet.getName());
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   676
            default:
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   677
                return false;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   678
        }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   679
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   680
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   681
    /*
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   682
     * Returns the position of the the first non-white space
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   683
     */
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   684
    private int skipWhiteSpace(String s, int start) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   685
        for (int i = start; i < s.length(); i++) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   686
            char c = s.charAt(i);
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   687
            if (!Character.isWhitespace(c)) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   688
                return i;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   689
            }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   690
        }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   691
        return -1;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   692
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   693
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   694
    private String removeTrailingWhitespace(String s) {
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   695
        for (int i = s.length() - 1 ; i >= 0 ; i--) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   696
            char ch = s.charAt(i);
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   697
            if (!Character.isWhitespace(ch)) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   698
                return s.substring(0, i + 1);
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   699
            }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   700
        }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   701
        return s;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   702
    }
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   703
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   704
    @SuppressWarnings("unchecked")
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   705
    private List<DCTree> cast(List<? extends DocTree> list) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   706
        return (List<DCTree>) list;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   707
    }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   708
}