001package 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
022import java.util.Map;
023
024import org.apache.maven.tools.plugin.extractor.javadoc.JavadocMojoAnnotation;
025
026import com.sun.tools.doclets.Taglet;
027
028// CHECKSTYLE_OFF: LineLength
029/**
030 * The <tt>@parameter</tt> tag is used to define a Mojo parameter and has annotation parameter.
031 * <br/>
032 * The following is a sample declaration:
033 * <pre>
034 * public class MyMojo extends AbstractMojo
035 * {
036 *   &#x2f;&#x2a;&#x2a;
037 *   &#x20;&#x2a; Dummy parameter.
038 *   &#x20;&#x2a;
039 *   &#x20;&#x2a; &#64;parameter &lt;name="..."&gt; &lt;alias="..."&gt; &lt;default-value="..."&gt; &lt;expression="..."&gt;
040 *   &#x20;&#x2a; &lt;implementation="..."&gt; &lt;property="..."&gt;
041 *   &#x20;&#x2a; ...
042 *   &#x20;&#x2a;&#x2f;
043 *   private Object parameterName;
044 * }
045 * </pre>
046 * To use it, calling the <code>Javadoc</code> tool with the following:
047 * <pre>
048 * javadoc ... -taglet 'org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet'
049 * </pre>
050 *
051 * @see <a href="package-summary.html#package_description">package-summary.html</a>
052 *
053 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
054 * @version $Id: MojoParameterFieldTaglet.html 1030109 2018-05-20 14:45:18Z hboutemy $
055 */
056//CHECKSTYLE_ON: LineLength
057public class MojoParameterFieldTaglet
058    extends AbstractMojoFieldTaglet
059{
060    /** The Javadoc annotation */
061    private static final String NAME = JavadocMojoAnnotation.PARAMETER;
062
063    private static final String[] PARAMETERS_NAME = {
064        JavadocMojoAnnotation.PARAMETER_NAME,
065        JavadocMojoAnnotation.PARAMETER_ALIAS,
066        JavadocMojoAnnotation.PARAMETER_DEFAULT_VALUE,
067        JavadocMojoAnnotation.PARAMETER_EXPRESSION,
068        JavadocMojoAnnotation.PARAMETER_IMPLEMENTATION,
069        JavadocMojoAnnotation.PARAMETER_PROPERTY };
070
071    /** The Javadoc text which will be added to the generated page. */
072    protected static final String HEADER = "Is defined by";
073
074    /**
075     * @return By default, return the string defined in {@linkplain #HEADER}.
076     * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getHeader()
077     * @see #HEADER
078     */
079    public String getHeader()
080    {
081        return HEADER;
082    }
083
084    /**
085     * @return <code>null</code> since <code>@parameter</code> has no value.
086     * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getAllowedValue()
087     */
088    public String getAllowedValue()
089    {
090        return null;
091    }
092
093    /**
094     * @return <code>MojoParameterFieldTaglet#PARAMETERS_NAME</code> since <code>@parameter</code> has parameters.
095     * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getAllowedParameterNames()
096     */
097    public String[] getAllowedParameterNames()
098    {
099        return PARAMETERS_NAME;
100    }
101
102    /**
103     * @return By default, return the name of this taglet.
104     * @see com.sun.tools.doclets.Taglet#getName()
105     * @see MojoParameterFieldTaglet#NAME
106     */
107    public String getName()
108    {
109        return NAME;
110    }
111
112    /**
113     * Register this Taglet.
114     *
115     * @param tagletMap the map to register this tag to.
116     */
117    public static void register( Map<String, Taglet> tagletMap )
118    {
119        MojoParameterFieldTaglet tag = new MojoParameterFieldTaglet();
120        Taglet t = tagletMap.get( tag.getName() );
121        if ( t != null )
122        {
123            tagletMap.remove( tag.getName() );
124        }
125        tagletMap.put( tag.getName(), tag );
126    }
127}