# HG changeset patch
# User Ernst Reissner <rei3ner@arcor.de>
# Date 1471647358 -7200
#      Sat Aug 20 00:55:58 2016 +0200
# Node ID de95ec1a5a97b67806c5970441d34263cbc7ad88
# Parent  2164b6e1cc1a615212ec7aba680b96e81f026900
preparation of ClassHelper for bugfix of 48593: structs

- ClassHelper: methods getFieldsXXX, getMethodsXXX, getConstructorsXXX:
  essentially now return String[] one field, method, constructor per entry,
  and no longer String of list of ';'-separated entries.
- xxx.m: according rework based on function char(.) instead of ostrsplit(...,';')

diff -r 2164b6e1cc1a -r de95ec1a5a97 scripts/general/fieldnames.m
--- a/scripts/general/fieldnames.m	Fri Aug 19 19:01:36 2016 +0200
+++ b/scripts/general/fieldnames.m	Sat Aug 20 00:55:58 2016 +0200
@@ -63,13 +63,11 @@
     ## So we decided that class names always refer to Java classes, 
     ## never to Octave classes. 
     ## This is unlike for methods.m for which Matlab allows both 
-    names_str = javaMethod ("getFieldsCls", 
-                            "org.octave.ClassHelper", obj, isfull);
-    names = ostrsplit (names_str, ';');
+    names = javaMethod ("getFieldsCls", "org.octave.ClassHelper", obj, isfull);
+    names = char(names);
   elseif (isjava (obj))
-    names_str = javaMethod ("getFieldsObj", 
-                            "org.octave.ClassHelper", obj, isfull);
-    names = ostrsplit (names_str, ';');
+    names = javaMethod ("getFieldsObj", "org.octave.ClassHelper", obj, isfull);
+    names = char(names);
   else
     error ("fieldnames: Invalid input argument");
   endif
diff -r 2164b6e1cc1a -r de95ec1a5a97 scripts/general/methods.m
--- a/scripts/general/methods.m	Fri Aug 19 19:01:36 2016 +0200
+++ b/scripts/general/methods.m	Sat Aug 20 00:55:58 2016 +0200
@@ -65,14 +65,14 @@
     mtds_list = __methods__ (obj);
     if (isempty (mtds_list))
       ## assume that obj refers to a java class 
-      mtds_str = javaMethod ("getMethodsCls", 
-                             "org.octave.ClassHelper", obj, isfull);
-      mtds_list = ostrsplit (mtds_str, ';');
+      mtds_list = javaMethod ("getMethodsCls", 
+                              "org.octave.ClassHelper", obj, isfull);
+      mtds_list = char(mtds_list);
     endif
   elseif (isjava (obj))
-    mtds_str = javaMethod ("getMethodsObj", 
+    mtds_list = javaMethod ("getMethodsObj", 
                            "org.octave.ClassHelper", obj, isfull);
-    mtds_list = strsplit (mtds_str, ';');
+    mtds_list = char(mtds_list);
   else
     error ("methods: Invalid input argument");
   endif
diff -r 2164b6e1cc1a -r de95ec1a5a97 scripts/java/constructors.m
--- a/scripts/java/constructors.m	Fri Aug 19 19:01:36 2016 +0200
+++ b/scripts/java/constructors.m	Sat Aug 20 00:55:58 2016 +0200
@@ -53,12 +53,12 @@
 
   if  (ischar (obj))
     retval = javaMethod ("getConstructorsCls", "org.octave.ClassHelper", obj);
-    retval = ostrsplit (retval, ';');
   elseif (isjava (obj))
     retval = javaMethod ("getConstructorsObj", "org.octave.ClassHelper", obj);
-    retval = ostrsplit (retval, ';');
   else
     error ("constructors: Invalid input argument");
   endif
+
+  retval = char(retval);
 endfunction
 
diff -r 2164b6e1cc1a -r de95ec1a5a97 scripts/java/org/octave/ClassHelper.java
--- a/scripts/java/org/octave/ClassHelper.java	Fri Aug 19 19:01:36 2016 +0200
+++ b/scripts/java/org/octave/ClassHelper.java	Sat Aug 20 00:55:58 2016 +0200
@@ -37,6 +37,9 @@
 import java.lang.reflect.Member;
 import java.lang.reflect.Executable;
 
+import java.util.List;
+import java.util.ArrayList;
+
 //! Collection of methods being the core of the octave functions
 //! forming Octave's Java Interface.
 //!
@@ -322,15 +325,13 @@
       }
   }
 
-  // new -MH-
-  //! Return list of string representations of all public methods
+  //! Return an array of string representations of all public methods
   //! of given class @c klass, where @c isFull determines 
   //! whether that representation comprises more than the mere name.
   //!
   //! This method is based on Class::getMethods().
   //! To obtain all methods, one could use Class::getDeclaredMethods()
   //! iterating over class and superclasses.
-  //! Used internally and by @file methods.m only.
   //!
   //! @param klass
   //!    the class under consideration.
@@ -340,26 +341,24 @@
   //!    including the modifiers except @c public, the return type, 
   //!    the name, the parameter list and the declared throwables. 
   //! @return
