langtools/test/jdk/javadoc/doclet/testLegacyTaglet/ToDoTaglet.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: 35426
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
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    24
import java.util.EnumSet;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    25
import java.util.List;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
import java.util.Map;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    27
import java.util.Set;
44388
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents: 44189
diff changeset
    28
import javax.lang.model.element.Element;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    29
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    30
import com.sun.source.doctree.DocTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    31
import com.sun.source.doctree.TextTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    32
import com.sun.source.doctree.UnknownBlockTagTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    33
import com.sun.source.doctree.UnknownInlineTagTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    34
import com.sun.source.util.SimpleDocTreeVisitor;
44189
dd311cfb920b 8176331: Simplify new doclet packages
jjg
parents: 44180
diff changeset
    35
import jdk.javadoc.doclet.Taglet;
dd311cfb920b 8176331: Simplify new doclet packages
jjg
parents: 44180
diff changeset
    36
import jdk.javadoc.doclet.Taglet.Location;
dd311cfb920b 8176331: Simplify new doclet packages
jjg
parents: 44180
diff changeset
    37
import static jdk.javadoc.doclet.Taglet.Location.*;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    38
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    39
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * A sample Taglet representing @todo. This tag can be used in any kind of
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    42
 * {@link javax.lang.model.Element}.  It is not an inline tag. The text is displayed
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * in yellow to remind the developer to perform a task.  For
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * example, "@todo Fix this!" would be shown as:
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * <DL>
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * <DT>
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * <B>To Do:</B>
25295
bb0339807d3c 8048168: update 2 javadoc tests to add summary attribute for table tag
sogoel
parents: 5520
diff changeset
    48
 * <DD><table summary="Summary" cellpadding=2 cellspacing=0><tr><td bgcolor="yellow">Fix this!
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * </td></tr></table></DD>
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * </DL>
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 * @since 1.4
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
public class ToDoTaglet implements Taglet {
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    private static final String NAME = "todo";
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    private static final String HEADER = "To Do:";
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     * Return the name of this custom tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    public String getName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        return NAME;
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    68
    private final EnumSet<Location> allowedSet = EnumSet.allOf(Location.class);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    70
    @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    71
    public Set<Taglet.Location> getAllowedLocations() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    72
        return allowedSet;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * Will return false since <code>@todo</code>
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     * is not an inline tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     * @return false since <code>@todo</code>
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     * is not an inline tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    public boolean isInlineTag() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     * Given an array of <code>Tag</code>s representing this custom
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     * tag, return its string representation.
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    89
     * @param tags  the array of <code>DocTree</code>s representing this custom tag.
44388
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents: 44189
diff changeset
    90
     * @param element the declaration to which the enclosing comment belongs
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    92
    @Override
44388
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents: 44189
diff changeset
    93
    public String toString(List<? extends DocTree> tags, Element element) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    94
        if (tags.isEmpty()) {
44180
207e05e0d9ad 8176131: Simplify new Taglet API
jjg
parents: 35426
diff changeset
    95
            return "";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        String result = "\n<DT><B>" + HEADER + "</B><DD>";
25295
bb0339807d3c 8048168: update 2 javadoc tests to add summary attribute for table tag
sogoel
parents: 5520
diff changeset
    98
        result += "<table summary=\"Summary\" cellpadding=2 cellspacing=0><tr><td bgcolor=\"yellow\">";
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
    99
        for (int i = 0; i < tags.size(); i++) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
            if (i > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
                result += ", ";
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   103
            result += getText(tags.get(i));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        return result + "</td></tr></table></DD>\n";
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   107
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   108
    static String getText(DocTree dt) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   109
        return new SimpleDocTreeVisitor<String, Void>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   110
            @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   111
            public String visitUnknownBlockTag(UnknownBlockTagTree node, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   112
                for (DocTree dt : node.getContent()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   113
                    return dt.accept(this, null);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   114
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   115
                return "";
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   116
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   117
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   118
            @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   119
            public String visitUnknownInlineTag(UnknownInlineTagTree node, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   120
                for (DocTree dt : node.getContent()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   121
                    return dt.accept(this, null);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   122
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   123
                return "";
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   124
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   125
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   126
            @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   127
            public String visitText(TextTree node, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   128
                return node.getBody();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   129
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   130
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   131
            @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   132
            protected String defaultAction(DocTree node, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   133
                return "";
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   134
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   135
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   136
        }.visit(dt, null);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25295
diff changeset
   137
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
}