def _create_child_under( res_opt: 'ResolveOptions', acp: 'AttributeContextParameters') -> 'CdmAttributeContext': if not acp: return None if acp._type == CdmAttributeContextType.PASS_THROUGH: return acp._under # This flag makes sure we hold on to any resolved object refs when things get copied. res_opt_copy = res_opt.copy() res_opt_copy._save_resolutions_on_copy = True definition = None # type: CdmObjectReference rts_applied = None # type: ResolvedTraitSet # Get a simple reference to definition object to avoid getting the traits that might be part of this ref # included in the link to the definition. if acp._regarding: # make a portable reference. this MUST be fixed up when the context node lands in the final document definition = cast( CdmObject, acp._regarding)._create_portable_reference(res_opt_copy) # Now get the traits applied at this reference (applied only, not the ones that are part of the definition # of the object) and make them the traits for this context. if acp._include_traits: rts_applied = acp._regarding._fetch_resolved_traits( res_opt_copy) under_child = acp._under.ctx.corpus.make_object( CdmObjectType.ATTRIBUTE_CONTEXT_DEF, acp._name) # type: CdmAttributeContext # Need context to make this a 'live' object. under_child.ctx = acp._under.ctx under_child.in_document = acp._under.in_document under_child.type = acp._type under_child.definition = definition # Add traits if there are any. if rts_applied and rts_applied.rt_set: for rt in rts_applied.rt_set: trait_ref = CdmObject._resolved_trait_to_trait_ref( res_opt_copy, rt) under_child.exhibits_traits.append(trait_ref, isinstance(trait_ref, str)) # Add to parent. under_child._update_parent(res_opt_copy, acp._under) if res_opt_copy._map_old_ctx_to_new_ctx is not None: res_opt_copy._map_old_ctx_to_new_ctx[ under_child] = under_child # so we can find every node, not only the replaced ones return under_child
def _create_child_under( res_opt: 'ResolveOptions', acp: 'AttributeContextParameters') -> 'CdmAttributeContext': if not acp: return None if acp.type == CdmAttributeContextType.PASS_THROUGH: return acp.under # This flag makes sure we hold on to any resolved object refs when things get copied. res_opt_copy = CdmObject._copy_resolve_options(res_opt) res_opt_copy._save_resolutions_on_copy = True definition = None # type: CdmObjectReference rts_applied = None # type: ResolvedTraitSet # Get a simple reference to definition object to avoid getting the traits that might be part of this ref # included in the link to the definition. if acp.regarding: definition = acp.regarding.create_simple_reference(res_opt_copy) definition.in_document = acp.under.in_document # ref is in same doc as context # Now get the traits applied at this reference (applied only, not the ones that are part of the definition # of the object) and make them the traits for this context. if acp.include_traits: rts_applied = acp.regarding._fetch_resolved_traits( res_opt_copy) under_child = acp.under.ctx.corpus.make_object( CdmObjectType.ATTRIBUTE_CONTEXT_DEF, acp.name) # type: CdmAttributeContext # Need context to make this a 'live' object. under_child.ctx = acp.under.ctx under_child.in_document = acp.under.in_document under_child.type = acp.type under_child.definition = definition # Add traits if there are any. if rts_applied and rts_applied.rt_set: for rt in rts_applied.rt_set: trait_ref = CdmObject._resolved_trait_to_trait_ref( res_opt_copy, rt) under_child.exhibits_traits.append(trait_ref, isinstance(trait_ref, str)) # Add to parent. under_child._update_parent(res_opt_copy, acp.under) return under_child