changeset 27186:b15b71bcd679

properties function: omit hidden properties (bug #55766) * ov-classdef.cc (Fproperties): Also skip hidden properties. * test/classdef/class_bug55766.m: New file. * classdef.tst: New test. * test/classdef/module.mk: Update.
author John W. Eaton <jwe@octave.org>
date Fri, 14 Jun 2019 12:52:27 -0500
parents 04889e45f54e
children 42efd1e986c7
files libinterp/octave-value/ov-classdef.cc test/classdef/class_bug55766.m test/classdef/classdef.tst test/classdef/module.mk
diffstat 4 files changed, 48 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-classdef.cc	Fri Jun 14 11:14:01 2019 -0500
+++ b/libinterp/octave-value/ov-classdef.cc	Fri Jun 14 12:52:27 2019 -0500
@@ -524,13 +524,14 @@
 @deftypefn  {} {} properties (@var{class_name})
 @deftypefnx {} {} properties (@var{obj})
 @deftypefnx {} {@var{plist} =} properties (@dots{})
-Return or display the public properties for the named class @var{class_name} or
-classdef object @var{obj}.
+Return or display the public properties for the named class
+@var{class_name} or classdef object @var{obj}.
 
-If an output value is requested, return the list of property names in a cell
-array.
+If an output value is requested, return the list of property names in a
+cell array.
 
-Programming Note: Property names are returned if the @code{GetAccess} attribute is public and if the @code{Hidden} attribute is false.
+Programming Note: Property names are returned if the @code{GetAccess}
+attribute is public and if the @code{Hidden} attribute is false.
 @seealso{methods}
 @end deftypefn */)
 {
@@ -561,13 +562,20 @@
 
   for (const auto& pname_prop : property_map)
     {
-      std::string nm = pname_prop.second.get_name ();
+      const octave::cdef_property& prop = pname_prop.second;
 
-      octave_value acc = pname_prop.second.get ("GetAccess");
+      std::string nm = prop.get_name ();
+
+      octave_value acc = prop.get ("GetAccess");
 
       if (! acc.is_string () || acc.string_value () != "public")
         continue;
 
+      octave_value hid = prop.get ("Hidden");
+
+      if (hid.bool_value ())
+        continue;
+
       property_names.push_back (nm);
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/classdef/class_bug55766.m	Fri Jun 14 12:52:27 2019 -0500
@@ -0,0 +1,27 @@
+classdef class_bug55766
+
+  properties
+    testprop = 0;
+  end
+
+  properties (Access = public)
+    publictestprop = 0;
+  end
+
+  properties (Access = protected)
+    protectedtestprop = 0;
+  end
+
+  properties (Hidden)
+    hiddentestprop = 0;
+  end
+
+  properties (Hidden = true)
+    anotherhiddentestprop = 0;
+  end
+
+  properties (Hidden = false)
+    notahiddentestprop = 0;
+  end
+
+end
--- a/test/classdef/classdef.tst	Fri Jun 14 11:14:01 2019 -0500
+++ b/test/classdef/classdef.tst	Fri Jun 14 12:52:27 2019 -0500
@@ -193,3 +193,8 @@
 %! B = class_bug52614B ();
 %! assert (B.a, 1);
 %! assert (B.b, 2);
+
+%!test <*55766>
+%! x = class_bug55766 ();
+%! props = {"notahiddentestprop"; "publictestprop"; "testprop"};
+%! assert (properties (x), props);
--- a/test/classdef/module.mk	Fri Jun 14 11:14:01 2019 -0500
+++ b/test/classdef/module.mk	Fri Jun 14 12:52:27 2019 -0500
@@ -1,6 +1,7 @@
 classdef_TEST_FILES = \
   %reldir%/class_bug52614A.m \
   %reldir%/class_bug52614B.m \
+  %reldir%/class_bug55766.m \
   %reldir%/classdef.tst \
   %reldir%/foo_method_changes_property_size.m \
   %reldir%/foo_static_method_constant_property.m \