-  //!    the list of string representations of the public methods 
-  //!    of the given class @c klass as a string,
-  //!    separated by <code>;</code>.
+  //!    an array of string representations of the public methods 
+  //!    of the given class @c klass as a string.
   //!    For <code>isFull==false</code> this is just the name,
-  //!    otherwise the full signature including the modifiers except @c public 
+  //!    otherwise the full signature including the modifiers except @c public, 
   //!    the return type, the name, the parameter list
   //!    and the throws-declaration as e.g. 
-  //!    <code>static void main(String[]) throws Exception</code>.
-  private static String getMethods (Class klass, boolean isFull)
+  //!    <code>static void main(String[]) throws Exception</code>
+  //!    followed by Octave comment with inheritance information.
+  private static String[] getMethods (Class klass, boolean isFull)
   {
-    StringBuffer sb = new StringBuffer ();
     Method[] methods = klass.getMethods ();
     Method theMethod;
-     for (int i = 0; i < methods.length; i++)
+    StringBuffer sb;
+    List res = new ArrayList();
+    for (int i = 0; i < methods.length; i++)
       {
         theMethod = methods[i];
-        if (i > 0)
-          {
-            sb.append (';');
-          }
+        sb = new StringBuffer ();
 
         if (isFull)
           {
@@ -381,13 +380,14 @@
             // append inheritance information by need
             appendInheritance(klass, theMethod, sb);
           }
+
+        res.add(sb.toString ());
       }
 
-    return sb.toString ();
+    return (String[])res.toArray (new String[res.size()]);
   }
 
-  // new -MH-
-  //! Return a list of string representations of public methods
+  //! Return an array of string representations of public methods
   //! of the class with the given class name @c classname
   //! loaded with #loader, where @c isFull determines 
   //! whether that representation comprises more than the mere name.
@@ -404,14 +404,13 @@
   //!    see ::getMethods(Class, boolean).
   //! @throws ClassNotFoundException
   //!    if #loader cannot find a class with name @c classname.
-  public static String getMethodsCls (String classname, boolean isFull)
+  public static String[] getMethodsCls (String classname, boolean isFull)
     throws ClassNotFoundException
   {
     return getMethods (Class.forName (classname, true, loader), isFull);
   }
 
-  // new -MH-
-  //! Return a list of string representations of all of public methods
+  //! Return an array of string representations of all of public methods
   //! of the class of the instance @c obj, where @c isFull determines 
   //! whether that representation comprises more than the mere name.
   //!
@@ -425,18 +424,12 @@
   //!    comprises more than the name (see ::getMethods(Class, boolean)).
   //! @return
   //!    see ::getMethods(Class, boolean).
-  //! @throws ClassNotFoundException
-  //!    if #loader cannot find @c obj's class.
-  //!    Since all objects are created by reflection
-  //!    from classes loaded by #loader, this shall not happen.
-  public static String getMethodsObj (Object obj, boolean isFull)
-    throws ClassNotFoundException
+  public static String[] getMethodsObj (Object obj, boolean isFull)
   {
     return getMethods (obj.getClass (), isFull);
   }
 
-  // new -MH-
-  //! Return a list of string representations of all public fields
+  //! Return an array of string representations of all public fields
   //! of the given class @c klass, 
   //! where @c isFull determines 
   //! whether that representation comprises more than the mere name.
@@ -444,7 +437,6 @@
   //! This method is based on Class::getFields().
   //! To obtain all fields, one could use Class::getDeclaredFields()
   //! iterating over class and superclasses.
-  //! Used internally and by @file fieldnames.m only.
   //!
   //! @param klass
   //!    the class under consideration.
@@ -453,29 +445,27 @@
   //!    comprises more than the name: 
   //!    namely in addition the modifiers except @c public and the type. 
   //! @return
-  //!    the list of string representations of the public fields
-  //!    of the given class @c klass as a string,
-  //!    separated by <code>;</code>.
+  //!    an array of string representations of the public fields
+  //!    of the given class @c klass as a string.
   //!    For <code>isFull==false</code> this is just the name,
