langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DocTreeMaker.java
author ksrini
Mon, 10 Oct 2016 11:21:00 -0700
changeset 41452 ddaef4bba083
parent 37009 476d8d615222
child 42831 feff6f296019
permissions -rw-r--r--
8165991: Fix DocTreeFactory newDocCommentTree 8154349: New doclet incorrectly shows entire text body for JavaFX properties in summary section 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
/*
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
     2
 * Copyright (c) 2011, 2016, 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;
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    47
import com.sun.source.util.DocTreeFactory;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    48
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
    49
import com.sun.tools.javac.api.JavacTrees;
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    50
import com.sun.tools.javac.parser.ParserFactory;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    51
import com.sun.tools.javac.parser.ReferenceParser;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    52
import com.sun.tools.javac.parser.Tokens.Comment;
36276
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
    53
import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    54
import com.sun.tools.javac.tree.DCTree.DCAttribute;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    55
import com.sun.tools.javac.tree.DCTree.DCAuthor;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    56
import com.sun.tools.javac.tree.DCTree.DCComment;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    57
import com.sun.tools.javac.tree.DCTree.DCDeprecated;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    58
import com.sun.tools.javac.tree.DCTree.DCDocComment;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    59
import com.sun.tools.javac.tree.DCTree.DCDocRoot;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    60
import com.sun.tools.javac.tree.DCTree.DCEndElement;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    61
import com.sun.tools.javac.tree.DCTree.DCEntity;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    62
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
    63
import com.sun.tools.javac.tree.DCTree.DCHidden;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    64
import com.sun.tools.javac.tree.DCTree.DCIdentifier;
34567
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
    65
import com.sun.tools.javac.tree.DCTree.DCIndex;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    66
import com.sun.tools.javac.tree.DCTree.DCInheritDoc;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    67
import com.sun.tools.javac.tree.DCTree.DCLink;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    68
import com.sun.tools.javac.tree.DCTree.DCLiteral;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    69
import com.sun.tools.javac.tree.DCTree.DCParam;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    70
import com.sun.tools.javac.tree.DCTree.DCReference;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    71
import com.sun.tools.javac.tree.DCTree.DCReturn;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    72
import com.sun.tools.javac.tree.DCTree.DCSee;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    73
import com.sun.tools.javac.tree.DCTree.DCSerial;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    74
import com.sun.tools.javac.tree.DCTree.DCSerialData;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    75
import com.sun.tools.javac.tree.DCTree.DCSerialField;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    76
import com.sun.tools.javac.tree.DCTree.DCSince;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    77
import com.sun.tools.javac.tree.DCTree.DCStartElement;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    78
import com.sun.tools.javac.tree.DCTree.DCText;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    79
import com.sun.tools.javac.tree.DCTree.DCThrows;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    80
import com.sun.tools.javac.tree.DCTree.DCUnknownBlockTag;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    81
import com.sun.tools.javac.tree.DCTree.DCUnknownInlineTag;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    82
import com.sun.tools.javac.tree.DCTree.DCValue;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    83
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
    84
import com.sun.tools.javac.util.Context;
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    85
import com.sun.tools.javac.util.DefinedBy;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
    86
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
    87
import com.sun.tools.javac.util.DiagnosticSource;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    88
import com.sun.tools.javac.util.JCDiagnostic;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    89
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    90
import com.sun.tools.javac.util.ListBuffer;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    91
import com.sun.tools.javac.util.Pair;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    92
import com.sun.tools.javac.util.Position;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    93
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    94
import static com.sun.tools.doclint.HtmlTag.*;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
    95
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    96
/**
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    97
 *
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
    98
 *  <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
    99
 *  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
   100
 *  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
   101
 *  deletion without notice.</b>
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   102
 */
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   103
public class DocTreeMaker implements DocTreeFactory {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   104
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   105
    /** The context key for the tree factory. */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14541
diff changeset
   106
    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
   107
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   108
    // A subset of block tags, which acts as sentence breakers, appearing
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   109
    // anywhere but the zero'th position in the first sentence.
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   110
    final EnumSet<HtmlTag> sentenceBreakTags;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   111
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   112
    /** Get the TreeMaker instance. */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   113
    public static DocTreeMaker instance(Context context) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   114
        DocTreeMaker instance = context.get(treeMakerKey);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   115
        if (instance == null)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   116
            instance = new DocTreeMaker(context);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   117
        return instance;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   118
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   119
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   120
    /** 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
   121
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   122
    public int pos = Position.NOPOS;
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
    /** Access to diag factory for ErroneousTrees. */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   125
    private final JCDiagnostic.Factory diags;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   126
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   127
    private final JavacTrees trees;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   128
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   129
    /** Utility class to parse reference signatures. */
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   130
    private final ReferenceParser referenceParser;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   131
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   132
    /** 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
   133
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   134
    protected DocTreeMaker(Context context) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   135
        context.put(treeMakerKey, this);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   136
        diags = JCDiagnostic.Factory.instance(context);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   137
        this.pos = Position.NOPOS;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   138
        trees = JavacTrees.instance(context);
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   139
        referenceParser = new ReferenceParser(ParserFactory.instance(context));
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   140
        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
   141
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   142
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   143
    /** Reassign current position.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   144
     */
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   145
    @Override @DefinedBy(Api.COMPILER_TREE)
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   146
    public DocTreeMaker at(int pos) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   147
        this.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   148
        return this;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   149
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   150
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   151
    /** Reassign current position.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   152
     */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   153
    public DocTreeMaker at(DiagnosticPosition pos) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   154
        this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   155
        return this;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   156
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   157
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   158
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   159
    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
   160
        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
   161
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   162
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   163
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   164
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   165
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   166
    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
   167
        DCAuthor tree = new DCAuthor(cast(name));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   168
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   169
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   170
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   171
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   172
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   173
    public DCLiteral newCodeTree(TextTree text) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   174
        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
   175
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   176
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   177
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   178
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   179
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   180
    public DCComment newCommentTree(String text) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   181
        DCComment tree = new DCComment(text);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   182
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   183
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   184
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   185
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   186
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   187
    public DCDeprecated newDeprecatedTree(List<? extends DocTree> text) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   188
        DCDeprecated tree = new DCDeprecated(cast(text));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   189
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   190
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   191
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   192
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   193
    public DCDocComment newDocCommentTree(Comment comment, List<? extends DocTree> fullBody, List<? extends DocTree> tags) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   194
        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
   195
        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
   196
        tree.pos = pos;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   197
        return tree;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   198
    }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   199
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   200
    /*
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   201
     * 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
   202
     * 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
   203
     * 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
   204
     */
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   205
    @Override @DefinedBy(Api.COMPILER_TREE)
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 37009
diff changeset
   206
    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
   207
        ListBuffer<DCTree> lb = new ListBuffer<>();
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 37009
diff changeset
   208
        lb.addAll(cast(fullBody));
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 37009
diff changeset
   209
        List<DCTree> fBody = lb.toList();
