@@ -69,20 +69,9 @@ def read_object_defs(self):
69
69
abstract_objects = {}
70
70
for object in doc ["objects" ]:
71
71
if "abstract" in object :
72
- abstract_objects [object ["object" ]] = object
72
+ self . abstract_objects [object ["object" ]] = object
73
73
74
74
for object in doc ["objects" ]:
75
- if not "class" in object and not "parent" in object :
76
- self ._map_custom_class (object , yaml_mappings )
77
-
78
- elif "parent" in object :
79
- # Children are added to self.objects during the children->abstract parents traversal.
80
- pos_constr = self ._get_pos_constr (object )
81
- named_constr = self ._get_named_constr (object )
82
- props = self ._get_props (object )
83
- self ._traverse_parents (object , object , pos_constr , named_constr , props , abstract_objects )
84
- continue
85
-
86
75
self ._print_obj (object )
87
76
self .objects .append (self ._convert_object (object ))
88
77
@@ -105,10 +94,10 @@ def _map_custom_class(self, obj, mappings):
105
94
else :
106
95
self .logger .warning ("No matching type found for object %s" % obj )
107
96
108
- def _traverse_parents (self , leaf , child , pos_constr ,
109
- named_constr , props , abstract_objects ):
97
+ def _convert_child_object (self , leaf , child , pos_constr ,
98
+ named_constr , props ):
110
99
111
- parent = abstract_objects [child ["parent" ]]
100
+ parent = self . abstract_objects [child ["parent" ]]
112
101
113
102
# At this point we only build up the lists of parameters but we don't create
114
103
# the object yet because the current parent object may still have its
@@ -148,20 +137,19 @@ def _traverse_parents(self, leaf, child, pos_constr,
148
137
props .append (parent_prop )
149
138
150
139
if "parent" in parent :
151
- self ._traverse_parents (leaf , parent , pos_constr , named_constr , props , abstract_objects )
140
+ # Continue traversing up the parent objects
141
+ return self ._convert_child_object (leaf , parent , pos_constr , named_constr , props )
152
142
else :
153
143
# Now we know we can create an object out of all the accumulated values.
154
-
144
+
155
145
# The object's class is its topmost parent's class.
156
146
class_ = parent ["class" ]
157
147
id , factory , lazy_init , abstract , parent , scope_ = self ._get_basic_object_data (leaf , class_ )
158
148
159
149
c = self ._create_object (id , factory , lazy_init , abstract , parent ,
160
150
scope_ , pos_constr , named_constr , props )
161
151
162
- self .objects .append (c )
163
-
164
- return parent
152
+ return c
165
153
166
154
def _get_pos_constr (self , object ):
167
155
""" Returns a list of all positional constructor arguments of an object.
@@ -225,20 +213,25 @@ def _convert_object(self, object, prefix=""):
225
213
object ["object" ] = prefix + "." + object ["object" ]
226
214
else :
227
215
object ["object" ] = prefix + ".<anonymous>"
228
-
229
- id , factory , lazy_init , abstract , parent , scope_ = self ._get_basic_object_data (object , object .get ("class" ))
230
-
216
+
217
+ if not "class" in object and "parent" not in object :
218
+ self ._map_custom_class (object , yaml_mappings )
219
+
231
220
pos_constr = self ._get_pos_constr (object )
232
221
named_constr = self ._get_named_constr (object )
233
222
props = self ._get_props (object )
223
+
224
+ if "parent" in object :
225
+ return self ._convert_child_object (object , object , pos_constr , named_constr , props )
226
+ else :
227
+ id , factory , lazy_init , abstract , parent , scope_ = self ._get_basic_object_data (object , object .get ("class" ))
234
228
235
- return self ._create_object (id , factory , lazy_init , abstract , parent ,
236
- scope_ , pos_constr , named_constr , props )
229
+ return self ._create_object (id , factory , lazy_init , abstract , parent ,
230
+ scope_ , pos_constr , named_constr , props )
237
231
238
232
def _print_obj (self , obj , level = 0 ):
239
233
self .logger .debug ("%sobject = %s" % ("\t " * level , obj ["object" ]))
240
- self .logger .debug ("%sobject id = %s" % ("\t " * level , obj ["object" ]))
241
- self .logger .debug ("%sclass = %s" % ("\t " * (level + 1 ), obj ["class" ]))
234
+ self .logger .debug ("%sclass = %s" % ("\t " * (level + 1 ), obj .get ("class" )))
242
235
243
236
if "scope" in obj :
244
237
self .logger .debug ("%sscope = %s" % ("\t " * (level + 1 ), obj ["scope" ]))
0 commit comments