src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/DocImpl.java
author ksrini
Fri, 09 Feb 2018 13:58:17 -0800
changeset 48840 5e2d2067da48
parent 47216 71c04702a3d5
permissions -rw-r--r--
8194651: javadoc: mark the com.sun.javadoc API for removal Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
48840
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
37938
42baa89d2156 8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents: 31752
diff changeset
    26
package com.sun.tools.javadoc.main;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
8632
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
    28
import java.io.DataInputStream;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 13844
diff changeset
    29
import java.io.IOException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.io.InputStream;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.text.CollationKey;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 13844
diff changeset
    32
import java.util.regex.Matcher;
8d2148961366 8000663: clean up langtools imports
jjg
parents: 13844
diff changeset
    33
import java.util.regex.Pattern;
8d2148961366 8000663: clean up langtools imports
jjg
parents: 13844
diff changeset
    34
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
    35
import javax.tools.FileObject;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
    36
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
    37
import com.sun.javadoc.*;
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    38
import com.sun.source.util.TreePath;
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    39
import com.sun.tools.javac.tree.JCTree;
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    40
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import com.sun.tools.javac.util.Position;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * abstract base class of all Doc classes.  Doc item's are representations
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * of java language constructs (class, package, method,...) which have
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * comments and have been processed by this run of javadoc.  All Doc items
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * are unique, that is, they are == comparable.
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    49
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    50
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    51
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    52
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    53
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 * @since 1.2
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 * @author Robert Field
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 * @author Neal Gafter (rewrite)
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 */
48840
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
    59
@Deprecated(since="9", forRemoval=true)
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
    60
@SuppressWarnings("removal")
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
    61
