[vala/staging] valadoc: Acknowledge possible properties in structs



commit ac94a35ec4309e35b2bb0b7eb90ddf84d1de34d6
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Nov 21 09:10:09 2017 +0100

    valadoc: Acknowledge possible properties in structs
    
    https://bugzilla.gnome.org/show_bug.cgi?id=784705

 libvaladoc/ctyperesolver.vala               |    9 +-
 valadoc/tests/drivers/api-test.data.vapi    |    3 +
 valadoc/tests/drivers/generic-api-test.vala |  159 ++++++++++++++++++++++++++-
 3 files changed, 168 insertions(+), 3 deletions(-)
---
diff --git a/libvaladoc/ctyperesolver.vala b/libvaladoc/ctyperesolver.vala
index 2909df6..e6444e0 100644
--- a/libvaladoc/ctyperesolver.vala
+++ b/libvaladoc/ctyperesolver.vala
@@ -259,8 +259,8 @@ public class Valadoc.CTypeResolver : Visitor {
                register_symbol (parent_cname+":"+cname, item);
 
 
-               Vala.Collection<Interface> interfaces = null;
-               Vala.Collection<Class> classes = null;
+               Vala.Collection<Interface> interfaces;
+               Vala.Collection<Class> classes;
 
                if (item.parent is Interface) {
                        interfaces = ((Api.Interface) item.parent).get_known_related_interfaces ();
@@ -268,6 +268,11 @@ public class Valadoc.CTypeResolver : Visitor {
                } else if (item.parent is Class) {
                        interfaces = ((Api.Class) item.parent).get_known_derived_interfaces ();
                        classes = ((Api.Class) item.parent).get_known_child_classes ();
+               } else if (item.parent is Struct) {
+                       // Properties are allowed here, similar to compact classes
+                       return;
+               } else {
+                       assert_not_reached ();
                }
 
                foreach (Interface iface in interfaces) {
diff --git a/valadoc/tests/drivers/api-test.data.vapi b/valadoc/tests/drivers/api-test.data.vapi
index 4a32365..f0b27ac 100644
--- a/valadoc/tests/drivers/api-test.data.vapi
+++ b/valadoc/tests/drivers/api-test.data.vapi
@@ -85,6 +85,9 @@ public struct TestStructGlobal {
        public void method ();
        public static void static_method ();
        public const int constant;
+       public int property1 { get; set; }
+       public int property2 { get; }
+       public int property3 { owned get; set; }
 }
 
 
diff --git a/valadoc/tests/drivers/generic-api-test.vala b/valadoc/tests/drivers/generic-api-test.vala
index 7591205..48c54b5 100644
--- a/valadoc/tests/drivers/generic-api-test.vala
+++ b/valadoc/tests/drivers/generic-api-test.vala
@@ -1386,6 +1386,164 @@ public static void test_struct_global (Api.Struct? stru, Api.Package pkg, Api.Na
        assert (field2 == true);
 
 
+       Vala.List<Api.Node> properties = stru.get_children_by_type (Api.NodeType.PROPERTY, false);
+       bool prop1 = false;
+       bool prop2 = false;
+       bool prop3 = false;
+
+       foreach (Api.Node node in properties) {
+               Api.Property property = node as Api.Property;
+               assert (property != null);
+
+               switch (property.name) {
+               case "property1":
+                       assert (property.get_cname () == "property1");
+                       assert (property.property_type != null);
+                       assert (property.is_virtual == false);
+                       assert (property.is_abstract == false);
+                       assert (property.is_override == false);
+                       assert (property.is_dbus_visible == true);
+                       assert (property.setter != null);
+                       assert (property.getter != null);
+                       assert (property.base_property == null);
+                       // (.Symbol check)
+                       assert (property.is_deprecated == false);
+                       assert (property.accessibility == Api.SymbolAccessibility.PUBLIC);
+                       // (.Node)
+                       assert (property.get_full_name () == "TestStructGlobal.property1");
+                       assert (property.get_filename () == "api-test.data.vapi");
+                       assert (property.nspace == global_ns);
+                       assert (property.package == pkg);
+
+
+                       assert (property.getter.get_cname () == "test_struct_global_get_property1");
+                       assert (property.getter.is_construct == false);
+                       assert (property.getter.is_set == false);
+                       assert (property.getter.is_get == true);
+                       assert (property.getter.is_owned == false);
+                       // (.Symbol check)
+                       assert (property.getter.is_deprecated == false);
+                       assert (property.getter.accessibility == Api.SymbolAccessibility.PUBLIC);
+                       // (.Node)
+                       //assert (property.getter.get_full_name () == "TestInterfaceGlobal.property2");
+                       assert (property.getter.get_filename () == "api-test.data.vapi");
+                       assert (property.getter.nspace == global_ns);
+                       assert (property.getter.package == pkg);
+
+
+                       assert (property.setter.get_cname () == "test_struct_global_set_property1");
+                       assert (property.setter.is_construct == false);
+                       assert (property.setter.is_get == false);
+                       assert (property.setter.is_set == true);
+                       assert (property.setter.is_owned == false);
+                       // (.Symbol check)
+                       assert (property.setter.is_deprecated == false);
+                       assert (property.setter.accessibility == Api.SymbolAccessibility.PUBLIC);
+                       // (.Node)
+                       //assert (property.getter.get_full_name () == "TestInterfaceGlobal.property2");
+                       assert (property.setter.get_filename () == "api-test.data.vapi");
+                       assert (property.setter.nspace == global_ns);
+                       assert (property.setter.package == pkg);
+
+                       prop1 = true;
+                       break;
+
+               case "property2":
+                       assert (property.get_cname () == "property2");
+                       assert (property.property_type != null);
+                       assert (property.is_virtual == false);
+                       assert (property.is_abstract == false);
+                       assert (property.is_override == false);
+                       assert (property.is_dbus_visible == true);
+                       assert (property.setter == null);
+                       assert (property.getter != null);
+                       assert (property.base_property == null);
+                       // (.Symbol check)
+                       assert (property.is_deprecated == false);
+                       assert (property.accessibility == Api.SymbolAccessibility.PUBLIC);
+                       // (.Node)
+                       assert (property.get_full_name () == "TestStructGlobal.property2");
+                       assert (property.get_filename () == "api-test.data.vapi");
+                       assert (property.nspace == global_ns);
+                       assert (property.package == pkg);
+
+                       assert (property.getter.get_cname () == "test_struct_global_get_property2");
+                       assert (property.getter.is_construct == false);
+                       assert (property.getter.is_set == false);
+                       assert (property.getter.is_get == true);
+                       assert (property.getter.is_owned == false);
+                       // (.Symbol check)
+                       assert (property.getter.is_deprecated == false);
+                       assert (property.getter.accessibility == Api.SymbolAccessibility.PUBLIC);
+                       // (.Node)
+                       //assert (property.getter.get_full_name () == "TestInterfaceGlobal.property2");
+                       assert (property.getter.get_filename () == "api-test.data.vapi");
+                       assert (property.getter.nspace == global_ns);
+                       assert (property.getter.package == pkg);
+
+                       prop2 = true;
+                       break;
+
+               case "property3":
+                       assert (property.get_cname () == "property3");
+                       assert (property.property_type != null);
+                       assert (property.is_virtual == false);
+                       assert (property.is_abstract == false);
+                       assert (property.is_override == false);
+                       assert (property.is_dbus_visible == true);
+                       assert (property.setter != null);
+                       assert (property.getter != null);
+                       assert (property.base_property == null);
+                       // (.Symbol check)
+                       assert (property.is_deprecated == false);
+                       assert (property.accessibility == Api.SymbolAccessibility.PUBLIC);
+                       // (.Node)
+                       assert (property.get_full_name () == "TestStructGlobal.property3");
+                       assert (property.get_filename () == "api-test.data.vapi");
+                       assert (property.nspace == global_ns);
+                       assert (property.package == pkg);
+
+                       assert (property.getter.get_cname () == "test_struct_global_get_property3");
+                       assert (property.getter.is_construct == false);
+                       assert (property.getter.is_set == false);
+                       assert (property.getter.is_get == true);
+                       assert (property.getter.is_owned == true);
+                       // (.Symbol check)
+                       assert (property.getter.is_deprecated == false);
+                       assert (property.getter.accessibility == Api.SymbolAccessibility.PUBLIC);
+                       // (.Node)
+                       //assert (property.getter.get_full_name () == "TestInterfaceGlobal.property3");
+                       assert (property.getter.get_filename () == "api-test.data.vapi");
+                       assert (property.getter.nspace == global_ns);
+                       assert (property.getter.package == pkg);
+
+
+                       assert (property.setter.get_cname () == "test_struct_global_set_property3");
+                       assert (property.setter.is_construct == false);
+                       assert (property.setter.is_get == false);
+                       assert (property.setter.is_set == true);
+                       assert (property.setter.is_owned == false);
+                       // (.Symbol check)
+                       assert (property.setter.is_deprecated == false);
+                       assert (property.setter.accessibility == Api.SymbolAccessibility.PUBLIC);
+                       // (.Node)
+                       //assert (property.getter.get_full_name () == "TestInterfaceGlobal.property3");
+                       assert (property.setter.get_filename () == "api-test.data.vapi");
+                       assert (property.setter.nspace == global_ns);
+                       assert (property.setter.package == pkg);
+
+
+                       prop3 = true;
+                       break;
+
+               default:
+                       assert_not_reached ();
+               }
+       }
+       assert (prop1);
+       assert (prop2);
+       assert (prop3);
+
 
        Api.NodeType[] forbidden = {
                        Api.NodeType.CLASS,
@@ -1398,7 +1556,6 @@ public static void test_struct_global (Api.Struct? stru, Api.Package pkg, Api.Na
                        Api.NodeType.INTERFACE,
                        Api.NodeType.NAMESPACE,
                        Api.NodeType.PACKAGE,
-                       Api.NodeType.PROPERTY,
                        Api.NodeType.PROPERTY_ACCESSOR,
                        Api.NodeType.SIGNAL,
                        Api.NodeType.STRUCT,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]