langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ParamTaglet.java
author ksrini
Sun, 15 Jun 2014 08:41:57 -0700
changeset 25454 376a52c9540c
parent 22163 3651128c74eb
permissions -rw-r--r--
8039028: [javadoc] refactor the usage of Util.java Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
     2
 * Copyright (c) 2001, 2014, 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
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 5520
diff changeset
    28
import java.util.*;
8d2148961366 8000663: clean up langtools imports
jjg
parents: 5520
diff changeset
    29
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.javadoc.*;
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
    31
import com.sun.tools.doclets.internal.toolkit.Content;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.doclets.internal.toolkit.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * A taglet that represents the @param tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    37
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    38
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    39
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    40
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * @since 1.4
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
public class ParamTaglet extends BaseTaglet implements InheritableTaglet {
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
     * Construct a ParamTaglet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    public ParamTaglet() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
        name = "param";
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     * Given an array of <code>Parameter</code>s, return
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     * a name/rank number map.  If the array is null, then
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     * null is returned.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     * @param params The array of parmeters (from type or executable member) to
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     *               check.
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     * @return a name-rank number map.
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    62
    private static Map<String,String> getRankMap(Object[] params){
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
        if (params == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        }
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    66
        HashMap<String,String> result = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        for (int i = 0; i < params.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
            String name = params[i] instanceof Parameter ?
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
                ((Parameter) params[i]).name() :
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
                ((TypeVariable) params[i]).typeName();
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
            result.put(name, String.valueOf(i));
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    public void inherit(DocFinder.Input input, DocFinder.Output output) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        if (input.tagId == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            input.isTypeVariableParamTag = ((ParamTag) input.tag).isTypeParameter();
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
            Object[] parameters = input.isTypeVariableParamTag ?
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
                (Object[]) ((MethodDoc) input.tag.holder()).typeParameters() :
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
                (Object[]) ((MethodDoc) input.tag.holder()).parameters();
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
            String target = ((ParamTag) input.tag).parameterName();
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
            int i;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
            for (i = 0; i < parameters.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
                String name = parameters[i] instanceof Parameter ?
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
                    ((Parameter) parameters[i]).name() :
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
                    ((TypeVariable) parameters[i]).typeName();
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
                if (name.equals(target)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
                    input.tagId = String.valueOf(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
            if (i == parameters.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
                //Someone used {@inheritDoc} on an invalid @param tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
                //We don't know where to inherit from.
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
                //XXX: in the future when Configuration is available here,
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
                //print a warning for this mistake.
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        ParamTag[] tags = input.isTypeVariableParamTag ?
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   105
            ((MethodDoc)input.element).typeParamTags() : ((MethodDoc)input.element).paramTags();
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   106
        Map<String, String> rankMap = getRankMap(input.isTypeVariableParamTag ?
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   107
            (Object[]) ((MethodDoc)input.element).typeParameters() :
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   108
            (Object[]) ((MethodDoc)input.element).parameters());
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   109
        for (ParamTag tag : tags) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   110
            if (rankMap.containsKey(tag.parameterName()) &&
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   111
                rankMap.get(tag.parameterName()).equals((input.tagId))) {
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   112
                output.holder = input.element;
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   113
                output.holderTag = tag;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
                output.inlineTags = input.isFirstSentence ?
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   115
                                    tag.firstSentenceTags() : tag.inlineTags();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    public boolean inField() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    public boolean inMethod() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    public boolean inOverview() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    public boolean inPackage() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    public boolean inType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    public boolean isInlineTag() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     * Given an array of <code>ParamTag</code>s,return its string representation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
     * @param holder the member that holds the param tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     * @param writer the TagletWriter that will write this tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     * @return the TagletOutput representation of these <code>ParamTag</code>s.
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     */
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   169
    public Content getTagletOutput(Doc holder, TagletWriter writer) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        if (holder instanceof ExecutableMemberDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
            ExecutableMemberDoc member = (ExecutableMemberDoc) holder;
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   172
            Content output = getTagletOutput(false, member, writer,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
                member.typeParameters(), member.typeParamTags());
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   174
            output.addContent(getTagletOutput(true, member, writer,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
                member.parameters(), member.paramTags()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
            return output;
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
            ClassDoc classDoc = (ClassDoc) holder;
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
            return getTagletOutput(false, classDoc, writer,
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
                classDoc.typeParameters(), classDoc.typeParamTags());
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     * Given an array of <code>ParamTag</code>s,return its string representation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     * Try to inherit the param tags that are missing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
     *
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   188
     * @param holder            the doc that holds the param tags.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * @param writer            the TagletWriter that will write this tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * @param formalParameters  The array of parmeters (from type or executable
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     *                          member) to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     * @return the TagletOutput representation of these <code>ParamTag</code>s.
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
     */
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   195
    private Content getTagletOutput(boolean isNonTypeParams, Doc holder,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
            TagletWriter writer, Object[] formalParameters, ParamTag[] paramTags) {
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   197
        Content result = writer.getOutputInstance();
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   198
        Set<String> alreadyDocumented = new HashSet<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        if (paramTags.length > 0) {
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   200
            result.addContent(
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
                processParamTags(isNonTypeParams, paramTags,
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
                getRankMap(formalParameters), writer, alreadyDocumented)
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
            );
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        if (alreadyDocumented.size() != formalParameters.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
            //Some parameters are missing corresponding @param tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
            //Try to inherit them.
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   208
            result.addContent(getInheritedTagletOutput (isNonTypeParams, holder,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
                writer, formalParameters, alreadyDocumented));
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     * Loop through each indivitual parameter.  It it does not have a
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     * corresponding param tag, try to inherit it.
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     */
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   218
    private Content getInheritedTagletOutput(boolean isNonTypeParams, Doc holder,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
            TagletWriter writer, Object[] formalParameters,
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   220
            Set<String> alreadyDocumented) {
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   221
        Content result = writer.getOutputInstance();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        if ((! alreadyDocumented.contains(null)) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
                holder instanceof MethodDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
            for (int i = 0; i < formalParameters.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
                if (alreadyDocumented.contains(String.valueOf(i))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
                    continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
                //This parameter does not have any @param documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
                //Try to inherit it.
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
                DocFinder.Output inheritedDoc =
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   231
                    DocFinder.search(writer.configuration(), new DocFinder.Input((MethodDoc) holder, this,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
                        String.valueOf(i), ! isNonTypeParams));
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
                if (inheritedDoc.inlineTags != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
                        inheritedDoc.inlineTags.length > 0) {
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   235
                    result.addContent(
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
                        processParamTag(isNonTypeParams, writer,
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
                            (ParamTag) inheritedDoc.holderTag,
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
                            isNonTypeParams ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
                                ((Parameter) formalParameters[i]).name():
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
                                ((TypeVariable) formalParameters[i]).typeName(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
                            alreadyDocumented.size() == 0));
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
                alreadyDocumented.add(String.valueOf(i));
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     * Given an array of <code>Tag</code>s representing this custom
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     * tag, return its string representation.  Print a warning for param
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     * tags that do not map to parameters.  Print a warning for param
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     * tags that are duplicated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
     * @param paramTags the array of <code>ParamTag</code>s to convert.
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
     * @param writer the TagletWriter that will write this tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     * @param alreadyDocumented the set of exceptions that have already
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     *        been documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     * @param rankMap a {@link java.util.Map} which holds ordering
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     *                    information about the parameters.
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   261
     * @param rankMap a {@link java.util.Map} which holds a mapping
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     *                of a rank of a parameter to its name.  This is
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     *                used to ensure that the right name is used
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     *                when parameter documentation is inherited.
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   265
     * @return the Content representation of this <code>Tag</code>.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     */
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   267
    private Content processParamTags(boolean isNonTypeParams,
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   268
            ParamTag[] paramTags, Map<String, String> rankMap, TagletWriter writer,
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   269
            Set<String> alreadyDocumented) {
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   270
        Content result = writer.getOutputInstance();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
        if (paramTags.length > 0) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   272
            for (ParamTag pt : paramTags) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
                String paramName = isNonTypeParams ?
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   274
                                   pt.parameterName() : "<" + pt.parameterName() + ">";
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   275
                if (!rankMap.containsKey(pt.parameterName())) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
                    writer.getMsgRetriever().warning(pt.position(),
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   277
                                                     isNonTypeParams ?
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   278
                                                     "doclet.Parameters_warn" :
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   279
                                                     "doclet.Type_Parameters_warn",
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   280
                                                     paramName);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
                }
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   282
                String rank = rankMap.get(pt.parameterName());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
                if (rank != null && alreadyDocumented.contains(rank)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                    writer.getMsgRetriever().warning(pt.position(),
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   285
                                                     isNonTypeParams ?
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   286
                                                     "doclet.Parameters_dup_warn" :
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   287
                                                     "doclet.Type_Parameters_dup_warn",
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   288
                                                     paramName);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
                }
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   290
                result.addContent(processParamTag(isNonTypeParams, writer, pt,
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17574
diff changeset
   291
                                                  pt.parameterName(), alreadyDocumented.size() == 0));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
                alreadyDocumented.add(rank);
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
    /**
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   298
     * Convert the individual ParamTag into Content.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
     * @param isNonTypeParams true if this is just a regular param tag.  False
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
     *                        if this is a type param tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
     * @param writer          the taglet writer for output writing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
     * @param paramTag        the tag whose inline tags will be printed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
     * @param name            the name of the parameter.  We can't rely on
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
     *                        the name in the param tag because we might be
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
     *                        inheriting documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
     * @param isFirstParam    true if this is the first param tag being printed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
     */
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   310
    private Content processParamTag(boolean isNonTypeParams,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
            TagletWriter writer, ParamTag paramTag, String name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
            boolean isFirstParam) {
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   313
        Content result = writer.getOutputInstance();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        String header = writer.configuration().getText(
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
            isNonTypeParams ? "doclet.Parameters" : "doclet.TypeParameters");
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        if (isFirstParam) {
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   317
            result.addContent(writer.getParamHeader(header));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
        }
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 17547
diff changeset
   319
        result.addContent(writer.paramTagOutput(paramTag,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
            name));
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
}