001    package org.apache.maven.tools.plugin.javadoc;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import java.util.Map;
023    
024    import org.apache.maven.tools.plugin.extractor.java.JavaMojoAnnotation;
025    
026    import com.sun.tools.doclets.Taglet;
027    
028    /**
029     * The <tt>@parameter</tt> tag is used to define a Mojo parameter and has annotation parameter.
030     * <br/>
031     * The following is a sample declaration:
032     * <pre>
033     * public class MyMojo extends AbstractMojo
034     * {
035     *   &#x2f;&#x2a;&#x2a;
036     *   &#x20;&#x2a; Dummy parameter.
037     *   &#x20;&#x2a;
038     *   &#x20;&#x2a; &#64;parameter &lt;alias="..."&gt; &lt;default-value="..."&gt; &lt;expression="..."&gt;
039     *   &#x20;&#x2a; &lt;implementation="..."&gt; &lt;property="..."&gt;
040     *   &#x20;&#x2a; ...
041     *   &#x20;&#x2a;&#x2f;
042     *   private Object parameterName;
043     * }
044     * </pre>
045     * To use it, calling the <code>Javadoc</code> tool with the following:
046     * <pre>
047     * javadoc ... -taglet 'org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet'
048     * </pre>
049     *
050     * @see <a href="package-summary.html#package_description">package-summary.html</a>
051     *
052     * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
053     * @version $Id: MojoParameterFieldTaglet.java 1133707 2011-06-09 08:28:59Z stephenc $
054     */
055    public class MojoParameterFieldTaglet
056        extends AbstractMojoFieldTaglet
057    {
058        /** The Javadoc annotation */
059        private static final String NAME = JavaMojoAnnotation.PARAMETER;
060    
061        private static final String[] PARAMETERS_NAME = {
062            JavaMojoAnnotation.PARAMETER_ALIAS,
063            JavaMojoAnnotation.PARAMETER_DEFAULT_VALUE,
064            JavaMojoAnnotation.PARAMETER_EXPRESSION,
065            JavaMojoAnnotation.PARAMETER_IMPLEMENTATION,
066            JavaMojoAnnotation.PARAMETER_PROPERTY };
067    
068        /** The Javadoc text which will be added to the generated page. */
069        protected static final String HEADER = "Is defined by";
070    
071        /**
072         * @return By default, return the string defined in {@linkplain #HEADER}.
073         * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getHeader()
074         * @see #HEADER
075         */
076        public String getHeader()
077        {
078            return HEADER;
079        }
080    
081        /**
082         * @return <code>null</code> since <code>@parameter</code> has no value.
083         * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getAllowedValue()
084         */
085        public String getAllowedValue()
086        {
087            return null;
088        }
089    
090        /**
091         * @return <code>MojoParameterFieldTaglet#PARAMETERS_NAME</code> since <code>@parameter</code> has parameters.
092         * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getAllowedParameterNames()
093         */
094        public String[] getAllowedParameterNames()
095        {
096            return PARAMETERS_NAME;
097        }
098    
099        /**
100         * @return By default, return the name of this taglet.
101         * @see com.sun.tools.doclets.Taglet#getName()
102         * @see MojoParameterFieldTaglet#NAME
103         */
104        public String getName()
105        {
106            return NAME;
107        }
108    
109        /**
110         * Register this Taglet.
111         *
112         * @param tagletMap the map to register this tag to.
113         */
114        public static void register( Map<String, Taglet> tagletMap )
115        {
116            MojoParameterFieldTaglet tag = new MojoParameterFieldTaglet();
117            Taglet t = tagletMap.get( tag.getName() );
118            if ( t != null )
119            {
120                tagletMap.remove( tag.getName() );
121            }
122            tagletMap.put( tag.getName(), tag );
123        }
124    }