001/*license*\
002   Codelet: Copyright (C) 2014, Jeff Epstein (aliteralmind __DASH__ github __AT__ yahoo __DOT__ com)
003
004   This software is dual-licensed under the:
005   - Lesser General Public License (LGPL) version 3.0 or, at your option, any later version;
006   - Apache Software License (ASL) version 2.0.
007
008   Either license may be applied at your discretion. More information may be found at
009   - http://en.wikipedia.org/wiki/Multi-licensing.
010
011   The text of both licenses is available in the root directory of this project, under the names "LICENSE_lgpl-3.0.txt" and "LICENSE_asl-2.0.txt". The latest copies may be downloaded at:
012   - LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt
013   - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt
014\*license*/
015package  com.github.aliteralmind.codelet.taglet;
016   import  com.github.aliteralmind.codelet.CodeletBootstrap;
017   import  com.github.aliteralmind.codelet.CodeletType;
018   import  com.sun.javadoc.Tag;
019   import  com.sun.tools.doclets.Taglet;
020   import  java.util.Map;
021/**
022   <p>Inline JavaDoc taglet for displaying the source code of a class (usually example code). This tag can be used in any kind of {@link com.sun.javadoc.Doc}.</p>
023
024   <p>The only custom code in this class is the {@link #NAME} field and {@link #toString(Tag) toString} function.</p>
025
026   <p>Jamie Ho's <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/taglet/overview.html#inlineexample">UnderlineTaglet</a> was the template used to create this file.</p>
027
028 * @since  0.1.0
029 * @author  Copyright (C) 2014, Jeff Epstein ({@code aliteralmind __DASH__ github __AT__ yahoo __DOT__ com}), dual-licensed under the LGPL (version 3.0 or later) or the ASL (version 2.0). See source code for details. <a href="http://codelet.aliteralmind.com">{@code http://codelet.aliteralmind.com}</a>, <a href="https://github.com/aliteralmind/codelet">{@code https://github.com/aliteralmind/codelet}</a>.
030 **/
031public class CodeletTaglet implements Taglet {
032   private static final CodeletBootstrap BOOTSTRAP = CodeletBootstrap.INSTANCE;
033   /*
034      To avoid configuration from being loaded repeatedly.
035      See: http://stackoverflow.com/questions/23914909/how-to-prevent-configuration-file-from-repeatedly-reloading-holding-it-statical
036   private static ClassLoader clsLdr = null;
037    */
038   /**
039      <p>The name of this taglet, which appears immediately after the <code>&#123;&#64;</code>--Equal to
040      <br/> &nbsp; &nbsp; <code>{@link com.github.aliteralmind.codelet.CodeletType CodeletType}.{@link com.github.aliteralmind.codelet.CodeletType#SOURCE_CODE SOURCE_CODE}.{@link com.github.aliteralmind.codelet.CodeletType#getName() getName}()</code></p>
041    */
042   public static final String NAME = CodeletType.SOURCE_CODE.getName();
043    /**
044     * Return the name of this custom tag.
045
046     @return  #NAME
047     */
048    public String getName() {
049        return NAME;
050    }
051
052    /**
053     * @return true since this tag can be used in a field
054     *         doc comment
055     */
056    public boolean inField() {
057        return true;
058    }
059
060    /**
061     * @return true since this tag can be used in a constructor
062     *         doc comment
063     */
064    public boolean inConstructor() {
065        return true;
066    }
067
068    /**
069     * @return true since this tag can be used in a method
070     *         doc comment
071     */
072    public boolean inMethod() {
073        return true;
074    }
075
076    /**
077     * @return true since this tag can be used in an overview
078     *         doc comment
079     */
080    public boolean inOverview() {
081        return true;
082    }
083
084    /**
085     * @return true since this tag can be used in a package
086     *         doc comment
087     */
088    public boolean inPackage() {
089        return true;
090    }
091
092    /**
093     * @return true since this
094     */
095    public boolean inType() {
096        return false;
097    }
098
099    /**
100     * Will return true since this is an inline tag.
101     * @return true since this is an inline tag.
102     */
103
104    public boolean isInlineTag() {
105        return true;
106    }
107   /**
108      <p>Register this Taglet.</p>
109
110    * <p>Equal to
111      <br/> &nbsp; &nbsp; <code>{@link ComSunJavaDocUtil}.{@link ComSunJavaDocUtil#registerNewTagletInstance(Taglet, Map) registerNewTagletInstance}(new {@link #CodeletTaglet() CodeletTaglet}(), taglet_map)</code></p>
112    */
113   @SuppressWarnings({"unchecked", "rawtypes"})
114   public static void register(Map taglet_map) {
115      ComSunJavaDocUtil.registerNewTagletInstance(new CodeletTaglet(), taglet_map);
116   }
117
118    /**
119      <p>Given the taglet input of a source-code file (as a fully-qualified class name), this returns the source code for that class, its lines potentially filtered and altered.</p>
120
121        @param tag The <code>Tag</code> representation of this custom tag.
122    * @return  <code>{@link com.github.aliteralmind.codelet.taglet.CodletComSunJavadocTagProcessor CodletComSunJavadocTagProcessor}.{@link com.github.aliteralmind.codelet.taglet.CodletComSunJavadocTagProcessor#get(Tag) get}(tag)</code>
123     */
124    public String toString(Tag tag) {
125         /*
126       if(clsLdr == null)  {
127            To avoid configuration from being loaded repeatedly.
128            See: http://stackoverflow.com/questions/23914909/how-to-prevent-configuration-file-from-repeatedly-reloading-holding-it-statical
129          clsLdr = this.getClass().getClassLoader();
130       }
131          */
132       return  CodletComSunJavadocTagProcessor.get(tag);
133    }
134
135    /**
136     * This method should not be called since arrays of inline tags do not
137     * exist.  Method {@link #toString(Tag)} should be used to convert this
138     * inline tag to a string.
139     * @param tags the array of <code>Tag</code>s representing of this custom tag.
140     */
141    public String toString(Tag[] tags) {
142        return null;
143    }
144}