langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java
author alanb
Fri, 07 Apr 2017 08:08:26 +0000
changeset 44573 245bb4e6f983
parent 38617 d93a7f64e231
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: jjg Contributed-by: alan.bateman@oracle.com, jan.lahoda@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
     2
 * Copyright (c) 2001, 2016, 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: 1789
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: 1789
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: 1789
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.doclets.internal.toolkit.taglets;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.net.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
    33
import javax.tools.DocumentationTool;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
    34
import javax.tools.JavaFileManager;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
    35
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14049
diff changeset
    36
import com.sun.javadoc.*;
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14049
diff changeset
    37
import com.sun.tools.doclets.internal.toolkit.util.*;
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 21500
diff changeset
    38
import com.sun.tools.javac.util.StringUtils;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14049
diff changeset
    39
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * Manages the<code>Taglet</code>s used by doclets.
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    43
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    44
 *  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: 14258
diff changeset
    45
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    46
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * @since 1.4
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
38617
d93a7f64e231 8157606: deprecate com.sun.javadoc API
jjg
parents: 37757
diff changeset
    52
@Deprecated
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
public class TagletManager {
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    /**
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
    56
     * The default separator for the simple tag option.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     */
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
    58
    public static final char SIMPLE_TAGLET_OPT_SEPARATOR = ':';
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    /**
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
    61
     * The alternate separator for simple tag options.  Use this
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
    62
     * when you want the default separator to be in the name of the
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * custom tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     */
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
    65
    public static final String ALT_SIMPLE_TAGLET_OPT_SEPARATOR = "-";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     * The map of custom tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    70
    private LinkedHashMap<String,Taglet> customTags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     * The array of custom tags that can appear in packages.
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    private Taglet[] packageTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     * The array of custom tags that can appear in classes or interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    private Taglet[] typeTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     * The array of custom tags that can appear in fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    private Taglet[] fieldTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     * The array of custom tags that can appear in constructors.
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    private Taglet[] constructorTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     * The array of custom tags that can appear in methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    private Taglet[] methodTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     * The array of custom tags that can appear in the overview.
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    private Taglet[] overviewTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     * The array of custom tags that can appear in comments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    private Taglet[] inlineTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     * The array of custom tags that can appear in the serialized form.
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    private Taglet[] serializedFormTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     * The message retriever that will be used to print error messages.
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    private MessageRetriever message;
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     * Keep track of standard tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   120
    private Set<String> standardTags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     * Keep track of standard tags in lowercase to compare for better
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     * error messages when a tag like @docRoot is mistakenly spelled
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     * lowercase @docroot.
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   127
    private Set<String> standardTagsLowercase;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     * Keep track of overriden standard tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   132
    private Set<String> overridenStandardTags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     * Keep track of the tags that may conflict
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * with standard tags in the future (any custom tag without
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     * a period in its name).
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   139
    private Set<String> potentiallyConflictingTags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     * The set of unseen custom tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   144
    private Set<String> unseenCustomTags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     * True if we do not want to use @since tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    private boolean nosince;
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     * True if we want to use @version tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    private boolean showversion;
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     * True if we want to use @author tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    private boolean showauthor;
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    /**
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14545
diff changeset
   162
     * True if we want to use JavaFX-related tags (@propertyGetter,
17572
1081a023532f 8012295: Cleanup JavaFX features in standard doclet
jjg
parents: 17565
diff changeset
   163
     * @propertySetter, @propertyDescription, @defaultValue, @treatAsPrivate).
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14545
diff changeset
   164
     */
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14545
diff changeset
   165
    private boolean javafx;
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14545
diff changeset
   166
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   167
    private boolean exportInternalAPI;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   168
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14545
diff changeset
   169
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     * Construct a new <code>TagletManager</code>.
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     * @param nosince true if we do not want to use @since tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     * @param showversion true if we want to use @version tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * @param showauthor true if we want to use @author tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * @param message the message retriever to print warnings.
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    public TagletManager(boolean nosince, boolean showversion,
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14545
diff changeset
   177
                         boolean showauthor, boolean javafx,
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   178
                         boolean exportInternalAPI,
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14545
diff changeset
   179
                         MessageRetriever message) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   180
        overridenStandardTags = new HashSet<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   181
        potentiallyConflictingTags = new HashSet<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   182
        standardTags = new HashSet<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   183
        standardTagsLowercase = new HashSet<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   184
        unseenCustomTags = new HashSet<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   185
        customTags = new LinkedHashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        this.nosince = nosince;
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        this.showversion = showversion;
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        this.showauthor = showauthor;
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14545
diff changeset
   189
        this.javafx = javafx;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   190
        this.exportInternalAPI = exportInternalAPI;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        this.message = message;
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   192
        initStandardTaglets();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        initStandardTagsLowercase();
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
     * Add a new <code>CustomTag</code>.  This is used to add a Taglet from within
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     * a Doclet.  No message is printed to indicate that the Taglet is properly
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     * registered because these Taglets are typically added for every execution of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     * Doclet.  We don't want to see this type of error message every time.
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     * @param customTag the new <code>CustomTag</code> to add.
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    public void addCustomTag(Taglet customTag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        if (customTag != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
            String name = customTag.getName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
            if (customTags.containsKey(name)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
                customTags.remove(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            customTags.put(name, customTag);
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
            checkTagName(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 18659
diff changeset
   214
    public Set<String> getCustomTagNames() {
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 18659
diff changeset
   215
        return customTags.keySet();
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 18659
diff changeset
   216
    }
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 18659
diff changeset
   217
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     * Add a new <code>Taglet</code>.  Print a message to indicate whether or not
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     * the Taglet was registered properly.
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     * @param classname  the name of the class representing the custom tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
     * @param tagletPath  the path to the class representing the custom tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
     */
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
   224
    public void addCustomTag(String classname, JavaFileManager fileManager, String tagletPath) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        try {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   226
            Class<?> customTagClass = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
            // construct class loader
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
            String cpString = null;   // make sure env.class.path defaults to dot
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
   230
            ClassLoader tagClassLoader;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
   231
            if (fileManager != null && fileManager.hasLocation(DocumentationTool.Location.TAGLET_PATH)) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
   232
                tagClassLoader = fileManager.getClassLoader(DocumentationTool.Location.TAGLET_PATH);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
   233
            } else {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
   234
                // do prepends to get correct ordering
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
   235
                cpString = appendPath(System.getProperty("env.class.path"), cpString);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
   236
                cpString = appendPath(System.getProperty("java.class.path"), cpString);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
   237
                cpString = appendPath(tagletPath, cpString);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
   238
                tagClassLoader = new URLClassLoader(pathToURLs(cpString));
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
   239
            }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
   240
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   241
            if (exportInternalAPI) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   242
                exportInternalAPI(tagClassLoader);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   243
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   244
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14368
diff changeset
   245
            customTagClass = tagClassLoader.loadClass(classname);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   246
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
            Method meth = customTagClass.getMethod("register",
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   248
                                                   Map.class);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
            Object[] list = customTags.values().toArray();
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            Taglet lastTag = (list != null && list.length > 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
                ? (Taglet) list[list.length-1] : null;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   252
            meth.invoke(null, customTags);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
            list = customTags.values().toArray();
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
            Object newLastTag = (list != null&& list.length > 0)
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   255
                ? list[list.length-1] : null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
            if (lastTag != newLastTag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
                //New taglets must always be added to the end of the LinkedHashMap.
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
                //If the current and previous last taglet are not equal, that
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
                //means a new Taglet has been added.
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                message.notice("doclet.Notice_taglet_registered", classname);
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                if (newLastTag != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
                    checkTaglet(newLastTag);
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        } catch (Exception exc) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   266
            exc.printStackTrace();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
            message.error("doclet.Error_taglet_not_registered", exc.getClass().getName(), classname);
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   272
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   273
     * Export javadoc internal API to the unnamed module for a classloader.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   274
     * This is to support continued use of existing non-standard doclets that
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   275
     * use the internal toolkit API and related classes.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   276
     * @param cl the classloader
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   277
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   278
    private void exportInternalAPI(ClassLoader cl) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   279
        String[] packages = {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   280
            "com.sun.tools.doclets",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   281
            "com.sun.tools.doclets.standard",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   282
            "com.sun.tools.doclets.internal.toolkit",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   283
            "com.sun.tools.doclets.internal.toolkit.taglets",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   284
            "com.sun.tools.doclets.internal.toolkit.builders",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   285
            "com.sun.tools.doclets.internal.toolkit.util",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   286
            "com.sun.tools.doclets.internal.toolkit.util.links",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   287
            "com.sun.tools.doclets.formats.html",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   288
            "com.sun.tools.doclets.formats.html.markup"
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   289
        };
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   290
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   291
        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   292
            Method getModuleMethod = Class.class.getDeclaredMethod("getModule");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   293
            Object thisModule = getModuleMethod.invoke(getClass());
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   294
44573
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 38617
diff changeset
   295
            Class<?> moduleClass = Class.forName("java.lang.Module");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   296
            Method addExportsMethod = moduleClass.getDeclaredMethod("addExports", String.class, moduleClass);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   297
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   298
            Method getUnnamedModuleMethod = ClassLoader.class.getDeclaredMethod("getUnnamedModule");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   299
            Object target = getUnnamedModuleMethod.invoke(cl);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   300
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   301
            for (String pack : packages) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   302
                addExportsMethod.invoke(thisModule, pack, target);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   303
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   304
        } catch (Exception e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   305
            // do nothing
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   306
            e.printStackTrace();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   307
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   308
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33920
diff changeset
   309
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
    private String appendPath(String path1, String path2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        if (path1 == null || path1.length() == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
            return path2 == null ? "." : path2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        } else if (path2 == null || path2.length() == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
            return path1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
            return path1  + File.pathSeparator + path2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
     * Utility method for converting a search path string to an array
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
     * of directory and JAR file URLs.
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
     * @param path the search path string
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
     * @return the resulting array of directory and JAR file URLs
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
     */
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14263
diff changeset
   327
    private URL[] pathToURLs(String path) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   328
        Set<URL> urls = new LinkedHashSet<>();
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14263
diff changeset
   329
        for (String s: path.split(File.pathSeparator)) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14263
diff changeset
   330
            if (s.isEmpty()) continue;
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14263
diff changeset
   331
            try {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14263
diff changeset
   332
                urls.add(new File(s).getAbsoluteFile().toURI().toURL());
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14263
diff changeset
   333
            } catch (MalformedURLException e) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14263
diff changeset
   334
                message.error("doclet.MalformedURL", s);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        }
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14263
diff changeset
   337
        return urls.toArray(new URL[urls.size()]);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
     * Add a new <code>SimpleTaglet</code>.  If this tag already exists
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
     * and the header passed as an argument is null, move tag to the back of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
     * list. If this tag already exists and the header passed as an argument is
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
     * not null, overwrite previous tag with new one.  Otherwise, add new
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
     * SimpleTaglet to list.
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
     * @param tagName the name of this tag
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
     * @param header the header to output.
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
     * @param locations the possible locations that this tag
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
     * can appear in.
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
    public void addNewSimpleCustomTag(String tagName, String header, String locations) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
        if (tagName == null || locations == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        }
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   356
        Taglet tag = customTags.get(tagName);
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 21500
diff changeset
   357
        locations = StringUtils.toLowerCase(locations);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
        if (tag == null || header != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
            customTags.remove(tagName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
            customTags.put(tagName, new SimpleTaglet(tagName, header, locations));
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
            if (locations != null && locations.indexOf('x') == -1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
                checkTagName(tagName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            //Move to back
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
            customTags.remove(tagName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
            customTags.put(tagName, tag);
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
     * Given a tag name, add it to the set of tags it belongs to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
    private void checkTagName(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
        if (standardTags.contains(name)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
            overridenStandardTags.add(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
            if (name.indexOf('.') == -1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
                potentiallyConflictingTags.add(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
            unseenCustomTags.add(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
     * Check the taglet to see if it is a legacy taglet.  Also
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
     * check its name for errors.
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
    private void checkTaglet(Object taglet) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
        if (taglet instanceof Taglet) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
            checkTagName(((Taglet) taglet).getName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
        } else if (taglet instanceof com.sun.tools.doclets.Taglet) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
            com.sun.tools.doclets.Taglet legacyTaglet = (com.sun.tools.doclets.Taglet) taglet;
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
            customTags.remove(legacyTaglet.getName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
            customTags.put(legacyTaglet.getName(), new LegacyTaglet(legacyTaglet));
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
            checkTagName(legacyTaglet.getName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
            throw new IllegalArgumentException("Given object is not a taglet.");
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
     * Given a name of a seen custom tag, remove it from the set of unseen
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
     * custom tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
     * @param name the name of the seen custom tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
    public void seenCustomTag(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        unseenCustomTags.remove(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
     * Given an array of <code>Tag</code>s, check for spelling mistakes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
     * @param doc the Doc object that holds the tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
     * @param tags the list of <code>Tag</code>s to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
     * @param areInlineTags true if the array of tags are inline and false otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
    public void checkTags(Doc doc, Tag[] tags, boolean areInlineTags) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
        if (tags == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        Taglet taglet;
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   422
        for (Tag tag : tags) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   423
            String name = tag.name();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
            if (name.length() > 0 && name.charAt(0) == '@') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
                name = name.substring(1, name.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
            if (! (standardTags.contains(name) || customTags.containsKey(name))) {
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 21500
diff changeset
   428
                if (standardTagsLowercase.contains(StringUtils.toLowerCase(name))) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   429
                    message.warning(tag.position(), "doclet.UnknownTagLowercase", tag.name());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
                    continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
                } else {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   432
                    message.warning(tag.position(), "doclet.UnknownTag", tag.name());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
                    continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
            //Check if this tag is being used in the wrong location.
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   437
            if ((taglet = customTags.get(name)) != null) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
                if (areInlineTags && ! taglet.isInlineTag()) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   439
                    printTagMisuseWarn(taglet, tag, "inline");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
                if ((doc instanceof RootDoc) && ! taglet.inOverview()) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   442
                    printTagMisuseWarn(taglet, tag, "overview");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
                } else if ((doc instanceof PackageDoc) && ! taglet.inPackage()) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   444
                    printTagMisuseWarn(taglet, tag, "package");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
                } else if ((doc instanceof ClassDoc) && ! taglet.inType()) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   446
                    printTagMisuseWarn(taglet, tag, "class");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
                } else if ((doc instanceof ConstructorDoc) && ! taglet.inConstructor()) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   448
                    printTagMisuseWarn(taglet, tag, "constructor");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
                } else if ((doc instanceof FieldDoc) && ! taglet.inField()) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   450
                    printTagMisuseWarn(taglet, tag, "field");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
                } else if ((doc instanceof MethodDoc) && ! taglet.inMethod()) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   452
                    printTagMisuseWarn(taglet, tag, "method");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
     * Given the taglet, the tag and the type of documentation that the tag
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
     * was found in, print a tag misuse warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
     * @param taglet the taglet representing the misused tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
     * @param tag the misused tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
     * @param holderType the type of documentation that the misused tag was found in.
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
    private void printTagMisuseWarn(Taglet taglet, Tag tag, String holderType) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   466
        Set<String> locationsSet = new LinkedHashSet<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
        if (taglet.inOverview()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
            locationsSet.add("overview");
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
        if (taglet.inPackage()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
            locationsSet.add("package");
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
        if (taglet.inType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
            locationsSet.add("class/interface");
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
        if (taglet.inConstructor())  {
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
            locationsSet.add("constructor");
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
        if (taglet.inField()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
            locationsSet.add("field");
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
        if (taglet.inMethod()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
            locationsSet.add("method");
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
        if (taglet.isInlineTag()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
            locationsSet.add("inline text");
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
        }
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   488
        String[] locations = locationsSet.toArray(new String[]{});
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
        if (locations == null || locations.length == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
            //This known tag is excluded.
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        }
14263
473b1eaede64 8000310: Clean up use of StringBuffer in langtools
jjg
parents: 14260
diff changeset
   493
        StringBuilder combined_locations = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
        for (int i = 0; i < locations.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
            if (i > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
                combined_locations.append(", ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
            combined_locations.append(locations[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
        message.warning(tag.position(), "doclet.tag_misuse",
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
            "@" + taglet.getName(), holderType, combined_locations.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
     * Return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
     * appear in packages.
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
     * @return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
     * appear in packages.
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
     */
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   510
    public Taglet[] getPackageCustomTaglets() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
        if (packageTags == null) {
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   512
            initCustomTagletArrays();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
        return packageTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
     * Return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
     * appear in classes or interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
     * @return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
     * appear in classes or interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
     */
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   523
    public Taglet[] getTypeCustomTaglets() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
        if (typeTags == null) {
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   525
            initCustomTagletArrays();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
        return typeTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
     * Return the array of inline <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
     * appear in comments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
     * @return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
     * appear in comments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
     */
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   536
    public Taglet[] getInlineCustomTaglets() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
        if (inlineTags == null) {
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   538
            initCustomTagletArrays();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
        return inlineTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
     * Return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
     * appear in fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
     * @return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
     * appear in field.
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
     */
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   549
    public Taglet[] getFieldCustomTaglets() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
        if (fieldTags == null) {
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   551
            initCustomTagletArrays();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
        return fieldTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
     * Return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
     * appear in the serialized form.
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
     * @return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
     * appear in the serialized form.
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
     */
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   562
    public Taglet[] getSerializedFormTaglets() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
        if (serializedFormTags == null) {
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   564
            initCustomTagletArrays();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
        return serializedFormTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
     * @return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
     * appear in the given Doc.
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
     */
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   573
    public Taglet[] getCustomTaglets(Doc doc) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
        if (doc instanceof ConstructorDoc) {
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   575
            return getConstructorCustomTaglets();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
        } else if (doc instanceof MethodDoc) {
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   577
            return getMethodCustomTaglets();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
        } else if (doc instanceof FieldDoc) {
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   579
            return getFieldCustomTaglets();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
        } else if (doc instanceof ClassDoc) {
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   581
            return getTypeCustomTaglets();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
        } else if (doc instanceof PackageDoc) {
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   583
            return getPackageCustomTaglets();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
        } else if (doc instanceof RootDoc) {
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   585
            return getOverviewCustomTaglets();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
     * Return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
     * appear in constructors.
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
     * @return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
     * appear in constructors.
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
     */
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   596
    public Taglet[] getConstructorCustomTaglets() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
        if (constructorTags == null) {
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   598
            initCustomTagletArrays();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
        return constructorTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
     * Return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
     * appear in methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
     * @return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
     * appear in methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
     */
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   609
    public Taglet[] getMethodCustomTaglets() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
        if (methodTags == null) {
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   611
            initCustomTagletArrays();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
        return methodTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
     * Return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
     * appear in an overview.
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
     * @return the array of <code>Taglet</code>s that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
     * appear in overview.
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
     */
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   622
    public Taglet[] getOverviewCustomTaglets() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
        if (overviewTags == null) {
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   624
            initCustomTagletArrays();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
        return overviewTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
     * Initialize the custom tag arrays.
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
     */
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   632
    private void initCustomTagletArrays() {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   633
        Iterator<Taglet> it = customTags.values().iterator();
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   634
        ArrayList<Taglet> pTags = new ArrayList<>(customTags.size());
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   635
        ArrayList<Taglet> tTags = new ArrayList<>(customTags.size());
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   636
        ArrayList<Taglet> fTags = new ArrayList<>(customTags.size());
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   637
        ArrayList<Taglet> cTags = new ArrayList<>(customTags.size());
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   638
        ArrayList<Taglet> mTags = new ArrayList<>(customTags.size());
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   639
        ArrayList<Taglet> iTags = new ArrayList<>(customTags.size());
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   640
        ArrayList<Taglet> oTags = new ArrayList<>(customTags.size());
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   641
        ArrayList<Taglet> sTags = new ArrayList<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
        Taglet current;
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
        while (it.hasNext()) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   644
            current = it.next();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
            if (current.inPackage() && !current.isInlineTag()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
                pTags.add(current);
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
            if (current.inType() && !current.isInlineTag()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
                tTags.add(current);
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
            if (current.inField() && !current.isInlineTag()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
                fTags.add(current);
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
            if (current.inConstructor() && !current.isInlineTag()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
                cTags.add(current);
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
            if (current.inMethod() && !current.isInlineTag()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
                mTags.add(current);
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
            if (current.isInlineTag()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
                iTags.add(current);
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
            if (current.inOverview() && !current.isInlineTag()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
                oTags.add(current);
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
        }
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   667
        packageTags = pTags.toArray(new Taglet[] {});
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   668
        typeTags = tTags.toArray(new Taglet[] {});
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   669
        fieldTags = fTags.toArray(new Taglet[] {});
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   670
        constructorTags = cTags.toArray(new Taglet[] {});
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   671
        methodTags = mTags.toArray(new Taglet[] {});
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   672
        overviewTags = oTags.toArray(new Taglet[] {});
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   673
        inlineTags = iTags.toArray(new Taglet[] {});
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
        //Init the serialized form tags
13842
6908f6badce4 7180906: Javadoc tool does not apply parameter -nosince
bpatel
parents: 5520
diff changeset
   676
        sTags.add(customTags.get("serialData"));
6908f6badce4 7180906: Javadoc tool does not apply parameter -nosince
bpatel
parents: 5520
diff changeset
   677
        sTags.add(customTags.get("throws"));
6908f6badce4 7180906: Javadoc tool does not apply parameter -nosince
bpatel
parents: 5520
diff changeset
   678
        if (!nosince)
6908f6badce4 7180906: Javadoc tool does not apply parameter -nosince
bpatel
parents: 5520
diff changeset
   679
            sTags.add(customTags.get("since"));
6908f6badce4 7180906: Javadoc tool does not apply parameter -nosince
bpatel
parents: 5520
diff changeset
   680
        sTags.add(customTags.get("see"));
6908f6badce4 7180906: Javadoc tool does not apply parameter -nosince
bpatel
parents: 5520
diff changeset
   681
        serializedFormTags = sTags.toArray(new Taglet[] {});
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
     * Initialize standard Javadoc tags for ordering purposes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
     */
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   687
    private void initStandardTaglets() {
18659
5fe5650da7f9 8015720: since tag isn't copied while generating JavaFX documentation
janvalenta
parents: 17573
diff changeset
   688
        if (javafx) {
5fe5650da7f9 8015720: since tag isn't copied while generating JavaFX documentation
janvalenta
parents: 17573
diff changeset
   689
            initJavaFXTaglets();
5fe5650da7f9 8015720: since tag isn't copied while generating JavaFX documentation
janvalenta
parents: 17573
diff changeset
   690
        }
5fe5650da7f9 8015720: since tag isn't copied while generating JavaFX documentation
janvalenta
parents: 17573
diff changeset
   691
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
        Taglet temp;
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   693
        addStandardTaglet(new ParamTaglet());
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   694
        addStandardTaglet(new ReturnTaglet());
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   695
        addStandardTaglet(new ThrowsTaglet());
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   696
        addStandardTaglet(new SimpleTaglet("exception", null,
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   697
                SimpleTaglet.METHOD + SimpleTaglet.CONSTRUCTOR));
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   698
        addStandardTaglet(!nosince, new SimpleTaglet("since", message.getText("doclet.Since"),
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   699
               SimpleTaglet.ALL));
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   700
        addStandardTaglet(showversion, new SimpleTaglet("version", message.getText("doclet.Version"),
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   701
                SimpleTaglet.PACKAGE + SimpleTaglet.TYPE + SimpleTaglet.OVERVIEW));
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   702
        addStandardTaglet(showauthor, new SimpleTaglet("author", message.getText("doclet.Author"),
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   703
                SimpleTaglet.PACKAGE + SimpleTaglet.TYPE + SimpleTaglet.OVERVIEW));
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   704
        addStandardTaglet(new SimpleTaglet("serialData", message.getText("doclet.SerialData"),
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   705
            SimpleTaglet.EXCLUDED));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
        customTags.put((temp = new SimpleTaglet("factory", message.getText("doclet.Factory"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
            SimpleTaglet.METHOD)).getName(), temp);
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   708
        addStandardTaglet(new SeeTaglet());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
        //Standard inline tags
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   710
        addStandardTaglet(new DocRootTaglet());
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   711
        addStandardTaglet(new InheritDocTaglet());
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   712
        addStandardTaglet(new ValueTaglet());
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   713
        addStandardTaglet(new LiteralTaglet());
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   714
        addStandardTaglet(new CodeTaglet());
33920
bd731341c405 8141492: Implement search feature in javadoc
bpatel
parents: 25874
diff changeset
   715
        addStandardTaglet(new IndexTaglet());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   717
        // Keep track of the names of standard tags for error
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   718
        // checking purposes. The following are not handled above.
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   719
        // See, for example, com.sun.tools.javadoc.Comment
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
        standardTags.add("deprecated");
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
        standardTags.add("link");
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
        standardTags.add("linkplain");
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
        standardTags.add("serial");
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
        standardTags.add("serialField");
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
        standardTags.add("Text");
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14545
diff changeset
   726
    }
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14545
diff changeset
   727
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14545
diff changeset
   728
    /**
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14545
diff changeset
   729
     * Initialize JavaFX-related tags.
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14545
diff changeset
   730
     */
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   731
    private void initJavaFXTaglets() {
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   732
        addStandardTaglet(new PropertyGetterTaglet());
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   733
        addStandardTaglet(new PropertySetterTaglet());
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   734
        addStandardTaglet(new SimpleTaglet("propertyDescription",
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   735
                message.getText("doclet.PropertyDescription"),
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   736
                SimpleTaglet.FIELD + SimpleTaglet.METHOD));
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   737
        addStandardTaglet(new SimpleTaglet("defaultValue", message.getText("doclet.DefaultValue"),
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   738
            SimpleTaglet.FIELD + SimpleTaglet.METHOD));
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   739
        addStandardTaglet(new SimpleTaglet("treatAsPrivate", null,
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   740
                SimpleTaglet.FIELD + SimpleTaglet.METHOD + SimpleTaglet.TYPE));
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   741
    }
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14545
diff changeset
   742
17573
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   743
    void addStandardTaglet(Taglet taglet) {
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   744
        String name = taglet.getName();
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   745
        customTags.put(name, taglet);
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   746
        standardTags.add(name);
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   747
    }
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   748
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   749
    void addStandardTaglet(boolean enable, Taglet taglet) {
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   750
        String name = taglet.getName();
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   751
        if (enable)
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   752
            customTags.put(name, taglet);
0e20dec17c87 8012311: Cleanup names and duplicatre code in TagletManager
jjg
parents: 17572
diff changeset
   753
        standardTags.add(name);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
     * Initialize lowercase version of standard Javadoc tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
    private void initStandardTagsLowercase() {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   760
        for (String standardTag : standardTags) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   761
            standardTagsLowercase.add(StringUtils.toLowerCase(standardTag));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
    public boolean isKnownCustomTag(String tagName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
        return customTags.containsKey(tagName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
     * Print a list of {@link Taglet}s that might conflict with
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
     * standard tags in the future and a list of standard tags
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
     * that have been overriden.
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
    public void printReport() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
        printReportHelper("doclet.Notice_taglet_conflict_warn", potentiallyConflictingTags);
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
        printReportHelper("doclet.Notice_taglet_overriden", overridenStandardTags);
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
        printReportHelper("doclet.Notice_taglet_unseen", unseenCustomTags);
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   780
    private void printReportHelper(String noticeKey, Set<String> names) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
        if (names.size() > 0) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   782
            String[] namesArray = names.toArray(new String[] {});
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
            String result = " ";
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
            for (int i = 0; i < namesArray.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
                result += "@" + namesArray[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
                if (i + 1 < namesArray.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
                    result += ", ";
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
            message.notice(noticeKey, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
     * Given the name of a tag, return the corresponding taglet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
     * Return null if the tag is unknown.
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
     * @param name the name of the taglet to retrieve.
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
     * @return return the corresponding taglet. Return null if the tag is
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
     *         unknown.
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
    public Taglet getTaglet(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
        if (name.indexOf("@") == 0) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   804
            return customTags.get(name.substring(1));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
        } else {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   806
            return customTags.get(name);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
}