Update of /cvsroot/xdoclet/xjavadoc/src/xjavadoc
In directory sc8-pr-cvs1:/tmp/cvs-serv24404/xjavadoc/src/xjavadoc

Modified Files:
        MethodImpl.java ParameterImpl.java ReturnType.java 
        XJavaDoc.java XJavaDocTest.java XMethod.java 
Added Files:
        AbstractType.java 
Log Message:
Added two method to XMethod: getAccessor() and getMutator(). These are for accessing a 
mutator method's corresponding accessor method and vice versa.

--- NEW FILE: AbstractType.java ---
/*
 * Copyright (c) 2001-2003 The XDoclet team
 * All rights reserved.
 */
package xjavadoc;

/**
 * Base class for Type.
 *
 * @author    <a href="mailto:aslak.hellesoy at bekk.no">Aslak Helles&oslash;y
 *      </a>
 * @created   25. mars 2003
 * @version   Revision: 1.0 $
 */
abstract class AbstractType implements Type
{
        public boolean equals( Object o )
        {
                if( ( o instanceof Type ) )
                {
                        Type other = ( Type ) o;
                        boolean typeEqual = getType().equals( other.getType() );
                        boolean dimensionEqual = getDimension() == 
other.getDimension();

                        return typeEqual && dimensionEqual;
                }
                return false;
        }
}

Index: MethodImpl.java
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/MethodImpl.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -r1.26 -r1.27
*** MethodImpl.java     21 Mar 2003 15:36:12 -0000      1.26
--- MethodImpl.java     25 Mar 2003 23:55:51 -0000      1.27
***************
*** 56,59 ****
--- 56,104 ----
        }
  
