langtools/test/jdk/javadoc/doclet/testUserTaglet/InfoTaglet.java
author jjg
Thu, 23 Mar 2017 10:58:16 -0700
changeset 44388 4d0903f1f311
permissions -rw-r--r--
8176836: Provide Taglet with context Reviewed-by: ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44388
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
     1
/*
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
     4
 *
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
     8
 *
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    13
 * accompanied this code).
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    14
 *
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    18
 *
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    21
 * questions.
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    22
 */
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    23
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    24
import java.util.EnumSet;
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    25
import java.util.List;
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    26
import java.util.Set;
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    27
import javax.lang.model.element.Element;
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    28
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    29
import jdk.javadoc.doclet.Doclet;
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    30
import jdk.javadoc.doclet.DocletEnvironment;
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    31
import jdk.javadoc.doclet.Taglet;
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    32
import static jdk.javadoc.doclet.Taglet.Location.*;
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    33
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    34
import com.sun.source.doctree.DocTree;
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    35
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    36
/**
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    37
 * A taglet to test access to a taglet's context.
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    38
 */
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    39
public class InfoTaglet implements Taglet {
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    40
    private DocletEnvironment env;
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    41
    private Doclet doclet;
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    42
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    43
    @Override
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    44
    public void init(DocletEnvironment env, Doclet doclet) {
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    45
        this.env = env;
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    46
        this.doclet = doclet;
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    47
    }
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    48
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    49
    @Override
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    50
    public Set<Location> getAllowedLocations() {
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    51
        return EnumSet.of(TYPE);
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    52
    }
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    53
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    54
    @Override
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    55
    public boolean isInlineTag() {
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    56
        return false;
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    57
    }
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    58
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    59
    @Override
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    60
    public String getName() {
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    61
        return "info";
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    62
    }
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    63
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    64
    @Override
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    65
    public String toString(List<? extends DocTree> tags, Element element) {
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    66
        // The content lines below are primarily to help verify the element
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    67
        // and the values passed to init.
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    68
        return "<dt>"
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    69
                +"<span class=\"simpleTagLabel\">Info:</span>\n"
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    70
                + "</dt>"
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    71
                + "<dd>"
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    72
                + "<ul>\n"
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    73
                + "<li>Element: " + element.getKind() + " " + element.getSimpleName() + "\n"
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    74
                + "<li>Element supertypes: " +
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    75
                        env.getTypeUtils().directSupertypes(element.asType()) + "\n"
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    76
                + "<li>Doclet: " + doclet.getClass() + "\n"
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    77
                + "</ul>\n"
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    78
                + "</dd>";
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    79
    }
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    80
}
4d0903f1f311 8176836: Provide Taglet with context
jjg
parents:
diff changeset
    81