36276
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   210
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   211
        // A dummy comment to keep the diagnostics logic happy.
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   212
        Comment c = new Comment() {
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   213
            @Override
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   214
            public String getText() {
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   215
                return null;
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   216
            }
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   217
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 int getSourcePos(int index) {
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   220
                return Position.NOPOS;
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 CommentStyle getStyle() {
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   225
                return CommentStyle.JAVADOC;
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 boolean isDeprecated() {
37bd10863a8a 8150130: NPE building javafx docs with new doclet
ksrini
parents: 35346
diff changeset
   230
                return false;
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
        };
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 37009
diff changeset
   233
        Pair<List<DCTree>, List<DCTree>> pair = splitBody(fullBody);
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 37009
diff changeset
   234
        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
   235
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   236
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   237
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   238
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   239
    public DCDocRoot newDocRootTree() {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   240
        DCDocRoot tree = new DCDocRoot();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   241
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   242
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   243
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   244
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   245
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   246
    public DCEndElement newEndElementTree(Name name) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   247
        DCEndElement tree = new DCEndElement(name);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   248
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   249
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   250
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   251
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   252
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   253
    public DCEntity newEntityTree(Name name) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   254
        DCEntity tree = new DCEntity(name);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   255
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   256
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   257
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   258
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   259
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   260
    public DCErroneous newErroneousTree(String text, Diagnostic<JavaFileObject> diag) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   261
        DCErroneous tree = new DCErroneous(text, (JCDiagnostic) diag);
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   262
        tree.pos = pos;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   263
        return tree;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   264
    }
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   265
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   266
    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
   267
        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
   268
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   269
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   270
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   271
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   272
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   273
    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
   274
        // 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
   275
        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
   276
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   277
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   278
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   279
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   280
    @Override @DefinedBy(Api.COMPILER_TREE)
37009
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36276
diff changeset
   281
    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
   282
        DCHidden tree = new DCHidden(cast(text));
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36276
diff changeset
   283
        tree.pos = pos;
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36276
diff changeset
   284
        return tree;
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36276
diff changeset
   285
    }
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36276
diff changeset
   286
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36276
diff changeset
   287
    @Override @DefinedBy(Api.COMPILER_TREE)
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   288
    public DCIdentifier newIdentifierTree(Name name) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   289
        DCIdentifier tree = new DCIdentifier(name);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   290
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   291
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   292
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   293
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   294
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   295
    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
   296
        DCIndex tree = new DCIndex((DCTree) term, cast(description));
34567
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   297
        tree.pos = pos;
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   298
        return tree;
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   299
    }
c74f68484156 8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents: 33424
diff changeset
   300
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   301
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   302
    public DCInheritDoc newInheritDocTree() {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   303
        DCInheritDoc tree = new DCInheritDoc();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   304
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   305
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   306
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   307
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   308
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   309
    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
   310
        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
   311
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   312
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   313
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   314
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   315
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   316
    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
   317
        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
   318
        tree.pos = pos;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   319
        return tree;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   320
    }
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   321
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   322
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   323
    public DCLiteral newLiteralTree(TextTree text) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   324
        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
   325
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   326
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   327
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   328
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   329
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   330
    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
   331
        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
   332
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   333
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   334
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   335
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   336
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   337
    public DCReference newReferenceTree(String signature) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   338
        try {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   339
            ReferenceParser.Reference ref = referenceParser.parse(signature);
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   340
            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
   341
            tree.pos = pos;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   342
            return tree;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   343
        } catch (ReferenceParser.ParseException e) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   344
            throw new IllegalArgumentException("invalid signature", e);
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   345
        }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   346
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   347
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   348
    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
   349
        DCReference tree = new DCReference(signature, qualExpr, member, paramTypes);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   350
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   351
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   352
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   353
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   354
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   355
    public DCReturn newReturnTree(List<? extends DocTree> description) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   356
        DCReturn tree = new DCReturn(cast(description));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   357
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   358
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   359
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   360
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   361
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   362
    public DCSee newSeeTree(List<? extends DocTree> reference) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   363
        DCSee tree = new DCSee(cast(reference));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   364
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   365
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   366
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   367
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   368
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   369
    public DCSerial newSerialTree(List<? extends DocTree> description) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   370
        DCSerial tree = new DCSerial(cast(description));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   371
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   372
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   373
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   374
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   375
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   376
    public DCSerialData newSerialDataTree(List<? extends DocTree> description) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   377
        DCSerialData tree = new DCSerialData(cast(description));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   378
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   379
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   380
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   381
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   382
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   383
    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
   384
        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
   385
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   386
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   387
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   388
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   389
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   390
    public DCSince newSinceTree(List<? extends DocTree> text) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   391
        DCSince tree = new DCSince(cast(text));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   392
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   393
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   394
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   395
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   396
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   397
    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
   398
        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
   399
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   400
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   401
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   402
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   403
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   404
    public DCText newTextTree(String text) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   405
        DCText tree = new DCText(text);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   406
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   407
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   408
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   409
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   410
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   411
    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
   412
        // 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
   413
        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
   414
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   415
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   416
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   417
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   418
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   419
    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
   420
        DCUnknownBlockTag tree = new DCUnknownBlockTag(name, cast(content));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   421
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   422
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   423
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   424
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   425
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   426
    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
   427
        DCUnknownInlineTag tree = new DCUnknownInlineTag(name, cast(content));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   428
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   429
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   430
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   431
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   432
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   433
    public DCValue newValueTree(ReferenceTree ref) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   434
        // 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
   435
        DCValue tree = new DCValue((DCReference) ref);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   436
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   437
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   438
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   439
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   440
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   441
    public DCVersion newVersionTree(List<? extends DocTree> text) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   442
        DCVersion tree = new DCVersion(cast(text));
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   443
        tree.pos = pos;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   444
        return tree;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   445
    }
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   446
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   447
    @Override @DefinedBy(Api.COMPILER_TREE)
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   448
    public java.util.List<DocTree> getFirstSentence(java.util.List<? extends DocTree> list) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   449
        Pair<List<DCTree>, List<DCTree>> pair = splitBody(list);
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   450
        return new ArrayList<>(pair.fst);
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   451
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   452
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   453
    /*
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   454
     * 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
   455
     * 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
   456
     * 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
   457
     * Trailing whitespaces are trimmed.
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   458
     */
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   459
    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
   460
        // 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
   461
        // 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
   462
        final int savedpos = this.pos;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   463
        try {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   464
            ListBuffer<DCTree> body = new ListBuffer<>();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   465
            // 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
   466
            ListBuffer<DCTree> fs = new ListBuffer<>();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   467
            if (list.isEmpty()) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   468
                return new Pair<>(fs.toList(), body.toList());
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   469
            }
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   470
            boolean foundFirstSentence = false;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   471
            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
   472
            ListIterator<DocTree> itr = alist.listIterator();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   473
            while (itr.hasNext()) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   474
                boolean isFirst = !itr.hasPrevious();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   475
                DocTree dt = itr.next();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   476
                int spos = ((DCTree) dt).pos;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   477
                if (foundFirstSentence) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   478
                    body.add((DCTree) dt);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   479
                    continue;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   480
                }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   481
                switch (dt.getKind()) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   482
                    case TEXT:
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   483
                        DCText tt = (DCText) dt;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   484
                        String s = tt.getBody();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   485
                        DocTree peekedNext = itr.hasNext()
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   486
                                ? alist.get(itr.nextIndex())
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   487
                                : null;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   488
                        int sbreak = getSentenceBreak(s, peekedNext);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   489
                        if (sbreak > 0) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   490
                            s = removeTrailingWhitespace(s.substring(0, sbreak));
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   491
                            DCText text = this.at(spos).newTextTree(s);
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   492
                            fs.add(text);
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   493
                            foundFirstSentence = true;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   494
                            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
   495
                            if (nwPos > 0) {
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   496
                                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
   497
                                body.add(text2);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   498
                            }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   499
                            continue;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   500
                        } else if (itr.hasNext()) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   501
                            // 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
   502
                            peekedNext = alist.get(itr.nextIndex());
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   503
                            boolean sbrk = isSentenceBreak(peekedNext, false);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   504
                            if (sbrk) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   505
                                DocTree next = itr.next();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   506
                                s = removeTrailingWhitespace(s);
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   507
                                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
   508
                                fs.add(text);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   509
                                body.add((DCTree) next);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   510
                                foundFirstSentence = true;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   511
                                continue;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   512
                            }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   513
                        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   514
                        break;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   515
                    default:
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   516
                        if (isSentenceBreak(dt, isFirst)) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   517
                            body.add((DCTree) dt);
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   518
                            foundFirstSentence = true;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   519
                            continue;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   520
                        }
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   521
                        break;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   522
                }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   523
                fs.add((DCTree) dt);
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   524
            }
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   525
            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
   526
        } finally {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   527
            this.pos = savedpos;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   528
        }
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   529
    }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   530
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   531
    private boolean isTextTree(DocTree tree) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   532
        return tree.getKind() == Kind.TEXT;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   533
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   534
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   535
    /*
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   536
     * Computes the first sentence break, a simple dot-space algorithm.
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   537
     */
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   538
    private int defaultSentenceBreak(String s) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   539
        // scan for period followed by whitespace
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   540
        int period = -1;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   541
        for (int i = 0; i < s.length(); i++) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   542
            switch (s.charAt(i)) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   543
                case '.':
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   544
                    period = i;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   545
                    break;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   546
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   547
                case ' ':
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   548
                case '\f':
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   549
                case '\n':
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   550
                case '\r':
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   551
                case '\t':
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   552
                    if (period >= 0) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   553
                        return i;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   554
                    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   555
                    break;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   556
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   557
                default:
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   558
                    period = -1;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   559
                    break;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   560
            }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   561
        }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   562
        return -1;
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
    /*
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   566
     * 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
   567
     * 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
   568
     * 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
   569
     *
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   570
     * 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
   571
     * 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
   572
     * "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
   573
     * 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
   574
     * 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
   575
     * 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
   576
     * |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
   577
     * |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
   578
     * |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
   579
     * |"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
   580
     * |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
   581
     * |"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
   582
     * 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
   583
     * 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
   584
     */
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   585
    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
   586
        BreakIterator breakIterator = trees.getBreakIterator();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   587
        if (breakIterator == null) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   588
            return defaultSentenceBreak(s);
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   589
        }
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   590
        breakIterator.setText(s);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   591
        final int sbrk = breakIterator.next();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   592
        // 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
   593
        if (dt == null) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   594
            return sbrk;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   595
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   596
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   597
        // 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
   598
        // 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
   599
        if (sbrk < s.length() - 1) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   600
            return sbrk;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   601
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   602
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   603
        if (isTextTree(dt)) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   604
            // 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
   605
            // 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
   606
            // 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
   607
            // 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
   608
            // 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
   609
            TextTree ttnext = (TextTree) dt;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   610
            String combined = s + ttnext.getBody();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   611
            breakIterator.setText(combined);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   612
            int sbrk2 = breakIterator.next();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   613
            if (sbrk < sbrk2) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   614
                return sbrk;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   615
            }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   616
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   617
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   618
        // 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
   619
        if (isSentenceBreak(dt, false)) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   620
            return sbrk;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   621
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   622
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   623
        // 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
   624
        // 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
   625
        // 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
   626
        String combined = s + "Dummy Sentence.";
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   627
        breakIterator.setText(combined);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   628
        int sbrk2 = breakIterator.next();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   629
        if (sbrk2 <= sbrk) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   630
            return sbrk2;
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
        return -1; // indeterminate at this time
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   633
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   634
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   635
    private boolean isSentenceBreak(javax.lang.model.element.Name tagName) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   636
        return sentenceBreakTags.contains(get(tagName));
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   637
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   638
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   639
    private boolean isSentenceBreak(DocTree dt, boolean isFirstDocTree) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   640
        switch (dt.getKind()) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   641
            case START_ELEMENT:
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   642
                    StartElementTree set = (StartElementTree)dt;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   643
                    return !isFirstDocTree && ((DCTree) dt).pos > 1 && isSentenceBreak(set.getName());
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   644
            case END_ELEMENT:
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   645
                    EndElementTree eet = (EndElementTree)dt;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   646
                    return !isFirstDocTree && ((DCTree) dt).pos > 1 && isSentenceBreak(eet.getName());
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   647
            default:
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   648
                return false;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   649
        }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   650
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   651
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   652
    /*
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   653
     * Returns the position of the the first non-white space
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   654
     */
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   655
    private int skipWhiteSpace(String s, int start) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   656
        for (int i = start; i < s.length(); i++) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   657
            char c = s.charAt(i);
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   658
            if (!Character.isWhitespace(c)) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   659
                return i;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   660
            }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   661
        }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   662
        return -1;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   663
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   664
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   665
    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
   666
        for (int i = s.length() - 1 ; i >= 0 ; i--) {
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   667
            char ch = s.charAt(i);
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   668
            if (!Character.isWhitespace(ch)) {
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   669
                return s.substring(0, i + 1);
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   670
            }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   671
        }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   672
        return s;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 25874
diff changeset
   673
    }
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   674
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   675
    @SuppressWarnings("unchecked")
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   676
    private List<DCTree> cast(List<? extends DocTree> list) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   677
        return (List<DCTree>) list;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 34567
diff changeset
   678
    }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff changeset
   679
}