User: rinkrank
  Date: 02/02/22 12:22:31

  Modified:    src/xjavadoc XJavaDoc.java SourceClass.java SimpleNode.java
                        ParameterImpl.java MethodImpl.java
                        ConstructorImpl.java ClassDump.java
                        BinaryClass.java AbstractExecutableMember.java
  Log:
  Implemented flyweight for ParameterImpl. Sorry Ara, that overwrites your 
optimisation.
  Added signature() to ClassDump
  Bypassed XJavaDocRunner
  
  There is a problem now. It's much slower, and 300000 SimpleNodes are generated!
  I'll try to fix it tomorrow. Seems there is too much parsing going on.
  
  Aslak
  
  Revision  Changes    Path
  1.13      +15 -0     xjavadoc/src/xjavadoc/XJavaDoc.java
  
  Index: XJavaDoc.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/XJavaDoc.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -w -r1.12 -r1.13
  --- XJavaDoc.java     20 Feb 2002 00:12:01 -0000      1.12
  +++ XJavaDoc.java     22 Feb 2002 20:22:30 -0000      1.13
  @@ -129,6 +129,7 @@
         * @param dir The new Dir value
         */
        public void setDir(File dir) {
  +             System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXX Using dir : " + 
dir.getAbsolutePath());
                this._dir = dir;
        }
   
  @@ -316,6 +317,7 @@
                }
                long end = System.currentTimeMillis();
                System.out.println("Scanned " + _sourceClasses.size() + " classes in " 
+ (end - start) + " milliseconds.");
  +             printMemoryStatus();
                if (_docletClass != null) {
                        _log.debug("Running doclet " + _docletClass);
                        invokeDoclet();
  @@ -526,6 +528,19 @@
                        _binaryClasses.put(clazz, result);
                }
                return result;
  +     }
  +
  +
  +     /**
  +      * Describe what the method does
  +      *
  +      * @todo-javadoc Write javadocs for method
  +      */
  +     private void printMemoryStatus() {
  +             System.out.println("ParameterImpl instances:   " + 
ParameterImpl.instanceCount);
  +             System.out.println("MethodImpl instances:      " + 
MethodImpl.instanceCount);
  +             System.out.println("ConstructorImpl instances: " + 
ConstructorImpl.instanceCount);
  +             System.out.println("SimpleNode instances:      " + 
SimpleNode.instanceCount);
        }
   
   
  
  
  
  1.4       +5 -4      xjavadoc/src/xjavadoc/SourceClass.java
  
  Index: SourceClass.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/SourceClass.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- SourceClass.java  22 Feb 2002 18:14:49 -0000      1.3
  +++ SourceClass.java  22 Feb 2002 20:22:30 -0000      1.4
  @@ -159,10 +159,11 @@
                        result = 
isUnqualifiedNameInTheSamePackage(unqualifiedClassName, result);
                }
                if (result == null) {
  -                     //if (dot_index == -1) {
  -                     throw new IllegalStateException("Couldn't resolve the 
unqualified class: " + unqualifiedClassName);
  -                     //}????
  -                     //result = 
XJavaDoc.getInstance().getUnknownClass(containingPackage().name() + "." + 
unqualifiedClassName);
  +                     // We'll get here when we use inner classes and nonexisting 
classes
  +                     //throw new IllegalStateException("In class " + 
qualifiedName() + ": Couldn't resolve the unqualified class: " + unqualifiedClassName);
  +
  +                     // Until we fix inner classes...
  +                     return new UnknownClass(unqualifiedClassName);
                }
                return result;
        }
  
  
  
  1.2       +5 -0      xjavadoc/src/xjavadoc/SimpleNode.java
  
  Index: SimpleNode.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/SimpleNode.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- SimpleNode.java   20 Feb 2002 00:12:01 -0000      1.1
  +++ SimpleNode.java   22 Feb 2002 20:22:30 -0000      1.2
  @@ -65,6 +65,10 @@
         */
        protected Token first, last;
        /**
  +      * @todo-javadoc Describe the field
  +      */
  +     public static int instanceCount = 0;
  +     /**
         * Get static reference to Log4J Logger
         */
        private static org.apache.log4j.Category _log = 
