langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/UserTaglet.java
author jjg
Thu, 23 Mar 2017 10:58:16 -0700
changeset 44388 4d0903f1f311
parent 44189 dd311cfb920b
permissions -rw-r--r--
8176836: Provide Taglet with context Reviewed-by: ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
44180
207e05e0d9ad 8176131: Simplify new Taglet API
jjg
parents: 38911
diff changeset
     2
 * Copyright (c) 2003, 2017, 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: 10
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: 10
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: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    25
package jdk.javadoc.internal.doclets.toolkit.taglets;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
44180
207e05e0d9ad 8176131: Simplify new Taglet API
jjg
parents: 38911
diff changeset
    27
import java.util.Collections;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    28
import java.util.List;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    29
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    30
import javax.lang.model.element.Element;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    32
import com.sun.source.doctree.DocTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    33
import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    34
import jdk.javadoc.internal.doclets.toolkit.Content;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    35
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    36
44189
dd311cfb920b 8176331: Simplify new doclet packages
jjg
parents: 44180
diff changeset
    37
import static jdk.javadoc.doclet.Taglet.Location.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
/**
44189
dd311cfb920b 8176331: Simplify new doclet packages
jjg
parents: 44180
diff changeset
    40
 * A taglet wrapper, allows the public taglet {@link jdk.javadoc.doclet.Taglet}
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    41
 * wrapped into an internal Taglet representation.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    43
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
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: 5520
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: 5520
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
 */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    50
public class UserTaglet implements Taglet {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
44189
dd311cfb920b 8176331: Simplify new doclet packages
jjg
parents: 44180
diff changeset
    52
    final private jdk.javadoc.doclet.Taglet userTaglet;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
44189
dd311cfb920b 8176331: Simplify new doclet packages
jjg
parents: 44180
diff changeset
    54
    public UserTaglet(jdk.javadoc.doclet.Taglet t) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    55
        userTaglet = t;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    public boolean inField() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    62
        return userTaglet.isInlineTag()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    63
                || userTaglet.getAllowedLocations().contains(FIELD);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    public boolean inConstructor() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    70
        return userTaglet.isInlineTag()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    71
                || userTaglet.getAllowedLocations().contains(CONSTRUCTOR);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    public boolean inMethod() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    78
        return userTaglet.isInlineTag()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    79
                || userTaglet.getAllowedLocations().contains(METHOD);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    public boolean inOverview() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    86
        return userTaglet.isInlineTag()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    87
                || userTaglet.getAllowedLocations().contains(OVERVIEW);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     */
38911
48a00b5ee366 8156077: Support javadoc tags in module documentation
bpatel
parents: 35426
diff changeset
    93
    public boolean inModule() {
48a00b5ee366 8156077: Support javadoc tags in module documentation
bpatel
parents: 35426
diff changeset
    94
        return userTaglet.isInlineTag()
48a00b5ee366 8156077: Support javadoc tags in module documentation
bpatel
parents: 35426
diff changeset
    95
                || userTaglet.getAllowedLocations().contains(MODULE);
48a00b5ee366 8156077: Support javadoc tags in module documentation
bpatel
parents: 35426
diff changeset
    96
    }
48a00b5ee366 8156077: Support javadoc tags in module documentation
bpatel
parents: 35426
diff changeset
    97
48a00b5ee366 8156077: Support javadoc tags in module documentation
bpatel
parents: 35426
diff changeset
    98
    /**
48a00b5ee366 8156077: Support javadoc tags in module documentation
bpatel
parents: 35426
diff changeset
    99
     * {@inheritDoc}
48a00b5ee366 8156077: Support javadoc tags in module documentation
bpatel
parents: 35426
diff changeset
   100
     */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    public boolean inPackage() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   102
        return userTaglet.isInlineTag()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   103
                || userTaglet.getAllowedLocations().contains(PACKAGE);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    public boolean inType() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   110
        return userTaglet.isInlineTag()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   111
                || userTaglet.getAllowedLocations().contains(TYPE);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   115
     * Return true if this <code>Taglet</code> is an inline tag.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   116
     *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   117
     * @return true if this <code>Taglet</code> is an inline tag and false otherwise.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    public boolean isInlineTag() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   120
        return userTaglet.isInlineTag();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    public String getName() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   127
        return userTaglet.getName();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   133
    public Content getTagletOutput(Element element, DocTree tag, TagletWriter writer){
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 14260
diff changeset
   134
        Content output = writer.getOutputInstance();
44388
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents: 44189
diff changeset
   135
        output.addContent(new RawHtml(userTaglet.toString(Collections.singletonList(tag), element)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        return output;
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   142
    public Content getTagletOutput(Element holder, TagletWriter writer) {
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 14260
diff changeset
   143
        Content output = writer.getOutputInstance();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   144
        Utils utils = writer.configuration().utils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   145
        List<? extends DocTree> tags = utils.getBlockTags(holder, getName());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   146
        if (!tags.isEmpty()) {
44388
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents: 44189
diff changeset
   147
            String tagString = userTaglet.toString(tags, holder);
19910
b87eac187379 8015882: Javadoc prints NPE when using Taglet
bpatel
parents: 17574
diff changeset
   148
            if (tagString != null) {
b87eac187379 8015882: Javadoc prints NPE when using Taglet
bpatel
parents: 17574
diff changeset
   149
                output.addContent(new RawHtml(tagString));
b87eac187379 8015882: Javadoc prints NPE when using Taglet
bpatel
parents: 17574
diff changeset
   150
            }
b87eac187379 8015882: Javadoc prints NPE when using Taglet
bpatel
parents: 17574
diff changeset
   151
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
        return output;
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
}