ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build AntDocNestedTypeSubTask.java AntDocRoleSubTask.java AntDocTypeSubTask.java AntTypeSubTask.java AntTypeTagHandler.java AntlibDescriptorTask.java type.j
Date Wed, 12 Jun 2002 06:51:05 GMT
adammurdoch    2002/06/11 23:51:05

  Modified:    buildtools/src/java/org/apache/myrmidon/build
                        AntDocRoleSubTask.java AntDocTypeSubTask.java
                        AntTypeSubTask.java AntTypeTagHandler.java
                        AntlibDescriptorTask.java type.j
  Added:       buildtools/src/java/org/apache/myrmidon/build
                        AntDocNestedTypeSubTask.java
  Log:
  Generate xml docs for classes used as nested elements:
  
  * Added 'collectNestedClasses' tag, which recursively
    locates all nested element classes for the current class,
    and remembers the result.
  
  * Added sub task to generate docs for nested element classes.
  
  Revision  Changes    Path
  1.2       +2 -7      jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntDocRoleSubTask.java
  
  Index: AntDocRoleSubTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntDocRoleSubTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AntDocRoleSubTask.java	11 Jun 2002 11:47:04 -0000	1.1
  +++ AntDocRoleSubTask.java	12 Jun 2002 06:51:04 -0000	1.2
  @@ -7,9 +7,8 @@
    */
   package org.apache.myrmidon.build;
   
  -import xdoclet.TemplateSubTask;
  -import xdoclet.XDocletException;
   import java.net.URL;
  +import xdoclet.XDocletException;
   import xjavadoc.XClass;
   
   /**
  @@ -26,10 +25,6 @@
           setDestinationFile( "{0}.xml" );
           final URL resource = getClass().getResource( "/org/apache/myrmidon/build/role.j"
);
           setTemplateURL( resource );
  -
  -        final TemplateSubTask.ExtentTypes extent = new TemplateSubTask.ExtentTypes();
  -        extent.setValue( "hierarchy" );
  -        setExtent( extent );
       }
   
       public String getSubTaskName()
  
  
  
  1.2       +13 -6     jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntDocTypeSubTask.java
  
  Index: AntDocTypeSubTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntDocTypeSubTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AntDocTypeSubTask.java	11 Jun 2002 11:47:04 -0000	1.1
  +++ AntDocTypeSubTask.java	12 Jun 2002 06:51:04 -0000	1.2
  @@ -8,7 +8,8 @@
   package org.apache.myrmidon.build;
   
   import java.net.URL;
  -import xdoclet.TemplateSubTask;
  +import java.util.Map;
  +import java.util.HashMap;
   import xdoclet.XDocletException;
   import xjavadoc.XClass;
   
  @@ -21,20 +22,26 @@
   public class AntDocTypeSubTask
       extends AntTypeSubTask
   {
  +    private final Map m_nestedElements = new HashMap();
  +
       public AntDocTypeSubTask()
       {
           setDestinationFile( "{0}.xml" );
           final URL resource = getClass().getResource( "/org/apache/myrmidon/build/type.j"
);
           setTemplateURL( resource );
  -
  -        final TemplateSubTask.ExtentTypes extent = new TemplateSubTask.ExtentTypes();
  -        extent.setValue( "hierarchy" );
  -        setExtent( extent );
       }
   
       public String getSubTaskName()
       {
           return "type-antdoc";
  +    }
  +
  +    /**
  +     * Returns the map to use to track the classes for nested elements.
  +     */
  +    protected Map getNestedElementMap()
  +    {
  +        return m_nestedElements;
       }
   
       protected boolean matchesGenerationRules( final XClass clazz )
  
  
  
  1.2       +13 -3     jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntTypeSubTask.java
  
  Index: AntTypeSubTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntTypeSubTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AntTypeSubTask.java	2 Jun 2002 04:58:51 -0000	1.1
  +++ AntTypeSubTask.java	12 Jun 2002 06:51:04 -0000	1.2
  @@ -10,6 +10,7 @@
   import xdoclet.TemplateSubTask;
   import xdoclet.XDocletException;
   import xdoclet.template.TemplateException;
  +import java.util.Map;
   
   /**
    * A subtask that deals with ant type tags.
  @@ -28,11 +29,20 @@
           super.init();
           try
           {
  -            getEngine().setTagHandlerFor( "Ant", new AntTypeTagHandler() );
  +            final AntTypeTagHandler tagHandler = new AntTypeTagHandler( getNestedElementMap()
);
  +            getEngine().setTagHandlerFor( "Ant", tagHandler );
           }
  -        catch( TemplateException e )
  +        catch( final TemplateException e )
           {
               throw new XDocletException( e, e.getMessage() );
           }
  +    }
  +
  +    /**
  +     * Returns the map to use to track the classes for nested elements.
  +     */
  +    protected Map getNestedElementMap()
  +    {
  +        return null;
       }
   }
  
  
  
  1.4       +56 -3     jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntTypeTagHandler.java
  
  Index: AntTypeTagHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntTypeTagHandler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AntTypeTagHandler.java	11 Jun 2002 11:42:00 -0000	1.3
  +++ AntTypeTagHandler.java	12 Jun 2002 06:51:04 -0000	1.4
  @@ -27,6 +27,44 @@
   public class AntTypeTagHandler
       extends XDocletTagSupport
   {
  +    private final Map m_nestedClasses;
  +
  +    public AntTypeTagHandler( final Map nestedClasses )
  +    {
  +        m_nestedClasses = nestedClasses;
  +    }
  +
  +    /**
  +     * Recursively collects the classes used as nested elements of this class.
  +     */
  +    public String collectNestedClasses()
  +    {
  +        if( m_nestedClasses != null )
  +        {
  +            final ArrayList queue = new ArrayList();
  +            queue.add( getCurrentClass() );
  +            while( queue.size() > 0 )
  +            {
  +                final XClass clazz = (XClass)queue.remove( 0 );
  +                if( m_nestedClasses.containsKey( clazz.getQualifiedName() ) )
  +                {
  +                    continue;
  +                }
  +
  +                m_nestedClasses.put( clazz.getQualifiedName(), clazz );
  +                final XMethod[] methods = getPropertyMethods( clazz, "add", false );
  +                for( int i = 0; i < methods.length; i++ )
  +                {
  +                    final XMethod method = methods[ i ];
  +                    final XClass childClazz = method.getParameters()[ 0 ].getType();
  +                    queue.add( childClazz );
  +                }
  +            }
  +        }
  +
  +        return "";
  +    }
  +
       /**
        * Iterates over the type tags of the current class.
        */
  @@ -103,11 +141,26 @@
       }
   
       /**
  -     * Returns the role display name of the current class.
  +     * Returns the role display name of the current class.  Currently, this
  +     * is simply the capitalised role name.
        */
       public String roleDisplayName()
       {
  -        return roleName();
  +        final StringBuffer buffer = new StringBuffer( roleName() );
  +        final int length = buffer.length();
  +        for( int i = 0; i < length; i++ )
  +        {
  +            if( i == 0 )
  +            {
  +                buffer.setCharAt( i, Character.toUpperCase( buffer.charAt( i ) ) );
  +            }
  +            else if( buffer.charAt( i ) == '-' && i < length-1 )
  +            {
  +                buffer.setCharAt( i, ' ' );
  +                buffer.setCharAt( i+1, Character.toUpperCase( buffer.charAt( i+1 ) ) );
  +            }
  +        }
  +        return buffer.toString();
       }
   
       /**
  
  
  
  1.9       +3 -1      jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntlibDescriptorTask.java
  
  Index: AntlibDescriptorTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntlibDescriptorTask.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AntlibDescriptorTask.java	11 Jun 2002 11:47:04 -0000	1.8
  +++ AntlibDescriptorTask.java	12 Jun 2002 06:51:04 -0000	1.9
  @@ -51,7 +51,9 @@
       {
           if( antDocs )
           {
  -            addTemplate( new AntDocTypeSubTask() );
  +            final AntDocTypeSubTask typeSubtask = new AntDocTypeSubTask();
  +            addTemplate( typeSubtask );
  +            addTemplate( new AntDocNestedTypeSubTask( typeSubtask.getNestedElementMap()
) );
               addTemplate( new AntDocRoleSubTask() );
               final TemplateSubTask typesTemplate = makeTemplateSubTask( TYPES_TEMPLATE,
"types.xml" );
               addTemplate( typesTemplate );
  
  
  
  1.3       +1 -0      jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/type.j
  
  Index: type.j
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/type.j,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- type.j	2 Jun 2002 04:58:51 -0000	1.2
  +++ type.j	12 Jun 2002 06:51:04 -0000	1.3
  @@ -1,4 +1,5 @@
   <type classname="<XDtClass:fullClassName/>">
  +  <XDtAnt:collectNestedClasses/>
     <names>
       <XDtAnt:forAllTypeTags>
         <name role="<XDtAnt:typeTagRoleName/>" name="<XDtAnt:typeTagTypeName/>"/>
  
  
  
  1.1                  jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntDocNestedTypeSubTask.java
  
  Index: AntDocNestedTypeSubTask.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.build;
  
  import java.util.Map;
  import java.net.URL;
  import xjavadoc.XClass;
  import xdoclet.XDocletException;
  
  /**
   * Generates documentation for classes used as nested elements.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/12 06:51:04 $
   */
  public class AntDocNestedTypeSubTask
      extends AntTypeSubTask
  {
      private final Map m_nestedElements;
  
      public AntDocNestedTypeSubTask( final Map nestedElements )
      {
          m_nestedElements = nestedElements;
          setDestinationFile( "{0}.xml" );
          final URL resource = getClass().getResource( "/org/apache/myrmidon/build/type.j"
);
          setTemplateURL( resource );
      }
  
      public String getSubTaskName()
      {
          return "nested-type-antdoc";
      }
  
      protected boolean matchesGenerationRules( XClass clazz )
          throws XDocletException
      {
          if( !super.matchesGenerationRules( clazz ) )
          {
              return false;
          }
          if( AntTypeTagHandler.hasTypeTag( clazz ) || AntTypeTagHandler.hasRoleTag( clazz
) )
          {
              // Skip classes with type or role tags
              return false;
          }
          return m_nestedElements.containsKey( clazz.getQualifiedName() );
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message