org.apache.log4j.Category.getInstance(SimpleNode.class.getName());
  @@ -79,6 +83,7 @@
         */
        public SimpleNode(int i) {
                id = i;
  +             instanceCount++;
        }
   
   
  
  
  
  1.3       +38 -46    xjavadoc/src/xjavadoc/ParameterImpl.java
  
  Index: ParameterImpl.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/ParameterImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- ParameterImpl.java        20 Feb 2002 00:12:01 -0000      1.2
  +++ ParameterImpl.java        22 Feb 2002 20:22:30 -0000      1.3
  @@ -36,58 +36,38 @@
   package xjavadoc;
   
   /**
  + * This is a flyweight implementation of XParameter
  + *
    * @author Ara Abrahamian ([EMAIL PROTECTED])
    * @author <a href="mailto:[EMAIL PROTECTED]";>Aslak Helles�y</a>
    * @created Feb 11, 2002
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
  -class ParameterImpl implements XParameter {
  +final class ParameterImpl implements XParameter {
   
        /**
  -      * @todo-javadoc Describe the field
  -      */
  -     private String _type;
  -     /**
  -      * @todo-javadoc Describe the field
  +      * XMember we're currently reresenting.
         */
  -     private String _name;
  +     private AbstractExecutableMember _containingExecutableMember;
  +
        /**
  -      * @todo-javadoc Describe the field
  +      * Index of the parameter we're currently reresenting.
         */
  -     private int _dimension;
  +     private int _parameterIndex;
  +
        /**
         * @todo-javadoc Describe the field
         */
  -     private XExecutableMember _containingExecutableMember;
  +     public static int instanceCount = 0;
   
   
        /**
  -      * @param type Describe what the parameter does
  -      * @param name Describe what the parameter does
  -      * @param dimension Describe what the parameter does
  -      * @param containingExecutableMember Describe what the parameter does
  -      * @todo-javadoc Write javadocs for method parameter
  -      * @todo-javadoc Write javadocs for method parameter
  -      * @todo-javadoc Write javadocs for method parameter
  -      * @todo-javadoc Write javadocs for method parameter
  -      * @pre type != null
  -      * @pre name != null
  -      */
  -     public ParameterImpl(XExecutableMember containingExecutableMember, String 
type, String name, int dimension) {
  -             if (type == null) {
  -                     throw new IllegalArgumentException("type can't be null");
  -             }
  -             if (name == null) {
  -                     throw new IllegalArgumentException("name can't be null");
  -             }
  -             if (name.equals("")) {
  -                     throw new IllegalArgumentException("name can't be \"\"");
  -             }
  -
  -             _containingExecutableMember = containingExecutableMember;
  -             _type = type;
  -             _name = name;
  -             _dimension = dimension;
  +      * Describe what the ParameterImpl constructor does
  +      *
  +      * @todo-javadoc Write javadocs for constructor
  +      */
  +     public ParameterImpl() {
  +             instanceCount++;
        }
   
   
  @@ -98,8 +78,8 @@
         * @todo-javadoc Write javadocs for method
         * @todo-javadoc Write javadocs for return value
         */
  -     public String name() {
  -             return _name;
  +     public final String name() {
  +             return _containingExecutableMember.getParameterName(_parameterIndex);
        }
   
   
  @@ -110,8 +90,9 @@
         * @todo-javadoc Write javadocs for method
         * @todo-javadoc Write javadocs for return value
         */
  -     public XClass type() {
  -             return _containingExecutableMember.containingClass().qualify(_type);
  +     public final XClass type() {
  +             String type = 
_containingExecutableMember.getParameterType(_parameterIndex);
  +             return _containingExecutableMember.containingClass().qualify(type);
        }
   
   
  @@ -122,8 +103,8 @@
         * @todo-javadoc Write javadocs for method
         * @todo-javadoc Write javadocs for return value
         */
  -     public String toString() {
  -             return _type + " " + _name;
  +     public final String toString() {
  +             return type() + " " + name();
        }
   
   
  @@ -134,8 +115,19 @@
         * @todo-javadoc Write javadocs for method
         * @todo-javadoc Write javadocs for return value
         */
  -     public int dimension() {
  -             return _dimension;
  -     }
  +     public final int dimension() {
  +             return 
_containingExecutableMember.getParameterDimension(_parameterIndex);
   }
   
  +
  +     /**
  +      * Sets the extrinsic state.
  +      *
  +      * @param containingExecutableMember The containing member
  +      * @param parameterIndex
  +      */
  +     final void setState(AbstractExecutableMember containingExecutableMember, int 
parameterIndex) {
  +             _containingExecutableMember = containingExecutableMember;
  +             _parameterIndex = parameterIndex;
  +     }
  +}
  
  
  
  1.3       +6 -0      xjavadoc/src/xjavadoc/MethodImpl.java
  
  Index: MethodImpl.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/MethodImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- MethodImpl.java   20 Feb 2002 00:12:01 -0000      1.2
  +++ MethodImpl.java   22 Feb 2002 20:22:30 -0000      1.3
  @@ -55,6 +55,11 @@
         */
        private int _returnDimension;
   
  +     /**
  +      * @todo-javadoc Describe the field
  +      */
  +     public static int instanceCount = 0;
  +
   
        /**
         * Describe what the SourceMethod constructor does
  @@ -68,6 +73,7 @@
         */
        public MethodImpl(XClass containingClass, String qualifiedName) {
                super(containingClass, qualifiedName);
  +             instanceCount++;
        }
   
   
  
  
  
  1.3       +7 -0      xjavadoc/src/xjavadoc/ConstructorImpl.java
  
  Index: ConstructorImpl.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/ConstructorImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- ConstructorImpl.java      20 Feb 2002 00:12:01 -0000      1.2
  +++ ConstructorImpl.java      22 Feb 2002 20:22:30 -0000      1.3
  @@ -45,6 +45,12 @@
   class ConstructorImpl extends AbstractExecutableMember implements XConstructor {
   
        /**
  +      * @todo-javadoc Describe the field
  +      */
  +     public static int instanceCount = 0;
  +
  +
  +     /**
         * Describe what the SourceConstructor constructor does
         *
         * @param containingClass Describe what the parameter does
  @@ -57,6 +63,7 @@
        public ConstructorImpl(XClass containingClass, String qualifiedName) {
                super(containingClass, qualifiedName);
                setName(containingClass().name());
  +             instanceCount++;
        }
   
   
  
  
  
  1.7       +2 -1      xjavadoc/src/xjavadoc/ClassDump.java
  
  Index: ClassDump.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/ClassDump.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -w -r1.6 -r1.7
  --- ClassDump.java    22 Feb 2002 18:14:49 -0000      1.6
  +++ ClassDump.java    22 Feb 2002 20:22:30 -0000      1.7
  @@ -44,7 +44,7 @@
    * @author Ara Abrahamian ([EMAIL PROTECTED])
    * @author <a href="mailto:[EMAIL PROTECTED]";>Aslak Helles�y</a>
    * @created Feb 2, 2002
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    */
   public class ClassDump extends Task {
   
  @@ -162,6 +162,7 @@
                        XMethod method = methods[i];
                        System.out.println("method=" + method);
                        System.out.println("method.returnType().qualifiedName()=" + 
method.returnType().qualifiedName());
  +                     System.out.println("method.signature()=" + method.signature());
                }
   
                if (!clazz.qualifiedName().equals("java.lang.Object")) {
  
  
  
  1.3       +1 -2      xjavadoc/src/xjavadoc/BinaryClass.java
  
  Index: BinaryClass.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/BinaryClass.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- BinaryClass.java  20 Feb 2002 00:12:01 -0000      1.2
  +++ BinaryClass.java  22 Feb 2002 20:22:31 -0000      1.3
  @@ -158,8 +158,7 @@
                }
                for (int i = parameters.length - 1; i >= 0; i--) {
                        // TODO 1
  -                     ParameterImpl xparameter = new ParameterImpl(executableMember, 
parameters[i].getName(), "p" + i, 0);
  -                     executableMember.addParameter(xparameter);
  +                     executableMember.addParameterData(parameters[i].getName(), "p" 
+ i, 0);
                }
                for (int i = exceptions.length - 1; i >= 0; i--) {
                        executableMember.addThrownException(exceptions[i].getName());
  
  
  
  1.4       +99 -64    xjavadoc/src/xjavadoc/AbstractExecutableMember.java
  
  Index: AbstractExecutableMember.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/AbstractExecutableMember.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- AbstractExecutableMember.java     22 Feb 2002 18:44:41 -0000      1.3
  +++ AbstractExecutableMember.java     22 Feb 2002 20:22:31 -0000      1.4
  @@ -35,8 +35,6 @@
    */
   package xjavadoc;
   
  -import xjavadoc.XParameter;
  -
   import java.util.ArrayList;
   import java.lang.reflect.Modifier;
   
  @@ -52,28 +50,42 @@
        /**
         * @todo-javadoc Describe the field
         */
  -     private ArrayList _parameters;
  +     private ArrayList _parameterData;
        /**
         * @todo-javadoc Describe the field
         */
  -     private XParameter[] _xparameters;
  +     private final ArrayList _thrownExceptions = new ArrayList();
   
        /**
         * @todo-javadoc Describe the field
         */
  -     private ArrayList _thrownExceptions;
  +     private final static XParameter[] EMPTY_PARAMETERS = new XParameter[0];
  +
        /**
  -      * @todo-javadoc Describe the field
  +      * Maximum dimension of a parameter. We want to avoid exessive Integer object
  +      * creation.
         */
  -     private XClass[] _xthrownExceptions;
  +     private final static int MAX_ARRAY_SIZE = 6;
        /**
         * @todo-javadoc Describe the field
         */
  -     private final static XParameter[] NULL_PARAMETERS = new XParameter[0];
  +     private final static Integer[] _dimensions = new Integer[MAX_ARRAY_SIZE];
  +
  +     /**
  +      * Initial size of data to hold parameters. Estimate of average number of
  +      * params in a method.
  +      */
  +     private final static int PARAMETER_DATA_SIZE = 5;
  +
  +     /**
  +      * Initial size of ParameterImpl pool. Estimate of max number of params in a
  +      * method
  +      */
  +     private final static int PARAMETER_POOL_SIZE = 20;
        /**
         * @todo-javadoc Describe the field
         */
  -     private final static XClass[] NULL_THROWN_EXCEPTIONS = new XClass[0];
  +     private final static ParameterImpl[] _parameterPool = new 
ParameterImpl[PARAMETER_POOL_SIZE];
   
   
        /**
  @@ -120,61 +132,63 @@
   
   
        /**
  -      * Describe what the method does
  +      * Adds a parameter
         *
  -      * @return Describe the return value
  -      * @todo-javadoc Write javadocs for method
  -      * @todo-javadoc Write javadocs for return value
  +      * @param type qualified nyme of parameter type
  +      * @param name parameter name
  +      * @param dimension parameter dimension
         */
  -     public XParameter[] parameters() {
  -
  -             if (_parameters == null) {
  -                     return NULL_PARAMETERS;
  -             }
  -
  -             if (_xparameters == null) {
  -                     _xparameters = new XParameter[_parameters.size()];
  -                     _xparameters = (XParameter[])_parameters.toArray(_xparameters);
  +     public void addParameterData(String type, String name, int dimension) {
  +             if (_parameterData == null) {
  +                     _parameterData = new ArrayList(PARAMETER_DATA_SIZE * 3);
                }
  -
  -             return _xparameters;
  +             _parameterData.add(type);
  +             _parameterData.add(name);
  +             _parameterData.add(_dimensions[dimension]);
        }
   
   
        /**
  -      * Describe what the method does
  +      * Returns the method parameters
         *
  -      * @return Describe the return value
  -      * @todo-javadoc Write javadocs for method
  -      * @todo-javadoc Write javadocs for return value
  +      * @todo increase the pool if necessary
  +      * @return the method parameters
         */
  -     public XClass[] thrownExceptions() {
  -
  -             if (_thrownExceptions == null) {
  -                     return NULL_THROWN_EXCEPTIONS;
  +     public final XParameter[] parameters() {
  +             XParameter[] result = null;
  +             if (_parameterData == null) {
  +                     result = EMPTY_PARAMETERS;
                }
  -
  -             if (_xthrownExceptions == null) {
  -                     _xthrownExceptions = new XClass[_thrownExceptions.size()];
  -                     for (int i = 0; i < _xthrownExceptions.length; i++) {
  -                             String exceptionName = 
(String)_thrownExceptions.get(i);
  -                             _xthrownExceptions[i] = 
containingClass().qualify(exceptionName);
  +             else {
  +                     result = new ParameterImpl[_parameterData.size() / 3];
  +                     for (int i = result.length - 1; i >= 0; i--) {
  +                             try {
  +                                     _parameterPool[i].setState(this, i);
  +                                     // TODO increase pool size
  +                                     result[i] = _parameterPool[i];
  +                             } catch (ArrayIndexOutOfBoundsException e) {
  +                                     System.out.println("In member " + 
qualifiedName() + ". Tried to set " + i + "th parameter. FIXME!");
                        }
                }
  -
  -             return _xthrownExceptions;
  +             }
  +             return result;
        }
   
   
        /**
  -      * Describe the method
  +      * Describe what the method does
         *
  -      * @param parameter Describe the method parameter
  -      * @todo-javadoc Describe the method
  -      * @todo-javadoc Describe the method parameter
  +      * @return Describe the return value
  +      * @todo-javadoc Write javadocs for method
  +      * @todo-javadoc Write javadocs for return value
         */
  -     public void addParameter(XParameter parameter) {
  -             getParameters().add(parameter);
  +     public XClass[] thrownExceptions() {
  +             XClass[] thrownExceptions = new XClass[_thrownExceptions.size()];
  +             for (int i = 0; i < thrownExceptions.length; i++) {
  +                     String exceptionName = (String)_thrownExceptions.get(i);
  +                     thrownExceptions[i] = containingClass().qualify(exceptionName);
  +             }
  +             return thrownExceptions;
        }
   
   
  @@ -186,7 +200,7 @@
         * @todo-javadoc Describe the method parameter
         */
        public void addThrownException(String thrownException) {
  -             getThrownException().add(thrownException);
  +             _thrownExceptions.add(thrownException);
        }
   
   
  @@ -197,12 +211,12 @@
         * @todo-javadoc Write javadocs for method
         * @todo-javadoc Write javadocs for return value
         */
  -     public String signature() {
  +     public final String signature() {
                StringBuffer sb = new StringBuffer("(");
                XParameter[] parameters = parameters();
                for (int i = 0; i < parameters.length; i++) {
                        sb.append(toString(parameters[i]));
  -                     if (i < _parameters.size() - 1) {
  +                     if (i < parameters.length - 1) {
                                sb.append(',');
                        }
                }
  @@ -211,30 +225,38 @@
   
   
        /**
  -      * Gets the Parameters attribute of the AbstractExecutableMember object
  +      * Gets the ParameterType attribute of the AbstractExecutableMember object
         *
  -      * @return The Parameters value
  +      * @param index Describe what the parameter does
  +      * @return The ParameterType value
  +      * @todo-javadoc Write javadocs for method parameter
         */
  -     protected ArrayList getParameters() {
  -             if (_parameters == null) {
  -                     _parameters = new ArrayList();
  -             }
  -
  -             return _parameters;
  +     final String getParameterType(int index) {
  +             return (String)_parameterData.get(index * 3);
        }
   
   
        /**
  -      * Gets the ThrownException attribute of the AbstractExecutableMember object
  +      * Gets the ParameterName attribute of the AbstractExecutableMember object
         *
  -      * @return The ThrownException value
  +      * @param index Describe what the parameter does
  +      * @return The ParameterName value
  +      * @todo-javadoc Write javadocs for method parameter
         */
  -     protected ArrayList getThrownException() {
  -             if (_thrownExceptions == null) {
  -                     _thrownExceptions = new ArrayList();
  +     final String getParameterName(int index) {
  +             return (String)_parameterData.get(index * 3 + 1);
                }
   
  -             return _thrownExceptions;
  +
  +     /**
  +      * Gets the ParameterDimension attribute of the AbstractExecutableMember object
  +      *
  +      * @param index Describe what the parameter does
  +      * @return The ParameterDimension value
  +      * @todo-javadoc Write javadocs for method parameter
  +      */
  +     final int getParameterDimension(int index) {
  +             return ((Integer)_parameterData.get(index * 3 + 2)).intValue();
        }
   
   
  @@ -248,10 +270,23 @@
         * @todo-javadoc Write javadocs for return value
         */
        private final static String toString(XParameter parameter) {
  +             if (parameter == null) {
  +                     throw new IllegalStateException("parameter can't be null!");
  +             }
                StringBuffer sb = new StringBuffer(parameter.type().qualifiedName());
                for (int i = parameter.dimension() - 1; i >= 0; i--) {
                        sb.append("[]");
                }
                return sb.toString();
  +     }
  +     static {
  +             for (int i = 0; i < MAX_ARRAY_SIZE; i++) {
  +                     _dimensions[i] = new Integer(i);
  +             }
  +     }
  +     static {
  +             for (int i = 0; i < PARAMETER_POOL_SIZE; i++) {
  +                     _parameterPool[i] = new ParameterImpl();
  +             }
        }
   }
  
  
  

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

Reply via email to