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