test/jdk/javadoc/tool/api/basic/taglets/UnderlineTaglet.java

Print this page


   1 /*
   2  * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
   3  *
   4  * Redistribution and use in source and binary forms, with or
   5  * without modification, are permitted provided that the following
   6  * conditions are met:
   7  *
   8  * -Redistributions of source code must retain the above copyright
   9  *  notice, this list of conditions and the following disclaimer.
  10  *
  11  * -Redistribution in binary form must reproduce the above copyright
  12  *  notice, this list of conditions and the following disclaimer in
  13  *  the documentation and/or other materials provided with the
  14  *  distribution.
  15  *
  16  * Neither the name of Oracle nor the names of
  17  * contributors may be used to endorse or promote products derived
  18  * from this software without specific prior written permission.
  19  *
  20  * This software is provided "AS IS," without a warranty of any
  21  * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
  22  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
  23  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
  24  * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
  25  * DAMAGES OR LIABILITIES  SUFFERED BY LICENSEE AS A RESULT OF OR
  26  * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR
  27  * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
  28  * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
  29  * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  30  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
  31  * THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN
  32  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  33  *
  34  * You acknowledge that Software is not designed, licensed or
  35  * intended for use in the design, construction, operation or
  36  * maintenance of any nuclear facility.
  37  */
  38 
  39 import com.sun.tools.doclets.Taglet;
  40 import com.sun.javadoc.*;
  41 import java.util.Map;
  42 







  43 /**
  44  * A sample Inline Taglet representing {@underline ...}. This tag can
  45  * be used in any kind of {@link com.sun.javadoc.Doc}.
  46  * The text is underlined.  For example,
  47  * "@underline UNDERLINE ME" would be shown as: <u>UNDERLINE ME</u>.
  48  *
  49  * @author Jamie Ho
  50  * @since 1.4
  51  */
  52 
  53 public class UnderlineTaglet implements Taglet {
  54 
  55     private static final String NAME = "underline";
  56 
  57     /**
  58      * Return the name of this custom tag.
  59      */
  60     public String getName() {
  61         return NAME;
  62     }
  63 
  64     /**
  65      * @return true since this tag can be used in a field
  66      *         doc comment
  67      */
  68     public boolean inField() {
  69         return true;
  70     }
  71 
  72     /**
  73      * @return true since this tag can be used in a constructor
  74      *         doc comment
  75      */
  76     public boolean inConstructor() {
  77         return true;
  78     }
  79 
  80     /**
  81      * @return true since this tag can be used in a method
  82      *         doc comment
  83      */
  84     public boolean inMethod() {
  85         return true;
  86     }
  87 
  88     /**
  89      * @return true since this tag can be used in an overview
  90      *         doc comment
  91      */
  92     public boolean inOverview() {
  93         return true;
  94     }
  95 
  96     /**
  97      * @return true since this tag can be used in a package
  98      *         doc comment
  99      */
 100     public boolean inPackage() {
 101         return true;
 102     }
 103 
 104     /**
 105      * @return true since this
 106      */
 107     public boolean inType() {
 108         return true;
 109     }
 110 
 111     /**
 112      * Will return true since this is an inline tag.
 113      * @return true since this is an inline tag.
 114      */
 115 
 116     public boolean isInlineTag() {
 117         return true;
 118     }
 119 
 120     /**
 121      * Register this Taglet.
 122      * @param tagletMap  the map to register this tag to.
 123      */
 124     public static void register(Map tagletMap) {
 125        UnderlineTaglet tag = new UnderlineTaglet();
 126        Taglet t = (Taglet) tagletMap.get(tag.getName());
 127        if (t != null) {
 128            tagletMap.remove(tag.getName());
 129        }
 130        tagletMap.put(tag.getName(), tag);
 131     }
 132 
 133     /**
 134      * Given the <code>Tag</code> representation of this custom
 135      * tag, return its string representation.
 136      * @param tag he <code>Tag</code> representation of this custom tag.
 137      */
 138     public String toString(Tag tag) {
 139         return "<u>" + tag.text() + "</u>";
 140     }
 141 
 142     /**
 143      * This method should not be called since arrays of inline tags do not
 144      * exist.  Method {@link #tostring(Tag)} should be used to convert this
 145      * inline tag to a string.
 146      * @param tags the array of <code>Tag</code>s representing of this custom tag.
 147      */
 148     public String toString(Tag[] tags) {
 149         return null;
 150     }































 151 }
 152 
   1 /*
   2  * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
   3  *
   4  * Redistribution and use in source and binary forms, with or
   5  * without modification, are permitted provided that the following
   6  * conditions are met:
   7  *
   8  * -Redistributions of source code must retain the above copyright
   9  *  notice, this list of conditions and the following disclaimer.
  10  *
  11  * -Redistribution in binary form must reproduce the above copyright
  12  *  notice, this list of conditions and the following disclaimer in
  13  *  the documentation and/or other materials provided with the
  14  *  distribution.
  15  *
  16  * Neither the name of Oracle nor the names of
  17  * contributors may be used to endorse or promote products derived
  18  * from this software without specific prior written permission.
  19  *
  20  * This software is provided "AS IS," without a warranty of any
  21  * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
  22  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
  23  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
  24  * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
  25  * DAMAGES OR LIABILITIES  SUFFERED BY LICENSEE AS A RESULT OF OR
  26  * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR
  27  * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
  28  * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
  29  * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  30  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
  31  * THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN
  32  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  33  *
  34  * You acknowledge that Software is not designed, licensed or
  35  * intended for use in the design, construction, operation or
  36  * maintenance of any nuclear facility.
  37  */
  38 
  39 import java.util.EnumSet;
  40 import java.util.List;
  41 import java.util.Set;
  42 
  43 import com.sun.source.doctree.DocTree;
  44 import com.sun.source.doctree.TextTree;
  45 import com.sun.source.doctree.UnknownBlockTagTree;
  46 import com.sun.source.doctree.UnknownInlineTagTree;
  47 import com.sun.source.util.SimpleDocTreeVisitor;
  48 import jdk.javadoc.doclet.taglet.Taglet;
  49 
  50 /**
  51  * A sample Inline Taglet representing {@underline ...}. This tag can
  52  * be used in any kind of {@link javax.lang.model.Element}.
  53  * The text is underlined.  For example,
  54  * "@underline UNDERLINE ME" would be shown as: <u>UNDERLINE ME</u>.
  55  *
  56  * @author Jamie Ho
  57  * @since 1.4
  58  */
  59 
  60 public class UnderlineTaglet implements Taglet {
  61 
  62     private static final String NAME = "underline";
  63 
  64     /**
  65      * Return the name of this custom tag.
  66      */
  67     public String getName() {
  68         return NAME;
  69     }
  70 
  71     private final EnumSet<Location> allowedSet = EnumSet.allOf(Location.class);






  72 
  73     @Override
  74     public Set<Taglet.Location> getAllowedLocations() {
  75         return allowedSet;



  76     }
  77 
  78     /**































  79      * Will return true since this is an inline tag.
  80      * @return true since this is an inline tag.
  81      */
  82 
  83     public boolean isInlineTag() {
  84         return true;
  85     }
  86 
  87     /**













  88      * Given the <code>Tag</code> representation of this custom
  89      * tag, return its string representation.
  90      * @param tag he <code>Tag</code> representation of this custom tag.
  91      */
  92     public String toString(DocTree tag) {
  93         return "<u>" + getText(tag) + "</u>";
  94     }
  95 
  96     /**
  97      * This method should not be called since arrays of inline tags do not
  98      * exist.  Method {@link #tostring(Tag)} should be used to convert this
  99      * inline tag to a string.
 100      * @param tags the array of <code>Tag</code>s representing of this custom tag.
 101      */
 102     public String toString(List<? extends DocTree> tags) {
 103         return null;
 104     }
 105 
 106     static String getText(DocTree dt) {
 107         return new SimpleDocTreeVisitor<String, Void>() {
 108             @Override
 109             public String visitUnknownBlockTag(UnknownBlockTagTree node, Void p) {
 110                 for (DocTree dt : node.getContent()) {
 111                     return dt.accept(this, null);
 112                 }
 113                 return "";
 114             }
 115 
 116             @Override
 117             public String visitUnknownInlineTag(UnknownInlineTagTree node, Void p) {
 118                 for (DocTree dt : node.getContent()) {
 119                     return dt.accept(this, null);
 120                 }
 121                 return "";
 122             }
 123 
 124             @Override
 125             public String visitText(TextTree node, Void p) {
 126                 return node.getBody();
 127             }
 128 
 129             @Override
 130             protected String defaultAction(DocTree node, Void p) {
 131                 return "";
 132             }
 133 
 134         }.visit(dt, null);
 135     }
 136 }
 137