# HG changeset patch # User Torsten # Date 1355487881 -3600 # Node ID 26553e6858574e213cc3ffcc9a4b59b5ffbfbcbe # Parent b081fbe801742ec3b6f78f442981ecf3efd13646# Parent 2a2c090fdef8ff5444183e181029ac7050453bd7 merge in changeset b081fbe80174 (separate icons for floating widgets) diff -r b081fbe80174 -r 26553e685857 libinterp/octave-value/ov-class.cc --- a/libinterp/octave-value/ov-class.cc Fri Dec 14 13:18:14 2012 +0100 +++ b/libinterp/octave-value/ov-class.cc Fri Dec 14 13:24:41 2012 +0100 @@ -2103,47 +2103,33 @@ return retval; } -DEFUN (methods, args, nargout, +DEFUN (__methods__, args, , "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} methods (@var{x})\n\ -@deftypefnx {Built-in Function} {} methods (\"classname\")\n\ -Return a cell array containing the names of the methods for the\n\ -object @var{x} or the named class.\n\ +@deftypefn {Built-in Function} {} __methods__ (@var{x})\n\ +@deftypefnx {Built-in Function} {} __methods__ (\"classname\")\n\ +Internal function.\n\ +\n\ +Implements @code{methods} for Octave class objects and classnames.\n\ +@seealso{methods}\n\ @end deftypefn") { octave_value retval; - if (args.length () == 1) - { - octave_value arg = args(0); - - std::string class_name; + // Input validation has already been done in methods.m. + octave_value arg = args(0); - if (arg.is_object ()) - class_name = arg.class_name (); - else if (arg.is_string ()) - class_name = arg.string_value (); - else - error ("methods: expecting object or class name as argument"); + std::string class_name; - if (! error_state) - { - string_vector sv = load_path::methods (class_name); - - if (nargout == 0) - { - octave_stdout << "Methods for class " << class_name << ":\n\n"; + if (arg.is_object ()) + class_name = arg.class_name (); + else if (arg.is_string ()) + class_name = arg.string_value (); - sv.list_in_columns (octave_stdout); - - octave_stdout << std::endl; - } - else - retval = Cell (sv); - } + if (! error_state) + { + string_vector sv = load_path::methods (class_name); + retval = Cell (sv); } - else - print_usage (); return retval; } diff -r b081fbe80174 -r 26553e685857 scripts/deprecated/java_get.m --- a/scripts/deprecated/java_get.m Fri Dec 14 13:18:14 2012 +0100 +++ b/scripts/deprecated/java_get.m Fri Dec 14 13:24:41 2012 +0100 @@ -1,4 +1,4 @@ -## Copyright (C) 1995-2012 Kurt Hornik +## Copyright (C) 2012 Rik Wehbring ## ## This file is part of Octave. ## diff -r b081fbe80174 -r 26553e685857 scripts/deprecated/java_new.m --- a/scripts/deprecated/java_new.m Fri Dec 14 13:18:14 2012 +0100 +++ b/scripts/deprecated/java_new.m Fri Dec 14 13:24:41 2012 +0100 @@ -1,4 +1,4 @@ -## Copyright (C) 1995-2012 Kurt Hornik +## Copyright (C) 2012 Rik Wehbring ## ## This file is part of Octave. ## @@ -41,7 +41,7 @@ "java_new is obsolete and will be removed from a future version of Octave; please use javaObject instead"); endif - if (nargin < 2) + if (nargin < 1) print_usage (); endif diff -r b081fbe80174 -r 26553e685857 scripts/deprecated/java_set.m --- a/scripts/deprecated/java_set.m Fri Dec 14 13:18:14 2012 +0100 +++ b/scripts/deprecated/java_set.m Fri Dec 14 13:24:41 2012 +0100 @@ -1,4 +1,4 @@ -## Copyright (C) 1995-2012 Kurt Hornik +## Copyright (C) 2012 Rik Wehbring ## ## This file is part of Octave. ## diff -r b081fbe80174 -r 26553e685857 scripts/deprecated/javamethods.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/deprecated/javamethods.m Fri Dec 14 13:24:41 2012 +0100 @@ -0,0 +1,54 @@ +## Copyright (C) 2007 Michael Goffioul +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} javamethods (@var{javaobj}) +## @deftypefnx {Function File} {} javamethods ("@var{classname}") +## @deftypefnx {Function File} {@var{mtd_names} =} javamethods (@dots{}) +## Return the methods of a Java object or Java class in the form of a cell +## array of strings. If no output is requested, print the result to the +## standard output. +## @seealso{methods, javafields, java_invoke, javaMethod, javaObject} +## @end deftypefn + +function mtd_names = javamethods (classname) + + persistent warned = false; + if (! warned) + warned = true; + warning ("Octave:deprecated-function", + "javamethods is obsolete and will be removed from a future version of Octave, please use methods instead"); + endif + + if (nargin != 1) + print_usage (); + endif + + cls_methods = java_invoke ("org.octave.ClassHelper", "getMethods", classname); + method_list = strsplit (cls_methods, ';'); + + if (nargout == 0) + if (! isempty (method_list)) + disp (method_list); + endif + else + mtd_names = cellstr (method_list); + endif + +endfunction + diff -r b081fbe80174 -r 26553e685857 scripts/deprecated/module.mk --- a/scripts/deprecated/module.mk Fri Dec 14 13:18:14 2012 +0100 +++ b/scripts/deprecated/module.mk Fri Dec 14 13:24:41 2012 +0100 @@ -7,10 +7,11 @@ deprecated/cut.m \ deprecated/error_text.m \ deprecated/isstr.m \ - deprecated/javafields.m \ deprecated/java_get.m \ deprecated/java_new.m \ deprecated/java_set.m \ + deprecated/javafields.m \ + deprecated/javamethods.m \ deprecated/polyderiv.m \ deprecated/setstr.m \ deprecated/shell_cmd.m \ diff -r b081fbe80174 -r 26553e685857 scripts/general/methods.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/general/methods.m Fri Dec 14 13:24:41 2012 +0100 @@ -0,0 +1,76 @@ +## Copyright (C) 2012 Rik Wehbring +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Built-in Function} {} methods (@var{obj}) +## @deftypefnx {Built-in Function} {} methods ("@var{classname}") +## @deftypefnx {Built-in Function} {@var{mtds} =} methods (@dots{}) +## +## Return a cell array containing the names of the methods for the +## object @var{obj} or the named class @var{classname}. +## @var{obj} may be an Octave class object or a Java object. +## +## @seealso{fieldnames} +## @end deftypefn + +function mtds = methods (obj) + + if (nargin != 1) + print_usage (); + endif + + if (isobject (obj)) + ## Call internal C++ function for Octave objects + mtds_list = __methods__ (obj); + elseif (ischar (obj)) + ## Could be a classname for an Octave class or Java class. + ## Try Octave class first. + mtds_list = __methods__ (obj); + if (isempty (mtds_list)) + mtds_str = java_invoke ("org.octave.ClassHelper", "getMethods", obj); + mtds_list = strsplit (mtds_str, ';'); + endif + elseif (isjava (obj)) + mtds_str = java_invoke ("org.octave.ClassHelper", "getMethods", obj); + mtds_list = strsplit (mtds_str, ';'); + else + error ("methods: Invalid input argument"); + endif + + if (nargout == 0) + classname = ifelse (ischar (obj), obj, class (obj)); + printf ("Methods for class %s:\n", classname); + disp (list_in_columns (mtds_list)); + else + mtds = mtds_list; + endif + +endfunction + + +## test Octave classname +%!test +%! mtds = methods ("ftp"); +%! assert (mtds{1}, "ascii"); + +## test Java classname +%!testif HAVE_JAVA +%! mtds = methods ("java.lang.Double"); +%! search = strfind (mtds, "java.lang.Double valueOf"); +%! assert (! isempty ([search{:}])); + diff -r b081fbe80174 -r 26553e685857 scripts/general/module.mk --- a/scripts/general/module.mk Fri Dec 14 13:18:14 2012 +0100 +++ b/scripts/general/module.mk Fri Dec 14 13:24:41 2012 +0100 @@ -53,6 +53,7 @@ general/isvector.m \ general/loadobj.m \ general/logspace.m \ + general/methods.m \ general/nargchk.m \ general/narginchk.m \ general/nargoutchk.m \ diff -r b081fbe80174 -r 26553e685857 scripts/java/javamethods.m --- a/scripts/java/javamethods.m Fri Dec 14 13:18:14 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -## Copyright (C) 2007 Michael Goffioul -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {} javamethods (@var{javaobj}) -## @deftypefnx {Function File} {} javamethods ("@var{classname}") -## @deftypefnx {Function File} {@var{mtd_names} =} javamethods (@dots{}) -## Return the methods of a Java object or Java class in the form of a cell -## array of strings. If no output is requested, print the result to the -## standard output. -## @seealso{javafields, java_invoke, javaMethod, javaObject} -## @end deftypefn - -function mtd_names = javamethods (classname) - - if (nargin != 1) - print_usage (); - endif - - cls_methods = java_invoke ("org.octave.ClassHelper", "getMethods", classname); - method_list = strsplit (cls_methods, ';'); - - if (nargout == 0) - if (! isempty (method_list)) - disp (method_list); - endif - else - mtd_names = cellstr (method_list); - endif - -endfunction - diff -r b081fbe80174 -r 26553e685857 scripts/java/module.mk --- a/scripts/java/module.mk Fri Dec 14 13:18:14 2012 +0100 +++ b/scripts/java/module.mk Fri Dec 14 13:24:41 2012 +0100 @@ -10,7 +10,6 @@ java/javaaddpath.m \ java/javaclasspath.m \ java/javamem.m \ - java/javamethods.m \ java/javarmpath.m \ java/listdlg.m \ java/msgbox.m \