-  //!    otherwise in addition the modifiers except @c public and the type.
-  //!    Example: <code>public static int num</code>.
-  private static String getFields (Class klass, boolean isFull)
+  //!    otherwise in addition the modifiers except @c public, and the type,
+  //!    as e.g. <code>public static int num</code>,
+  //!    followed by Octave comment with inheritance information.
+  private static String[] getFields (Class klass, boolean isFull)
   {
-    StringBuffer sb = new StringBuffer ();
     Field[] fields = klass.getFields ();
     Field theField;
+    StringBuffer sb;
+    List res = new ArrayList();
     for (int i = 0; i < fields.length; i++)
       {
         theField = fields[i];
-        if (i > 0)
-          {
-            sb.append (';');
-          }
+        sb = new StringBuffer ();
 
         if (isFull)
           {
             // append the modifiers except 'public' and...
-             appendModifiers(theField, sb);
+            appendModifiers(theField, sb);
             // ... its type
             sb.append (theField.getType ().getCanonicalName ());
             sb.append (' ');
@@ -485,13 +475,14 @@
         sb.append (theField.getName ());
         // append inheritance information by need
         appendInheritance(klass, theField, sb);
+
+        res.add(sb.toString ());
       }
 
-    return sb.toString ();
+    return (String[])res.toArray (new String[res.size()]);
   }
 
-  // new -MH-
-  //! Return a list of string representations of all public fields
+  //! Return an array of string representations of all public fields
   //! of the class with the given class name @c classname
   //! loaded with #loader, 
   //! where @c isFull determines 
@@ -509,14 +500,13 @@
   //!    see ::getFields(Class, boolean).
   //! @throws ClassNotFoundException
   //!    if #loader cannot find a class with name @c classname.
-  public static String getFieldsCls (String classname, boolean isFull)
+  public static String[] getFieldsCls (String classname, boolean isFull)
     throws ClassNotFoundException
   {
     return getFields (Class.forName (classname, true, loader), isFull);
   }
 
-  // new -MH-
-  //! Return a list of string representations of all public fields
+  //! Return an array of string representations of all public fields
   //! of class of the instance @c obj, 
   //! where @c isFull determines 
   //! whether that representation comprises more than the mere name.
@@ -531,18 +521,13 @@
   //!    comprises more than the name (see ::getFields(Class, boolean)).
   //! @return
   //!    see ::getFields(Class, boolean).
-  //! @throws ClassNotFoundException
-  //!    if #loader cannot find @c obj's class.
-  //!    Since all objects are created by reflection
-  //!    from classes loaded by #loader, this shall not happen.
-  public static String getFieldsObj (Object obj, boolean isFull)
-    throws ClassNotFoundException
+  public static String[] getFieldsObj (Object obj, boolean isFull)
   {
     return getFields (obj.getClass (), isFull);
   }
 
 
-  //! Return a list of string representations of all public constructors
+  //! Return an array of string representations of all public constructors
   //! of the given class @c klass.
   //!
   //! This method is based on Class::getConstructors().
@@ -553,37 +538,38 @@
   //! @param klass
   //!    the class under consideration.
   //! @return
-  //!    the list of string representations of the public constructors
-  //!    of the given class @c klass as a string,
-  //!    separated by <code>;</code>.
-  //!    This is the full signature including the modifiers except @c public 
-  //!    the parameter list and the throws-declaration.
-  //!    For class <code>java.math.BigDecimal</code> this is 
-  //!    <code>(String);(double)</code>.
-  private static String getConstructors (Class klass)
+  //!    an array of string representations of the public constructors
+  //!    of the given class @c klass as a string.
+  //!    This is the full signature including the modifiers except @c public,
+  //!    the parameter list and the throws-declaration
+  //!    followed by Octave comment with inheritance information.
+  //!    For class <code>java.math.BigDecimal</code> this has the entries
+  //!    <code>(String)</code> and <code>(double)</code>.
+  private static String[] getConstructors (Class klass)
   {
-    StringBuffer sb = new StringBuffer ();
     Constructor[] constructors = klass.getConstructors ();
     Constructor theConstructor;
+    StringBuffer sb;
+    List res = new ArrayList();
     for (int i = 0; i < constructors.length; i++)
       {
         theConstructor = constructors[i];
-        if (i > 0)
-          {
-            sb.append (';');
-          }
-
+        sb = new StringBuffer ();
+ 
         // append the modifiers except 'public' ...
         appendModifiers(theConstructor, sb);
         // ... and the list of parameters and throwables 
         appendParamsThrwbs(theConstructor, sb);
         // append inheritance information by need
         appendInheritance(klass, theConstructor, sb);
-       }
-    return sb.toString();
+
+        res.add(sb.toString ());
+      }
+
+    return (String[])res.toArray (new String[res.size()]);
   }
 
-  //! Return a list of string representations of public constructors
+  //! Return an array of string representations of the public constructors
   //! of the class with the given class name @c classname
   //! loaded with #loader.
   //!
@@ -596,13 +582,13 @@
   //!    see ::getConstructors(Class).
   //! @throws ClassNotFoundException
   //!    if #loader cannot find a class with name @c classname.
-  public static String getConstructorsCls (String classname)
+  public static String[] getConstructorsCls (String classname)
     throws ClassNotFoundException
   {
     return getConstructors (Class.forName (classname, true, loader));
   }
 
-  //! Return a list of string representations of all of public constructors
+  //! Return an array of string representations of all of public constructors
   //! of the class of the instance @c obj.
   //!
   //! This method is based on ::getConstroctors(Class).
@@ -616,8 +602,8 @@
   //!    if #loader cannot find @c obj's class.
   //!    Since all objects are created by reflection
   //!    from classes loaded by #loader, this shall not happen.
-  public static String getConstructorsObj (Object obj)
-    throws ClassNotFoundException
+  public static String[] getConstructorsObj (Object obj)
+  //throws ClassNotFoundException
   {
     return getConstructors (obj.getClass ());
   }
@@ -1802,4 +1788,5 @@
 
       }
     throw new NumberFormatException("Object cannot be converted to a long.");
-  }}
+  }
+}
