User: vharcq  
  Date: 02/04/23 11:18:24

  Modified:    core/src/xdoclet XDocletTagSupport.java
  Log:
  We have to give the "for_type" (class, method,...) information up to the end of 
getTagValue chain because this is at the end that a CURRENT tag value is checked.  
This should solve the problem of mixing forAllCLASSTag and forAllMETHODTag and the 
opposite.
  Again this patch passes samples and uni tests but users test is more than welcome.
  
  Revision  Changes    Path
  1.43      +166 -200  xdoclet/core/src/xdoclet/XDocletTagSupport.java
  
  Index: XDocletTagSupport.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/XDocletTagSupport.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -w -r1.42 -r1.43
  --- XDocletTagSupport.java    21 Apr 2002 22:18:52 -0000      1.42
  +++ XDocletTagSupport.java    23 Apr 2002 18:18:24 -0000      1.43
  @@ -11,7 +11,6 @@
   import java.util.List;
   import java.util.Iterator;
   import java.util.Map;
  -import java.util.Arrays;
   
   import xjavadoc.XClass;
   import xjavadoc.XDoc;
  @@ -39,7 +38,7 @@
    *
    * @author    Dmitri Colebatch ([EMAIL PROTECTED])
    * @created   October 12, 2001
  - * @version   $Revision: 1.42 $
  + * @version   $Revision: 1.43 $
    */
   public abstract class XDocletTagSupport extends TemplateTagHandler
   {
  @@ -73,20 +72,12 @@
                return getDocletContext().getActiveSubTask().getCurrentMethodTag();
        }
   
  -     public static XTag getCurrentClassTag()
  -     {
  -             return getDocletContext().getActiveSubTask().getCurrentClassTag();
  -     }
  -
        /**
  -      * This method is used for backward compatibility but use method or class Tag
  -      * specific getter is encouraged.
  -      *
  -      * @return
  +      * @return   The current tag.
         */
  -     public static XTag getCurrentTag()
  +     public static XTag getCurrentClassTag()
        {
  -             return getDocletContext().getActiveSubTask().getCurrentTag();
  +             return getDocletContext().getActiveSubTask().getCurrentClassTag();
        }
   
        /**
  @@ -195,7 +186,7 @@
        }
   
        /**
  -      * Sets the CurrentTag attribute of the XDocletTagSupport class
  +      * Sets the CurrentMethodTag attribute of the XDocletTagSupport class
         *
         * @param currentTag  The new CurrentTag value
         */
  @@ -204,6 +195,11 @@
                getDocletContext().getActiveSubTask().setCurrentMethodTag( currentTag 
);
        }
   
  +     /**
  +      * Sets the CurrentClassTag attribute of the XDocletTagSupport class
  +      *
  +      * @param currentTag  The new CurrentTag value
  +      */
        public static void setCurrentClassTag( XTag currentTag )
        {
                getDocletContext().getActiveSubTask().setCurrentClassTag( currentTag );
  @@ -415,55 +411,6 @@
                boolean superclasses = TypeConversionUtil.stringToBoolean( 
attributes.getProperty( "superclasses" ), true );
                boolean is_mandatory = TypeConversionUtil.stringToBoolean( 
attributes.getProperty( "mandatory" ), false );
   
  -             String tagValue = null;
  -
  -             if( for_type == FOR_METHOD && getCurrentMethodTag() != null && 
getCurrentMethodTag().name().equals( tag_name ) && Arrays.asList( 
getCurrentMethodTag().attributeValueNames() ).contains( param_name ) )
  -             {
  -                     //COMMENTED OUT (ASLAK). BREAKS DEFAULTVALUE. tagValue = 
getCurrentMethodTag().attributeValue( param_name );
  -                     XTag tag = getCurrentMethodTag();
  -
  -                     tagValue = getTagValue(
  -                             getCurrentMethod().doc(),
  -                             tag,
  -                             param_name,
  -                             valid_values,
  -                             default_value,
  -                             is_mandatory
  -                              );
  -             }
  -             else if( for_type == FOR_METHOD && getCurrentMethodTag() != null && 
getCurrentMethodTag().name().equals( tag_name ) && ( param_name == null || param_num 
== null ) )
  -             {
  -                     // somebody is just interested in tag contens.
  -                     // return whole
  -                     //COMMENTED OUT (ASLAK). BREAKS DEFAULTVALUE. return 
getCurrentMethodTag().value();
  -                     XTag tag = getCurrentMethodTag();
  -
  -                     tagValue = getTagValue(
  -                             getCurrentMethod().doc(),
  -                             tag,
  -                             param_name,
  -                             valid_values,
  -                             default_value,
  -                             is_mandatory
  -                              );
  -
  -             }
  -             else if( for_type == FOR_CLASS && getCurrentClassTag() != null )
  -             {
  -                     //COMMENTED OUT (ASLAK). BREAKS DEFAULTVALUE. tagValue = 
getCurrentClassTag().attributeValue( param_name );
  -                     XTag tag = getCurrentClassTag();
  -
  -                     tagValue = getTagValue(
  -                             getCurrentClass().doc(),
  -                             tag,
  -                             param_name,
  -                             valid_values,
  -                             default_value,
  -                             is_mandatory
  -                              );
  -             }
  -             else
  -             {
                        /*
                         * Handles multiple tags/parameters. Multiple tags/parameter 
are specified
                         * as alternatives, and are meant to be used as a "backward 
compatibility"
  @@ -488,6 +435,7 @@
                        }
   
                        // Loop until we get a non-null tag/parameter or there aren't 
any more alternatives
  +             String tagValue = null;
   
                        while( tagTokenizer.hasMoreTokens() && tagValue == null )
                        {
  @@ -498,7 +446,9 @@
                                {
                                        current_param = 
paramTokenizer.nextToken().trim();
                                }
  -
  +//           String current_tag = tag_name;
  +//           String current_param = param_name;
  +//           String
                                tagValue = getTagValue(
                                        for_type,
                                        current_tag,
  @@ -519,6 +469,8 @@
                                                current_param_num = 
paramNumTokenizer.nextToken().trim();
                                        }
   
  +//                   String current_param_num = param_num;
  +
                                        if( current_param_num != null )
                                        {
                                                XProgramElement prg_elem = getPrgElem( 
for_type );
  @@ -541,9 +493,10 @@
                                {
                                        tagValue = tagValue.substring( 1, 
tagValue.length() - 1 );
                                }
  +
                        }
  -             }
  -             tagValue = delimit( tagValue, attributes );
  +
  +             //tagValue = delimit( tagValue, attributes );
                return tagValue;
        }
   
  @@ -589,6 +542,7 @@
                XDoc doc = prg_elem.doc();
   
                return getTagValue(
  +                     for_type,
                        doc,
                        tag_name,
                        param_name,
  @@ -599,35 +553,15 @@
                         );
        }
   
  -     protected static String getTagValue(
  -             XDoc doc,
  -             String tag_name,
  -             String param_name,
  -             String valid_values,
  -             String default_value,
  -             boolean superclasses,
  -             boolean is_mandatory
  -              ) throws XDocletException
  -     {
  -             XTag tag = doc.tag( tag_name, superclasses );
  -
  -             return getTagValue(
  -                     doc,
  -                     tag,
  -                     param_name,
  -                     valid_values,
  -                     default_value,
  -                     is_mandatory
  -                      );
  -     }
  -
        /**
  +      * @param doc                   Describe what the parameter does
  +      * @param tag_name              Describe what the parameter does
         * @param param_name            Describe what the parameter does
         * @param valid_values          Describe what the parameter does
         * @param default_value         Describe what the parameter does
  +      * @param superclasses          Describe what the parameter does
         * @param is_mandatory          Describe what the parameter does
  -      * @param tag
  -      * @param tagOwnerDoc
  +      * @param for_type
         * @return                      The TagValue value
         * @exception XDocletException  Describe the exception
         * @todo                        (Aslak) maybe this method ought to be moved to
  @@ -642,15 +576,33 @@
         * @todo-javadoc                Write javadocs for exception
         */
        protected static String getTagValue(
  -     // passed to method only for the sake of proper error reporting
  -             XDoc tagOwnerDoc,
  -             XTag tag,
  +             int for_type,
  +             XDoc doc,
  +             String tag_name,
                String param_name,
                String valid_values,
                String default_value,
  +             boolean superclasses,
                boolean is_mandatory
                 ) throws XDocletException
        {
  +             XTag tag = null;
  +
  +             // first try to get current tag
  +             if( for_type == FOR_METHOD || for_type == FOR_CONSTRUCTOR )
  +                     tag = getCurrentMethodTag();
  +             else if( for_type == FOR_CLASS )
  +                     tag = getCurrentClassTag();
  +
  +             if( tag != null && !tag.name().equals( tag_name ) )
  +                     tag = null;
  +
  +             if( tag == null )
  +             {
  +                     // if there is no current tag, look in the doc
  +                     tag = doc.tag( tag_name, superclasses );
  +             }
  +
                String value = null;
   
                // check if we have a tag at all
  @@ -672,7 +624,8 @@
                        // nothing found in javadocs
                        if( is_mandatory )
                        {
  -                             mandatoryParamNotFound( tagOwnerDoc, param_name, 
tag.name() );
  +                             // throws XDocletException
  +                             mandatoryParamNotFound( doc, param_name, tag_name );
                        }
                        if( default_value != null )
                        {
  @@ -698,7 +651,7 @@
                                                return value;
                                        }
                                }
  -                             invalidParamValueFound( tagOwnerDoc, param_name, 
tag.name(), value, valid_values );
  +                             invalidParamValueFound( doc, param_name, tag_name, 
value, valid_values );
                        }
                }
                return value;
  @@ -733,13 +686,16 @@
                String tag_name = attributes.getProperty( "tagName" );
                String param_name = attributes.getProperty( "paramName" );
   
  -             if( for_type == FOR_METHOD && getCurrentMethodTag() != null && 
getCurrentMethodTag().name().equals( tag_name ) )
  -             {
  -                     attribute_value = getCurrentMethodTag().attributeValue( 
param_name );
  -             }
  -             if( for_type == FOR_CLASS && getCurrentClassTag() != null && 
getCurrentClassTag().name().equals( tag_name ) )
  +             XTag currentTag = null;
  +
  +             if( for_type == FOR_METHOD || for_type == FOR_CONSTRUCTOR )
  +                     currentTag = getCurrentMethodTag();
  +             else if( for_type == FOR_CLASS )
  +                     currentTag = getCurrentClassTag();
  +
  +             if( currentTag != null && currentTag.name().equals( tag_name ) )
                {
  -                     attribute_value = getCurrentClassTag().attributeValue( 
param_name );
  +                     attribute_value = currentTag.attributeValue( param_name );
                }
                else
                {
  @@ -751,6 +707,56 @@
        }
   
        /**
  +      * Throws an XDocletException exception to stop the build process. The
  +      * exception has an informative message to help user find out the cause of the
  +      * error (not specifying a mandatory parameter for a tag).
  +      *
  +      * @param param_name            Description of Parameter
  +      * @param tag_name              Description of Parameter
  +      * @param doc                   Describe what the parameter does
  +      * @exception XDocletException  Description of Exception
  +      * @todo-javadoc                Write javadocs for method parameter
  +      */
  +     protected static void mandatoryParamNotFound( XDoc doc, String param_name, 
String tag_name ) throws XDocletException
  +     {
  +             XProgramElement programElement = doc.getOwner();
  +
  +             if( programElement instanceof XMethod )
  +             {
  +                     XMethod method = ( XMethod ) programElement;
  +
  +                     throw new XDocletException( Translator.getString( 
"mandatory_tag_param_missing_method",
  +                             new String[]{param_name, tag_name, method.name(), 
method.containingClass().qualifiedName()} ) );
  +             }
  +             else if( programElement instanceof XClass )
  +             {
  +                     XClass clazz = ( XClass ) programElement;
  +
  +                     throw new XDocletException( Translator.getString( 
"mandatory_tag_param_missing_class",
  +                             new String[]{param_name, tag_name, 
clazz.qualifiedName()} ) );
  +             }
  +             else if( programElement instanceof XConstructor )
  +             {
  +                     XConstructor constructor = ( XConstructor ) programElement;
  +
  +                     throw new XDocletException( Translator.getString( 
"mandatory_tag_param_missing_constructor",
  +                             new String[]{param_name, tag_name, 
constructor.containingClass().qualifiedName()} ) );
  +             }
  +             else if( programElement instanceof XField )
  +             {
  +                     XField field = ( XField ) programElement;
  +
  +                     throw new XDocletException( Translator.getString( 
"mandatory_tag_param_missing_field",
  +                             new String[]{param_name, tag_name, field.name(), 
field.containingClass().qualifiedName()} ) );
  +             }
  +             else
  +             {
  +                     throw new XDocletException( Translator.getString( 
"bad_prgelemdoc_type",
  +                             new String[]{programElement.toString()} ) );
  +             }
  +     }
  +
  +     /**
         * A utility method used by ifHasClassTag/ifDoesntHaveClassTag and
         * ifHasMethodTag/ifDoesntHaveMethodTag, return true if at least one tag exists
         * with the specified name.
  @@ -780,7 +786,6 @@
                // Optional Parameter
                String delim = attributes.getProperty( "delimiter" );
                String tokenNumberStr = attributes.getProperty( "tokenNumber" );
  -
                int tokenNumber = 0;
   
                if( tokenNumberStr != null )
  @@ -866,56 +871,6 @@
        /**
         * Throws an XDocletException exception to stop the build process. The
         * exception has an informative message to help user find out the cause of the
  -      * error (not specifying a mandatory parameter for a tag).
  -      *
  -      * @param param_name            Description of Parameter
  -      * @param tag_name              Description of Parameter
  -      * @param doc                   Describe what the parameter does
  -      * @exception XDocletException  Description of Exception
  -      * @todo-javadoc                Write javadocs for method parameter
  -      */
  -     private static void mandatoryParamNotFound( XDoc doc, String param_name, 
String tag_name ) throws XDocletException
  -     {
  -             XProgramElement programElement = doc.getOwner();
  -
  -             if( programElement instanceof XMethod )
  -             {
  -                     XMethod method = ( XMethod ) programElement;
  -
  -                     throw new XDocletException( Translator.getString( 
"mandatory_tag_param_missing_method",
  -                             new String[]{param_name, tag_name, method.name(), 
method.containingClass().qualifiedName()} ) );
  -             }
  -             else if( programElement instanceof XClass )
  -             {
  -                     XClass clazz = ( XClass ) programElement;
  -
  -                     throw new XDocletException( Translator.getString( 
"mandatory_tag_param_missing_class",
  -                             new String[]{param_name, tag_name, 
clazz.qualifiedName()} ) );
  -             }
  -             else if( programElement instanceof XConstructor )
  -             {
  -                     XConstructor constructor = ( XConstructor ) programElement;
  -
  -                     throw new XDocletException( Translator.getString( 
"mandatory_tag_param_missing_constructor",
  -                             new String[]{param_name, tag_name, 
constructor.containingClass().qualifiedName()} ) );
  -             }
  -             else if( programElement instanceof XField )
  -             {
  -                     XField field = ( XField ) programElement;
  -
  -                     throw new XDocletException( Translator.getString( 
"mandatory_tag_param_missing_field",
  -                             new String[]{param_name, tag_name, field.name(), 
field.containingClass().qualifiedName()} ) );
  -             }
  -             else
  -             {
  -                     throw new XDocletException( Translator.getString( 
"bad_prgelemdoc_type",
  -                             new String[]{programElement.toString()} ) );
  -             }
  -     }
  -
  -     /**
  -      * Throws an XDocletException exception to stop the build process. The
  -      * exception has an informative message to help user find out the cause of the
         * error (specifying an incorrect value for a parameter of a tag).
         *
         * @param param_name            Description of Parameter
  @@ -979,6 +934,17 @@
        protected String modifiers( int for_type ) throws XDocletException
        {
                return getPrgElem( for_type ).modifiers();
  +     }
  +
  +     /**
  +      * @param template_tag_name
  +      * @param param_name
  +      * @exception XDocletException
  +      */
  +     protected void mandatoryTemplateTagParamNotFound( String template_tag_name, 
String param_name ) throws XDocletException
  +     {
  +             throw new XDocletException( Translator.getString( 
"mandatory_tag_param_missing_template",
  +                     new String[]{param_name, template_tag_name} ) );
        }
   
   }
  
  
  

_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to