MCPcopy Create free account
hub / github.com/scottrogowski/code2flow / matches_variable

Method matches_variable

code2flow/model.py:213–259  ·  view source on GitHub ↗

Check whether this variable is what the call is acting on. For example, if we had 'obj' from obj = Obj() as a variable and a call of obj.do_something() Those would match and we would return the "do_something" node from obj. :param var

(self, variable)

Source from the content-addressed store, hash-verified

211 return self.owner_token is not None
212
213 def matches_variable(self, variable):
214 """
215 Check whether this variable is what the call is acting on.
216 For example, if we had 'obj' from
217 obj = Obj()
218 as a variable and a call of
219 obj.do_something()
220 Those would match and we would return the "do_something" node from obj.
221
222 :param variable Variable:
223 :rtype: Node
224 """
225
226 if self.is_attr():
227 if self.owner_token == variable.token:
228 for node in getattr(variable.points_to, 'nodes', []):
229 if self.token == node.token:
230 return node
231 for inherit_nodes in getattr(variable.points_to, 'inherits', []):
232 for node in inherit_nodes:
233 if self.token == node.token:
234 return node
235 if variable.points_to in OWNER_CONST:
236 return variable.points_to
237
238 # This section is specifically for resolving namespace variables
239 if isinstance(variable.points_to, Group) \
240 and variable.points_to.group_type == GROUP_TYPE.NAMESPACE:
241 parts = self.owner_token.split('.')
242 if len(parts) != 2:
243 return None
244 if parts[0] != variable.token:
245 return None
246 for node in variable.points_to.all_nodes():
247 if parts[1] == node.namespace_ownership() \
248 and self.token == node.token:
249 return node
250
251 return None
252 if self.token == variable.token:
253 if isinstance(variable.points_to, Node):
254 return variable.points_to
255 if isinstance(variable.points_to, Group) \
256 and variable.points_to.group_type == GROUP_TYPE.CLASS \
257 and variable.points_to.get_constructor():
258 return variable.points_to.get_constructor()
259 return None
260
261
262class Node():

Callers 1

_find_link_for_callFunction · 0.80

Calls 4

is_attrMethod · 0.95
all_nodesMethod · 0.80
namespace_ownershipMethod · 0.80
get_constructorMethod · 0.80

Tested by

no test coverage detected