@@ -154,44 +154,60 @@ def _link_usings(
154154 edges : EdgeDict ,
155155 ) -> None :
156156 for using in _extract_usings (df .content , df .path ):
157- using_lower = using .lower ()
158- for fid in namespace_to_frags .get (using_lower , []):
159- if fid != df .id :
160- self .add_edge (edges , df .id , fid , self .using_weight )
157+ self ._link_single_using (df .id , using , namespace_to_frags , fqn_to_frags , type_to_frags , edges )
161158
162- for fid in fqn_to_frags .get (using_lower , []):
163- if fid != df .id :
164- self .add_edge (edges , df .id , fid , self .using_weight )
159+ def _link_single_using (
160+ self ,
161+ df_id : FragmentId ,
162+ using : str ,
163+ namespace_to_frags : dict [str , list [FragmentId ]],
164+ fqn_to_frags : dict [str , list [FragmentId ]],
165+ type_to_frags : dict [str , list [FragmentId ]],
166+ edges : EdgeDict ,
167+ ) -> None :
168+ using_lower = using .lower ()
169+ self ._add_edges_from_index (df_id , namespace_to_frags .get (using_lower , []), self .using_weight , edges )
170+ self ._add_edges_from_index (df_id , fqn_to_frags .get (using_lower , []), self .using_weight , edges )
165171
166- parts = using .split ("." )
167- if parts :
168- for fid in type_to_frags .get (parts [- 1 ].lower (), []):
169- if fid != df .id :
170- self .add_edge (edges , df .id , fid , self .using_weight )
172+ parts = using .split ("." )
173+ if parts :
174+ self ._add_edges_from_index (df_id , type_to_frags .get (parts [- 1 ].lower (), []), self .using_weight , edges )
175+
176+ def _add_edges_from_index (self , source_id : FragmentId , target_ids : list [FragmentId ], weight : float , edges : EdgeDict ) -> None :
177+ for fid in target_ids :
178+ if fid != source_id :
179+ self .add_edge (edges , source_id , fid , weight )
171180
172181 def _link_refs (
173182 self ,
174183 df : Fragment ,
175184 type_to_frags : dict [str , list [FragmentId ]],
176185 edges : EdgeDict ,
177186 ) -> None :
178- for parent in _extract_inheritance (df .content ):
179- for fid in type_to_frags .get (parent .lower (), []):
180- if fid != df .id :
181- self .add_edge (edges , df .id , fid , self .inheritance_weight )
187+ self ._link_inheritance (df .id , df .content , type_to_frags , edges )
188+ self ._link_type_refs (df .id , df .content , type_to_frags , edges )
189+ self ._link_attributes (df .id , df .content , type_to_frags , edges )
182190
183- for type_ref in _extract_type_refs (df .content ):
184- for fid in type_to_frags .get (type_ref .lower (), []):
185- if fid != df .id :
186- self .add_edge (edges , df .id , fid , self .type_weight )
191+ def _link_inheritance (
192+ self , df_id : FragmentId , content : str , type_to_frags : dict [str , list [FragmentId ]], edges : EdgeDict
193+ ) -> None :
194+ for parent in _extract_inheritance (content ):
195+ self ._add_edges_from_index (df_id , type_to_frags .get (parent .lower (), []), self .inheritance_weight , edges )
187196
188- for attr in _extract_attributes (df .content ):
197+ def _link_type_refs (
198+ self , df_id : FragmentId , content : str , type_to_frags : dict [str , list [FragmentId ]], edges : EdgeDict
199+ ) -> None :
200+ for type_ref in _extract_type_refs (content ):
201+ self ._add_edges_from_index (df_id , type_to_frags .get (type_ref .lower (), []), self .type_weight , edges )
202+
203+ def _link_attributes (
204+ self , df_id : FragmentId , content : str , type_to_frags : dict [str , list [FragmentId ]], edges : EdgeDict
205+ ) -> None :
206+ for attr in _extract_attributes (content ):
189207 attr_lower = attr .lower ()
190208 attr_full = attr_lower if attr_lower .endswith ("attribute" ) else attr_lower + "attribute"
191209 for lookup in [attr_lower , attr_full ]:
192- for fid in type_to_frags .get (lookup , []):
193- if fid != df .id :
194- self .add_edge (edges , df .id , fid , self .attribute_weight )
210+ self ._add_edges_from_index (df_id , type_to_frags .get (lookup , []), self .attribute_weight , edges )
195211
196212 def _link_same_namespace (
197213 self ,
0 commit comments