[vala/staging: 10/22] libvaladoc: Clean up Api.TypeReference constructor



commit 8f188107c19eb04670ad65d3b21876c271eadc0a
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Jun 12 15:41:41 2018 +0200

    libvaladoc: Clean up Api.TypeReference constructor

 libvaladoc/api/typereference.vala | 99 +++++++++++++++++++++++++++++++++++++--
 valadoc/treebuilder.vala          | 97 --------------------------------------
 2 files changed, 96 insertions(+), 100 deletions(-)
---
diff --git a/libvaladoc/api/typereference.vala b/libvaladoc/api/typereference.vala
index 884b721bc..47bf5efc4 100644
--- a/libvaladoc/api/typereference.vala
+++ b/libvaladoc/api/typereference.vala
@@ -31,19 +31,112 @@ public class Valadoc.Api.TypeReference : Item {
        private string? dbus_type_signature;
        private Ownership ownership;
 
-       public TypeReference (Item parent, Ownership ownership, bool pass_ownership, bool is_dynamic,
+       public TypeReference (Item parent, bool is_dynamic,
                                                  bool is_nullable, string? dbus_type_signature, 
Vala.DataType? data)
        {
                base (data);
 
                this.dbus_type_signature = dbus_type_signature;
-               this.pass_ownership = pass_ownership;
+               this.pass_ownership = type_reference_pass_ownership (data);
                this.is_nullable = is_nullable;
                this.is_dynamic = is_dynamic;
-               this.ownership = ownership;
+               this.ownership = get_type_reference_ownership (data);
                this.parent = parent;
        }
 
+       bool is_reference_counting (Vala.TypeSymbol sym) {
+               return Vala.is_reference_counting (sym);
+       }
+
+       bool type_reference_pass_ownership (Vala.DataType? element) {
+               if (element == null) {
+                       return false;
+               }
+
+               weak Vala.CodeNode? node = element.parent_node;
+               if (node == null) {
+                       return false;
+               }
+               if (node is Vala.Parameter) {
+                       return (((Vala.Parameter)node).direction == Vala.ParameterDirection.IN &&
+                               ((Vala.Parameter)node).variable_type.value_owned);
+               }
+               if (node is Vala.Property) {
+                       return ((Vala.Property)node).property_type.value_owned;
+               }
+
+               return false;
+       }
+
+       bool is_type_reference_unowned (Vala.DataType? element) {
+                       if (element == null) {
+                               return false;
+                       }
+
+                       // non ref counted types are weak, not unowned
+                       if (element.data_type is Vala.TypeSymbol
+                               && is_reference_counting ((Vala.TypeSymbol) element.data_type) == true)
+                       {
+                               return false;
+                       }
+
+                       // FormalParameters are weak by default
+                       return (element.parent_node is Vala.Parameter == false)
+                               ? element.is_weak ()
+                               : false;
+       }
+
+       bool is_type_reference_owned (Vala.DataType? element) {
+               if (element == null) {
+                       return false;
+               }
+
+               weak Vala.CodeNode parent = element.parent_node;
+
+               // parameter:
+               if (parent is Vala.Parameter) {
+                       if (((Vala.Parameter)parent).direction != Vala.ParameterDirection.IN) {
+                               return false;
+                       }
+                       return ((Vala.Parameter)parent).variable_type.value_owned;
+               }
+
+               return false;
+       }
+
+       bool is_type_reference_weak (Vala.DataType? element) {
+               if (element == null) {
+                       return false;
+               }
+
+               // non ref counted types are unowned, not weak
+               if (element.data_type is Vala.TypeSymbol
+                       && is_reference_counting ((Vala.TypeSymbol) element.data_type) == false)
+               {
+                       return false;
+               }
+
+               // arrays are unowned, not weak
+               if (element is Vala.ArrayType) {
+                       return false;
+               }
+
+               // FormalParameters are weak by default
+               return (element.parent_node is Vala.Parameter == false)? element.is_weak () : false;
+       }
+
+       Ownership get_type_reference_ownership (Vala.DataType? element) {
+               if (is_type_reference_owned (element)) {
+                       return Ownership.OWNED;
+               } else if (is_type_reference_weak (element)) {
+                       return Ownership.WEAK;
+               } else if (is_type_reference_unowned (element)) {
+                       return Ownership.UNOWNED;
+               }
+
+               return Ownership.DEFAULT;
+       }
+
        /**
         * Returns a copy of the list of generic type arguments.
         *
diff --git a/valadoc/treebuilder.vala b/valadoc/treebuilder.vala
index 7c5d4d112..b0ef026e9 100644
--- a/valadoc/treebuilder.vala
+++ b/valadoc/treebuilder.vala
@@ -172,13 +172,9 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
                        && !(vtyperef is Vala.PointerType);
                string? signature = (vtyperef != null
                        && vtyperef.data_type != null)? Vala.GVariantModule.get_dbus_signature 
(vtyperef.data_type) : null;
-               bool pass_ownership = type_reference_pass_ownership (vtyperef);
-               Ownership ownership = get_type_reference_ownership (vtyperef);
                bool is_dynamic = vtyperef != null && vtyperef.is_dynamic;
 
                TypeReference type_ref = new TypeReference (parent,
-                                                                                                       
ownership,
-                                                                                                       
pass_ownership,
                                                                                                        
is_dynamic,
                                                                                                        
is_nullable,
                                                                                                        
signature,
@@ -223,10 +219,6 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
                return Vala.get_ccode_type_id (node);
        }
 
-       private bool is_reference_counting (Vala.TypeSymbol sym) {
-               return Vala.is_reference_counting (sym);
-       }
-
        private string? get_ref_function (Vala.Class sym) {
                return Vala.get_ccode_ref_function (sym);
        }
@@ -496,95 +488,6 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
                return meta_data.get_namespace ((Vala.Namespace) namespace_symbol, file);
        }
 
-       private bool type_reference_pass_ownership (Vala.DataType? element) {
-               if (element == null) {
-                       return false;
-               }
-
-               weak Vala.CodeNode? node = element.parent_node;
-               if (node == null) {
-                       return false;
-               }
-               if (node is Vala.Parameter) {
-                       return (((Vala.Parameter)node).direction == Vala.ParameterDirection.IN &&
-                               ((Vala.Parameter)node).variable_type.value_owned);
-               }
-               if (node is Vala.Property) {
-                       return ((Vala.Property)node).property_type.value_owned;
-               }
-
-               return false;
-       }
-
-       private bool is_type_reference_unowned (Vala.DataType? element) {
-                       if (element == null) {
-                               return false;
-                       }
-
-                       // non ref counted types are weak, not unowned
-                       if (element.data_type is Vala.TypeSymbol
-                               && is_reference_counting ((Vala.TypeSymbol) element.data_type) == true)
-                       {
-                               return false;
-                       }
-
-                       // FormalParameters are weak by default
-                       return (element.parent_node is Vala.Parameter == false)
-                               ? element.is_weak ()
-                               : false;
-       }
-
-       private bool is_type_reference_owned (Vala.DataType? element) {
-               if (element == null) {
-                       return false;
-               }
-
-               weak Vala.CodeNode parent = element.parent_node;
-
-               // parameter:
-               if (parent is Vala.Parameter) {
-                       if (((Vala.Parameter)parent).direction != Vala.ParameterDirection.IN) {
-                               return false;
-                       }
-                       return ((Vala.Parameter)parent).variable_type.value_owned;
-               }
-
-               return false;
-       }
-
-       private bool is_type_reference_weak (Vala.DataType? element) {
-               if (element == null) {
-                       return false;
-               }
-
-               // non ref counted types are unowned, not weak
-               if (element.data_type is Vala.TypeSymbol
-                       && is_reference_counting ((Vala.TypeSymbol) element.data_type) == false)
-               {
-                       return false;
-               }
-
-               // arrays are unowned, not weak
-               if (element is Vala.ArrayType) {
-                       return false;
-               }
-
-               // FormalParameters are weak by default
-               return (element.parent_node is Vala.Parameter == false)? element.is_weak () : false;
-       }
-
-       private Ownership get_type_reference_ownership (Vala.DataType? element) {
-               if (is_type_reference_owned (element)) {
-                       return Ownership.OWNED;
-               } else if (is_type_reference_weak (element)) {
-                       return Ownership.WEAK;
-               } else if (is_type_reference_unowned (element)) {
-                       return Ownership.UNOWNED;
-               }
-
-               return Ownership.DEFAULT;
-       }
-
        private Ownership get_property_ownership (Vala.PropertyAccessor element) {
                if (element.value_type.value_owned) {
                        return Ownership.OWNED;


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