+       public XMethod getAccessor()
+       {
+               XMethod result = null;
+ 
+               if( isPropertyMutator() )
+               {
+                       Type requiredType = ( Type ) getParameters().iterator().next();
+                       String getterNameWithSignature = "get" + 
getNameWithoutPrefix() + "()";
+                       String isserNameWithSignature = "is" + getNameWithoutPrefix() 
+ "()";
+                       XMethod getter = getContainingClass().getMethod( 
getterNameWithSignature, true );
+                       XMethod isser = getContainingClass().getMethod( 
isserNameWithSignature, true );
+ 
+                       // If only one is non null, return it. If both or none exist, 
return null.
+                       if( getter == null && isser != null )
+                       {
+                               result = isser;
+                       }
+                       else if( getter != null && isser == null )
+                       {
+                               result = getter;
+                       }
+                       // Verify that the types are compatible
+                       if( !requiredType.equals( result.getReturnType() ) )
+                       {
+                               result = null;
+                       }
+               }
+               return result;
+       }
+ 
+       public XMethod getMutator()
+       {
+               XMethod result = null;
+ 
+               if( isPropertyAccessor() )
+               {
+                       Type requiredType = getReturnType();
+                       String argument = requiredType.getType().getQualifiedName() + 
requiredType.getDimensionAsString();
+                       String setterNameWithSignature = "set" + 
getNameWithoutPrefix() + "(" + argument + ")";
+ 
+                       result = getContainingClass().getMethod( 
setterNameWithSignature, true );
+               }
+               return result;
+       }
+ 
        public boolean isPropertyAccessor()
        {
***************
*** 64,67 ****
--- 109,113 ----
                {
                        signatureOk = 
getReturnType().getType().getQualifiedName().equals( "boolean" ) || 
getReturnType().getType().getQualifiedName().equals( "java.lang.Boolean" );
+                       signatureOk = signatureOk && getReturnType().getDimension() == 
0;
                        if( getName().length() > 2 )
                        {
***************
*** 182,185 ****
--- 228,246 ----
        }
  
+       private String getNameWithoutPrefix()
+       {
+               String result = null;
+ 
+               if( isPropertyAccessor() )
+               {
+                       result = getName().startsWith( "is" ) ? getName().substring( 2 
) : getName().substring( 3 );
+               }
+               else if( isPropertyMutator() )
+               {
+                       result = getName().substring( 3 );
+               }
+               return result;
+       }
+ 
        private String getMethodNameWithSignatureAndModifiers()
        {
***************
*** 212,216 ****
                if( modifiers )
                {
!                       sb = new StringBuffer( getModifiers() ).append( ' ' );
                }
                else
--- 273,281 ----
                if( modifiers )
                {
!                       sb = new StringBuffer( getModifiers() );
!                       if( sb.length() > 0 )
!                       {
!                               sb.append( ' ' );
!                       }
                }
                else

Index: ParameterImpl.java
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/ParameterImpl.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -r1.16 -r1.17
*** ParameterImpl.java  20 Mar 2003 22:35:51 -0000      1.16
--- ParameterImpl.java  25 Mar 2003 23:55:51 -0000      1.17
***************
*** 16,20 ****
   * @version   $Revision$
   */
! public final class ParameterImpl implements XParameter
  {
        public static int  instanceCount = 0;
--- 16,20 ----
   * @version   $Revision$
   */
! public final class ParameterImpl extends AbstractType implements XParameter
  {
        public static int  instanceCount = 0;

Index: ReturnType.java
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/ReturnType.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** ReturnType.java     20 Mar 2003 22:35:51 -0000      1.1
--- ReturnType.java     25 Mar 2003 23:55:51 -0000      1.2
***************
*** 13,17 ****
   * @version   $Revision$
   */
! class ReturnType implements Type
  {
        private MethodImpl _method;
--- 13,17 ----
   * @version   $Revision$
   */
! class ReturnType extends AbstractType
  {
        private MethodImpl _method;

Index: XJavaDoc.java
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/XJavaDoc.java,v
retrieving revision 1.70
retrieving revision 1.71
diff -C2 -r1.70 -r1.71
*** XJavaDoc.java       20 Mar 2003 22:35:54 -0000      1.70
--- XJavaDoc.java       25 Mar 2003 23:55:52 -0000      1.71
***************
*** 425,429 ****
         * </b> If the Java source can be located, an instance of SourceClass will be
         * returned. -Even if that file was not among the files in the fileset or
!        * sourceset.
         *
         * @param qualifiedName  Fully qualified class name
--- 425,431 ----
         * </b> If the Java source can be located, an instance of SourceClass will be
         * returned. -Even if that file was not among the files in the fileset or
!        * sourceset. <b>IMPORTANT: </b> If qualifiedName represents an inner class, an
!        * UnknownClass will be returned unless the enclousing "outer" class has been
!        * resolved first.
         *
         * @param qualifiedName  Fully qualified class name

Index: XJavaDocTest.java
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/XJavaDocTest.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -r1.49 -r1.50
*** XJavaDocTest.java   21 Mar 2003 15:36:17 -0000      1.49
--- XJavaDocTest.java   25 Mar 2003 23:55:53 -0000      1.50
***************
*** 17,36 ****
  
  /**
!  * Describe what this class does
!  *
!  * @author         <a href="mailto:[EMAIL PROTECTED]">Aslak Hellesøy</a>
!  * @created        8. januar 2002
!  * @todo-javadoc   Write javadocs
   */
  public class XJavaDocTest extends TestCase
  {
  
-       /**
-        * Describe what the XJavaDocTest constructor does
-        *
-        * @param name     Describe what the parameter does
-        * @todo-javadoc   Write javadocs for constructor
-        * @todo-javadoc   Write javadocs for method parameter
-        */
        public XJavaDocTest( String name )
        {
--- 17,25 ----
  
  /**
!  * @created   25. mars 2003
   */
  public class XJavaDocTest extends TestCase
  {
  
        public XJavaDocTest( String name )
        {
***************
*** 38,47 ****
        }
  
-       /**
-        * The JUnit setup method
-        *
-        * @exception Exception  Describe the exception
-        * @todo-javadoc         Write javadocs for exception
-        */
        public void setUp() throws Exception
        {
--- 27,30 ----
***************
*** 58,77 ****
  
        /**
-        * The teardown method for JUnit
-        *
-        * @exception Exception  Describe the exception
-        * @todo                 Uncomment the body. Reset should be done really, but
-        *      it doesn't work properly.
-        * @todo-javadoc         Write javadocs for exception
-        */
-       public void tearDown() throws Exception
-       {
-               /*
-                * See @todo
-                * XJavaDoc.getInstance().reset();
-                */
-       }
- 
-       /**
         * A unit test for JUnit
         */
--- 41,44 ----
***************
*** 161,167 ****
         * change was successful.
         *
!        * @exception Exception  Describe the exception
!        * @todo                 reread
!        * @todo-javadoc         Write javadocs for exception
         */
        public void testGetMethodParameterValue() throws Exception
--- 128,132 ----
         * change was successful.
         *
!        * @exception Exception
         */
        public void testGetMethodParameterValue() throws Exception
***************
*** 179,186 ****
        }
  
-       /**
-        * @exception Exception  Describe the exception
-        * @todo-javadoc         Write javadocs for exception
-        */
        public void testModifyMethodParameterValue() throws Exception
        {
--- 144,147 ----
***************
*** 199,208 ****
        }
  
-       /**
-        * A unit test for JUnit
-        *
-        * @exception Exception  Describe the exception
-        * @todo-javadoc         Write javadocs for exception
-        */
        public void testAddCommentToCommentedClass() throws Exception
        {
--- 160,163 ----
***************
*** 214,223 ****
        }
  
-       /**
-        * A unit test for JUnit
-        *
-        * @exception Exception  Describe the exception
-        * @todo-javadoc         Write javadocs for exception
-        */
        public void testInnerlass() throws Exception
        {
--- 169,172 ----
***************
*** 238,247 ****
        }
  
-       /**
-        * A unit test for JUnit
-        *
-        * @exception Exception  Describe the exception
-        * @todo-javadoc         Write javadocs for exception
-        */
        public void testIsA() throws Exception
        {
--- 187,190 ----
***************
*** 360,369 ****
        }
  
-       /**
-        * A unit test for JUnit
-        *
-        * @exception Exception  Describe the exception
-        * @todo-javadoc         Write javadocs for exception
-        */
        public void testAddCommentToUncommentedMethod() throws Exception
        {
--- 303,306 ----
***************
*** 382,389 ****
        }
  
-       /**
-        * @exception Exception  Describe the exception
-        * @todo-javadoc         Write javadocs for exception
-        */
        public void testBinaryClassHasNoMembersBecauseOfSpeedOptimisation() throws 
Exception
        {
--- 319,322 ----
***************
*** 470,474 ****
        }
  
!       public void testAttributeMethods() throws Exception
        {
                XClass hello = XJavaDoc.getInstance().getXClass( "Hello" );
--- 403,407 ----
        }
  
!       public void testPropertyMethods1() throws Exception
        {
                XClass hello = XJavaDoc.getInstance().getXClass( "Hello" );
***************
*** 493,496 ****
--- 426,467 ----
        }
  
+       public void testPropertyMethods2()
+       {
+               // Get the enclosing class first, just to resolve the rest.
+               XClass abAB = XJavaDoc.getInstance().getXClass( "ab.AB" );
+               XClass abABC = XJavaDoc.getInstance().getXClass( "ab.AB.C" );
+ 
+               XMethod getFoo = abABC.getMethod( "getFoo()" );
+ 
+               assertTrue( getFoo.isPropertyAccessor() );
+ 
+               XMethod setFoo = abABC.getMethod( "setFoo(java.lang.String)" );
+ 
+               assertTrue( setFoo.isPropertyMutator() );
+ 
+               assertSame( getFoo, setFoo.getAccessor() );
+               assertSame( setFoo, getFoo.getMutator() );
+ 
+               XMethod getBar = abABC.getMethod( "getBar()" );
+ 
+               assertTrue( getBar.isPropertyAccessor() );
+ 
+               XMethod setBar = abABC.getMethod( "setBar(int)" );
+ 
+               assertTrue( setBar.isPropertyMutator() );
+ 
+               assertNull( getBar.getMutator() );
+               assertNull( setBar.getAccessor() );
+ 
+               XMethod isThisIsNotAnAccessor = abABC.getMethod( 
"isThisIsNotAnAccessor()" );
+ 
+               assertTrue( !isThisIsNotAnAccessor.isPropertyAccessor() );
+ 
+               XMethod setThisIsAMutator = abABC.getMethod( 
"setThisIsAMutator(boolean[])" );
+ 
+               assertTrue( setThisIsAMutator.isPropertyMutator() );
+ 
+       }
+ 
        /**
         * Test for bugfix for XJD-17
***************
*** 498,513 ****
        public void testXJD17()
        {
!               XClass abAA = XJavaDoc.getInstance().getXClass( "ab.AB" );
                XClass abB = XJavaDoc.getInstance().getXClass( "ab.B" );
  
!               assertEquals( xjavadoc.SourceClass.class, abAA.getClass() );
                assertEquals( xjavadoc.SourceClass.class, abB.getClass() );
!               assertTrue( !abAA.isInterface() );
                assertTrue( abB.isInterface() );
!               assertTrue( !abAA.isInner() );
                assertTrue( !abB.isInner() );
!               assertTrue( !abAA.isAnonymous() );
                assertTrue( !abB.isAnonymous() );
!               assertEquals( "ab", abAA.getContainingPackage().getName() );
                assertEquals( "ab", abB.getContainingPackage().getName() );
  
--- 469,484 ----
        public void testXJD17()
        {
!               XClass abAB = XJavaDoc.getInstance().getXClass( "ab.AB" );
                XClass abB = XJavaDoc.getInstance().getXClass( "ab.B" );
  
!               assertEquals( xjavadoc.SourceClass.class, abAB.getClass() );
                assertEquals( xjavadoc.SourceClass.class, abB.getClass() );
!               assertTrue( !abAB.isInterface() );
                assertTrue( abB.isInterface() );
!               assertTrue( !abAB.isInner() );
                assertTrue( !abB.isInner() );
!               assertTrue( !abAB.isAnonymous() );
                assertTrue( !abB.isAnonymous() );
!               assertEquals( "ab", abAB.getContainingPackage().getName() );
                assertEquals( "ab", abB.getContainingPackage().getName() );
  

Index: XMethod.java
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/XMethod.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** XMethod.java        20 Mar 2003 22:35:56 -0000      1.14
--- XMethod.java        25 Mar 2003 23:55:54 -0000      1.15
***************
*** 62,65 ****
--- 62,81 ----
  
        /**
+        * If this method is a mutator, and a corresponding accessor exists, that
+        * accessor will be returned. Otherwise, null is returned.
+        *
+        * @return   the corresponding accessor.
+        */
+       public XMethod getAccessor();
+ 
+       /**
+        * If this method is an accessor, and a corresponding mutator exists, that
+        * mutator will be returned. Otherwise, null is returned.
+        *
+        * @return   the corresponding mutator.
+        */
+       public XMethod getMutator();
+ 
+       /**
         * @created   20. mars 2003
         */



-------------------------------------------------------
This SF.net email is sponsored by:
The Definitive IT and Networking Event. Be There!
NetWorld+Interop Las Vegas 2003 -- Register today!
http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en
_______________________________________________
xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to