/[classpath]/classpath/java/beans/Statement.java
ViewVC logotype

Diff of /classpath/java/beans/Statement.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.2.1 by gnu_andrew, Tue Aug 2 20:12:16 2005 UTC revision 1.1.2.2 by gnu_andrew, Sat Sep 10 15:31:46 2005 UTC
# Line 1  Line 1 
1  /* java.beans.Statement  /* java.beans.Statement
2     Copyright (C) 2004 Free Software Foundation, Inc.     Copyright (C) 2004, 2005 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 42  import java.lang.reflect.Array; Line 42  import java.lang.reflect.Array;
42  import java.lang.reflect.Constructor;  import java.lang.reflect.Constructor;
43  import java.lang.reflect.Method;  import java.lang.reflect.Method;
44    
45    import java.util.HashMap;
46    import java.util.WeakHashMap;
47    
48  /**  /**
49   * class Statement   * class Statement
50   *   *
# Line 54  import java.lang.reflect.Method; Line 57  import java.lang.reflect.Method;
57   */   */
58  public class Statement  public class Statement
59  {  {
60      /** Nested map for the relation between a class, its instances and their
61        * names.
62        */
63      private static HashMap classMaps = new HashMap();
64    
65    private Object target;    private Object target;
66    private String methodName;    private String methodName;
67    private Object[] arguments;    private Object[] arguments;
# Line 64  public class Statement Line 72  public class Statement
72    private transient Constructor ctor;    private transient Constructor ctor;
73    
74    /**    /**
75     * Constructs a statement representing the invocation of     * <p>Constructs a statement representing the invocation of
76     * object.methodName(arg[0], arg[1], ...);     * object.methodName(arg[0], arg[1], ...);</p>
77       *
78       * <p>If the argument array is null it is replaced with an
79       * array of zero length.</p>
80     *     *
81     * @param target The object to invoke the method on.     * @param target The object to invoke the method on.
82     * @param methodName The object method to invoke.     * @param methodName The object method to invoke.
# Line 75  public class Statement Line 86  public class Statement
86    {    {
87      this.target = target;      this.target = target;
88      this.methodName = methodName;      this.methodName = methodName;
89      this.arguments = arguments;      this.arguments = (arguments != null) ? arguments : new Object[0];
90        storeTargetName(target);
91      }
92    
93      /** Creates a name for the target instance or does nothing if the object's
94       * name is already known. This makes sure that there *is* a name for every
95       * target instance.
96       */
97      private static synchronized void storeTargetName(Object obj)
98      {
99        Class klass = obj.getClass();
100        WeakHashMap names = (WeakHashMap) classMaps.get(klass);
101    
102        if ( names == null )
103        {
104          names = new WeakHashMap();
105    
106          names.put(obj,
107            ( klass == String.class ? ("\"" + obj + "\"") :
108            (klass.getName() + names.size()) ));
109    
110          classMaps.put(klass, names);
111    
112          return;
113        }
114    
115        String targetName = (String) names.get(obj);
116        if ( targetName == null )
117        {
118          names.put(obj,
119            ( klass == String.class ? ("\"" + obj + "\"") :
120            (klass.getName() + names.size()) ));
121        }
122    
123        // Nothing to do. The given object was already stored.
124    }    }
125    
126    /**    /**
# Line 234  public class Statement Line 279  public class Statement
279            {            {
280              // Skip methods with wrong number of args.              // Skip methods with wrong number of args.
281              Class ptypes[] = ctors[i].getParameterTypes();              Class ptypes[] = ctors[i].getParameterTypes();
282              System.out.println("ptypeslen = " + ptypes.length);  
             System.out.println("ptypes = " + ptypes);  
             System.out.println("ctor = " + ctors[i].getName());  
             for (int j=0; j < ptypes.length; j++) {  
               System.out.println("param = " + ptypes[i].getName());  
       
             }  
                 
               
283              if (ptypes.length != args.length)              if (ptypes.length != args.length)
284                continue;                continue;
285    
# Line 313  public class Statement Line 350  public class Statement
350    /** Return a string representation. */    /** Return a string representation. */
351    public String toString()    public String toString()
352    {    {
353      String result = target.getClass().getName() + "." + methodName + "(";      StringBuffer result = new StringBuffer();
354    
355        Class klass = target.getClass();
356    
357        result.append( ((WeakHashMap) classMaps.get(klass)).get(target));
358        result.append(".");
359        result.append(methodName);
360        result.append("(");
361    
362      String sep = "";      String sep = "";
363      for (int i = 0; i < arguments.length; i++)      for (int i = 0; i < arguments.length; i++)
364        {        {
365          result = result + sep + arguments[i].getClass().getName();          result.append(sep);
366          sep = ", ";          result.append(arguments[i].getClass().getName());
367            sep = ", ";
368        }        }
369      result = result + ")";      result.append(")");
370      return result;  
371        return result.toString();
372    }    }
373  }  }

Legend:
Removed from v.1.1.2.1  
changed lines
  Added in v.1.1.2.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26