Mercurial > hg > octave-nkf
changeset 15788:26553e685857
merge in changeset b081fbe80174 (separate icons for floating widgets)
author | Torsten <ttl@justmail.de> |
---|---|
date | Fri, 14 Dec 2012 13:24:41 +0100 |
parents | b081fbe80174 (current diff) 2a2c090fdef8 (diff) |
children | 8056d0e36bef |
files | scripts/java/javamethods.m |
diffstat | 9 files changed, 109 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-class.cc +++ b/libinterp/octave-value/ov-class.cc @@ -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; }
--- a/scripts/deprecated/java_get.m +++ b/scripts/deprecated/java_get.m @@ -1,4 +1,4 @@ -## Copyright (C) 1995-2012 Kurt Hornik +## Copyright (C) 2012 Rik Wehbring ## ## This file is part of Octave. ##
--- a/scripts/deprecated/java_new.m +++ b/scripts/deprecated/java_new.m @@ -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
--- a/scripts/deprecated/java_set.m +++ b/scripts/deprecated/java_set.m @@ -1,4 +1,4 @@ -## Copyright (C) 1995-2012 Kurt Hornik +## Copyright (C) 2012 Rik Wehbring ## ## This file is part of Octave. ##
rename from scripts/java/javamethods.m rename to scripts/deprecated/javamethods.m --- a/scripts/java/javamethods.m +++ b/scripts/deprecated/javamethods.m @@ -23,10 +23,17 @@ ## 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} +## @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 ();
--- a/scripts/deprecated/module.mk +++ b/scripts/deprecated/module.mk @@ -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 \
new file mode 100644 --- /dev/null +++ b/scripts/general/methods.m @@ -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 +## <http://www.gnu.org/licenses/>. + +## -*- 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{:}])); +