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

Method make_class_group

code2flow/php.py:355–399  ·  view source on GitHub ↗

Given an AST for the subgroup (a class), generate that subgroup. In this function, we will also need to generate all of the nodes internal to the group. Specific to PHP, this can also be a namespace or class. :param tree ast: :param parent Group:

(tree, parent)

Source from the content-addressed store, hash-verified

353
354 @staticmethod
355 def make_class_group(tree, parent):
356 """
357 Given an AST for the subgroup (a class), generate that subgroup.
358 In this function, we will also need to generate all of the nodes internal
359 to the group.
360
361 Specific to PHP, this can also be a namespace or class.
362
363 :param tree ast:
364 :param parent Group:
365 :rtype: Group
366 """
367 assert tree['nodeType'] in ('Stmt_Class', 'Stmt_Namespace', 'Stmt_Trait')
368 subgroup_trees, node_trees, body_trees = PHP.separate_namespaces(tree['stmts'])
369
370 token = get_name(tree['name'])
371 display_type = tree['nodeType'][5:]
372
373 inherits = get_inherits(tree)
374
375 group_type = GROUP_TYPE.CLASS
376 if display_type == 'Namespace':
377 group_type = GROUP_TYPE.NAMESPACE
378
379 import_tokens = [token]
380 if display_type == 'Class' and parent.group_type == GROUP_TYPE.NAMESPACE:
381 import_tokens = [djoin(parent.token, token)]
382
383 class_group = Group(token, group_type, display_type, import_tokens=import_tokens,
384 parent=parent, inherits=inherits, line_number=lineno(tree))
385
386 for subgroup_tree in subgroup_trees:
387 class_group.add_subgroup(PHP.make_class_group(subgroup_tree, class_group))
388
389 for node_tree in node_trees:
390 for new_node in PHP.make_nodes(node_tree, parent=class_group):
391 class_group.add_node(new_node)
392
393 if group_type == GROUP_TYPE.NAMESPACE:
394 class_group.add_node(PHP.make_root_node(body_trees, class_group))
395 for node in class_group.nodes:
396 node.variables += [Variable(n.token, n, line_number=n.line_number)
397 for n in class_group.nodes]
398
399 return class_group
400
401 @staticmethod
402 def file_import_tokens(filename):

Callers 1

make_file_groupFunction · 0.45

Calls 11

add_subgroupMethod · 0.95
add_nodeMethod · 0.95
get_nameFunction · 0.85
djoinFunction · 0.85
GroupClass · 0.85
VariableClass · 0.85
get_inheritsFunction · 0.70
linenoFunction · 0.70
separate_namespacesMethod · 0.45
make_nodesMethod · 0.45
make_root_nodeMethod · 0.45

Tested by

no test coverage detected