langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/UserTaglet.java
author bpatel
Thu, 09 Jun 2016 23:24:05 -0700
changeset 38911 48a00b5ee366
parent 35426 374342e56a56
child 44180 207e05e0d9ad
permissions -rw-r--r--
8156077: Support javadoc tags in module documentation Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
     2
 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 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
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    27
import java.util.List;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    28
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    29
import javax.lang.model.element.Element;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    31
import com.sun.source.doctree.DocTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    32
import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    33
import jdk.javadoc.internal.doclets.toolkit.Content;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    34
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    35
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    36
import static jdk.javadoc.doclet.taglet.Taglet.Location.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
/**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    39
 * A taglet wrapper, allows the public taglet {@link jdk.javadoc.doclet.taglet.Taglet}
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    40
 * wrapped into an internal Taglet representation.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    42
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    43
 *  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
    44
 *  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
    45
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    49
public class UserTaglet implements Taglet {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    51
    final private jdk.javadoc.doclet.taglet.Taglet userTaglet;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    53
    public UserTaglet(jdk.javadoc.doclet.taglet.Taglet t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    54
        userTaglet = t;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    public boolean inField() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    61
        return userTaglet.isInlineTag()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    62
                || userTaglet.getAllowedLocations().contains(FIELD);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    public boolean inConstructor() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    69
        return userTaglet.isInlineTag()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    70
                || userTaglet.getAllowedLocations().contains(CONSTRUCTOR);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    public boolean inMethod() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    77
        return userTaglet.isInlineTag()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    78
                || userTaglet.getAllowedLocations().contains(METHOD);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    public boolean inOverview() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    85
        return userTaglet.isInlineTag()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    86
                || userTaglet.getAllowedLocations().contains(OVERVIEW);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     */
38911
48a00b5ee366 8156077: Support javadoc tags in module documentation
bpatel
parents: 35426
diff changeset
    92
    public boolean inModule() {
48a00b5ee366 8156077: Support javadoc tags in module documentation
bpatel
parents: 35426
diff changeset
    93
        return userTaglet.isInlineTag()
48a00b5ee366 8156077: Support javadoc tags in module documentation
bpatel
parents: 35426
diff changeset
    94
                || userTaglet.getAllowedLocations().contains(MODULE);
48a00b5ee366 8156077: Support javadoc tags in module documentation
bpatel
parents: 35426
diff changeset
    95
    }
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
     * {@inheritDoc}
48a00b5ee366 8156077: Support javadoc tags in module documentation
bpatel
parents: 35426
diff changeset
    99
     */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    public boolean inPackage() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   101
        return userTaglet.isInlineTag()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   102
                || userTaglet.getAllowedLocations().contains(PACKAGE);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    public boolean inType() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   109
        return userTaglet.isInlineTag()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   110
                || userTaglet.getAllowedLocations().contains(TYPE);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   114
     * Return true if this <code>Taglet</code> is an inline tag.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   115
     *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   116
     * @return true if this <code>Taglet</code> is an inline tag and false otherwise.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    public boolean isInlineTag() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   119
        return userTaglet.isInlineTag();
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
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    public String getName() {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   126
        return userTaglet.getName();
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
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   132
    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
   133
        Content output = writer.getOutputInstance();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   134
        output.addContent(new RawHtml(userTaglet.toString(tag)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        return output;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   141
    public Content getTagletOutput(Element holder, TagletWriter writer) {
17574
044c7e1e4d53 8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents: 14260
diff changeset
   142
        Content output = writer.getOutputInstance();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   143
        Utils utils = writer.configuration().utils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   144
        List<? extends DocTree> tags = utils.getBlockTags(holder, getName());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   145
        if (!tags.isEmpty()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   146
            String tagString = userTaglet.toString(tags);
19910
b87eac187379 8015882: Javadoc prints NPE when using Taglet
bpatel
parents: 17574
diff changeset
   147
            if (tagString != null) {
b87eac187379 8015882: Javadoc prints NPE when using Taglet
bpatel
parents: 17574
diff changeset
   148
                output.addContent(new RawHtml(tagString));
b87eac187379 8015882: Javadoc prints NPE when using Taglet
bpatel
parents: 17574
diff changeset
   149
            }
b87eac187379 8015882: Javadoc prints NPE when using Taglet
bpatel
parents: 17574
diff changeset
   150
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        return output;
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
}