public abstract class DocImpl implements Doc, Comparable<Object> {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     * Doc environment
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    protected final DocEnv env;   //### Rename this everywhere to 'docenv' ?
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    /**
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    69
     * Back pointer to the tree node for this doc item.
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    70
     * May be null if there is no associated tree.
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    71
     */
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    72
    protected TreePath treePath;
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    73
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    74
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     *  The complex comment object, lazily initialized.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    private Comment comment;
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
     * The cached sort key, to take care of Natural Language Text sorting.
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    private CollationKey collationkey = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     *  Raw documentation string.
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    protected String documentation;  // Accessed in PackageDocImpl, RootDocImpl
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     * Cached first sentence.
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    private Tag[] firstSentence;
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     * Cached inline tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    private Tag[] inlineTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     * Constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     */
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   102
    DocImpl(DocEnv env, TreePath treePath) {
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   103
        this.treePath = treePath;
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   104
        this.documentation = getCommentText(treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        this.env = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   108
    private static String getCommentText(TreePath p) {
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   109
        if (p == null)
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   110
            return null;
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   111
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   112
        JCCompilationUnit topLevel = (JCCompilationUnit) p.getCompilationUnit();
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   113
        JCTree tree = (JCTree) p.getLeaf();
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   114
        return topLevel.docComments.getCommentText(tree);
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   115
    }
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   116
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     * So subclasses have the option to do lazy initialization of
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     * "documentation" string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     */
10189
57268b86d4da 7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents: 8632
diff changeset
   121
    protected String documentation() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        if (documentation == null) documentation = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        return documentation;
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     * For lazy initialization of comment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    Comment comment() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        if (comment == null) {
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   131
            String d = documentation();
43261
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   132
            if (env.javaScriptScanner != null) {
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   133
                env.javaScriptScanner.parse(d, new JavaScriptScanner.Reporter() {
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   134
                    @Override
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   135
                    public void report() {
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   136
                        env.error(DocImpl.this, "javadoc.JavaScript_in_comment");
45742
36bf0f2436ad 8177511: Remove the old standard doclet
ksrini
parents: 43261
diff changeset
   137
                        throw new Error();
43261
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   138
                    }
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   139
                });
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   140
            }
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   141
            if (env.doclint != null
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   142
                    && treePath != null
31752
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 25874
diff changeset
   143
                    && env.shouldCheck(treePath.getCompilationUnit())
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   144
                    && d.equals(getCommentText(treePath))) {
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   145
                env.doclint.scan(treePath);
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   146
            }
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   147
            comment = new Comment(this, d);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        return comment;
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     * Return the text of the comment for this doc item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     * TagImpls have been removed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    public String commentText() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
        return comment().commentText();
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     * Return all tags in this Doc item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
     * @return an array of TagImpl containing all tags on this Doc item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    public Tag[] tags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        return comment().tags();
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     * Return tags of the specified kind in this Doc item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     * @param tagname name of the tag kind to search for.
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * @return an array of TagImpl containing all tags whose 'kind()'
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * matches 'tagname'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    public Tag[] tags(String tagname) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        return comment().tags(tagname);
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * Return the see also tags in this Doc item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     *
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 10189
diff changeset
   183
     * @return an array of SeeTag containing all &#64;see tags.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    public SeeTag[] seeTags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        return comment().seeTags();
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    public Tag[] inlineTags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        if (inlineTags == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
            inlineTags = Comment.getInlineTags(this, commentText());
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        return inlineTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    public Tag[] firstSentenceTags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        if (firstSentence == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
            //Parse all sentences first to avoid duplicate warnings.
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
            inlineTags();
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
                env.setSilent(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
                firstSentence = Comment.firstSentenceTags(this, commentText());
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
            } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
                env.setSilent(false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        return firstSentence;
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     * Utility for subclasses which read HTML documentation files.
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     */
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   213
    String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException {
8632
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   214
        byte[] filecontents = new byte[input.available()];
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   215
        try {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   216
            DataInputStream dataIn = new DataInputStream(input);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   217
            dataIn.readFully(filecontents);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   218
        } finally {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   219
            input.close();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   220
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        String encoding = env.getEncoding();
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        String rawDoc = (encoding!=null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
            ? new String(filecontents, encoding)
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
            : new String(filecontents);
8632
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   225
        Pattern bodyPat = Pattern.compile("(?is).*<body\\b[^>]*>(.*)</body\\b.*");
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   226
        Matcher m = bodyPat.matcher(rawDoc);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   227
        if (m.matches()) {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   228
            return m.group(1);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   229
        } else {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   230
            String key = rawDoc.matches("(?is).*<body\\b.*")
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   231
                    ? "javadoc.End_body_missing_from_html_file"
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   232
                    : "javadoc.Body_missing_from_html_file";
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   233
            env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), key);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
            return "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     * Return the full unprocessed text of the comment.  Tags
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
     * are included as text.  Used mainly for store and retrieve
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     * operations like internalization.
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
    public String getRawCommentText() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        return documentation();
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
     * Set the full unprocessed text of the comment.  Tags
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
     * are included as text.  Used mainly for store and retrieve
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     * operations like internalization.
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
    public void setRawCommentText(String rawDocumentation) {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   253
        treePath = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        documentation = rawDocumentation;
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        comment = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
    /**
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   259
     * Set the full unprocessed text of the comment and tree path.
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   260
     */
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   261
    void setTreePath(TreePath treePath) {
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   262
        this.treePath = treePath;
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   263
        documentation = getCommentText(treePath);
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   264
        comment = null;
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   265
    }
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   266
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   267
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
     * return a key for sorting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    CollationKey key() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
        if (collationkey == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
            collationkey = generateKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        return collationkey;
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
     * Generate a key for sorting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
     * <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
     * Default is name().
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    CollationKey generateKey() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        String k = name();
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\"");
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        return env.doclocale.collator.getCollationKey(k);
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
     * Returns a string representation of this Doc item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
     */
8632
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents: 5520
diff changeset
   291
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
    public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        return qualifiedName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     * Returns the name of this Doc item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
     * @return  the name
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
    public abstract String name();
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
     * Returns the qualified name of this Doc item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
     * @return  the name
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
    public abstract String qualifiedName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
     * Compares this Object with the specified Object for order.  Returns a
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
     * negative integer, zero, or a positive integer as this Object is less
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
     * than, equal to, or greater than the given Object.
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
     * <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
     * Included so that Doc item are java.lang.Comparable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
     *
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   317
     * @param   obj the {@code Object} to be compared.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
     * @return  a negative integer, zero, or a positive integer as this Object
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
     *          is less than, equal to, or greater than the given Object.
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
     * @exception ClassCastException the specified Object's type prevents it
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
     *            from being compared to this Object.
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
    public int compareTo(Object obj) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
        // System.out.println("COMPARE \"" + this + "\" to \"" + obj + "\" = " + key().compareTo(((DocImpl)obj).key()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
        return key().compareTo(((DocImpl)obj).key());
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
     * Is this Doc item a field?  False until overridden.
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
     * @return true if it represents a field
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
    public boolean isField() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
     * Is this Doc item an enum constant?  False until overridden.
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
     * @return true if it represents an enum constant
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
    public boolean isEnumConstant() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
     * Is this Doc item a constructor?  False until overridden.
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
     * @return true if it represents a constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
    public boolean isConstructor() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
     * Is this Doc item a method (but not a constructor or annotation
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
     * type element)?
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
     * False until overridden.
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
     * @return true if it represents a method
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
    public boolean isMethod() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
     * Is this Doc item an annotation type element?
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
     * False until overridden.
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
     * @return true if it represents an annotation type element
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
    public boolean isAnnotationTypeElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
     * Is this Doc item a interface (but not an annotation type)?
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
     * False until overridden.
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
     * @return true if it represents a interface
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
    public boolean isInterface() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
     * Is this Doc item a exception class?  False until overridden.
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
     * @return true if it represents a exception
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
    public boolean isException() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
     * Is this Doc item a error class?  False until overridden.
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
     * @return true if it represents a error
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
    public boolean isError() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
     * Is this Doc item an enum type?  False until overridden.
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
     * @return true if it represents an enum type
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
    public boolean isEnum() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
     * Is this Doc item an annotation type?  False until overridden.
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
     * @return true if it represents an annotation type
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
    public boolean isAnnotationType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
     * Is this Doc item an ordinary class (i.e. not an interface,
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
     * annotation type, enumeration, exception, or error)?
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
     * False until overridden.
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
     * @return true if it represents an ordinary class
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
    public boolean isOrdinaryClass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
     * Is this Doc item a class
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
     * (and not an interface or annotation type)?
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
     * This includes ordinary classes, enums, errors and exceptions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
     * False until overridden.
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
     * @return true if it represents a class
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
    public boolean isClass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
     * return true if this Doc is include in the active set.
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
    public abstract boolean isIncluded();
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
     * Return the source position of the entity, or null if
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
     * no position is available.
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
    public SourcePosition position() { return null; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
}