Mercurial > octave
changeset 26761:8554becefe1b
handle -full argument for methods function (bug #55487)
* methods.m: Accept "-full" argument. Currently only works for Java
methods. Update tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 21 Feb 2019 18:41:15 +0000 |
parents | c97a65af7c4b |
children | c4e53014f248 |
files | scripts/miscellaneous/methods.m |
diffstat | 1 files changed, 20 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/miscellaneous/methods.m Thu Feb 21 15:08:27 2019 +0100 +++ b/scripts/miscellaneous/methods.m Thu Feb 21 18:41:15 2019 +0000 @@ -32,12 +32,15 @@ ## @seealso{fieldnames} ## @end deftypefn -function mtds = methods (obj) +function mtds = methods (obj, opt) - if (nargin != 1) + if (nargin < 1 || nargin > 2) print_usage (); endif + showsigs = (nargin > 1 && ischar (opt) && strcmp (opt, "-full")); + havesigs = false; + if (isobject (obj)) ## Call internal C++ function for Octave objects mtds_list = __methods__ (obj); @@ -48,6 +51,7 @@ if (isempty (mtds_list)) mtds_str = javaMethod ("getMethods", "org.octave.ClassHelper", obj); mtds_list = ostrsplit (mtds_str, ';'); + havesigs = true; endif elseif (isjava (obj)) ## FIXME: Function prototype accepts java obj, but doesn't work if obj @@ -59,8 +63,14 @@ mtds_str = javaMethod ("getMethods", "org.octave.ClassHelper", obj); end_try_catch mtds_list = strsplit (mtds_str, ';'); + havesigs = true; else - error ("methods: Invalid input argument"); + error ("methods: invalid input argument"); + endif + + if (havesigs && ! showsigs) + mtds_list = regexprep (mtds_list, '^(?:[^ ]+ )+(\w+)\(.*$', '$1'); + mtds_list = unique (mtds_list); endif if (nargout == 0) @@ -81,8 +91,14 @@ ## test Java classname %!testif HAVE_JAVA; usejava ("jvm") +%! mtds = methods ("java.lang.Double", "-full"); +%! search = strfind (mtds, "java.lang.Double valueOf"); +%! assert (! isempty ([search{:}])); + +## test Java classname +%!testif HAVE_JAVA; usejava ("jvm") %! mtds = methods ("java.lang.Double"); -%! search = strfind (mtds, "java.lang.Double valueOf"); +%! search = strfind (mtds, "valueOf"); %! assert (! isempty ([search{:}])); ## classdef