Handle R call nodes for imports and class definitions.
(
self, node, source: bytes, language: str, file_path: str,
nodes: list[NodeInfo], edges: list[EdgeInfo],
enclosing_class: Optional[str], enclosing_func: Optional[str],
import_map: Optional[dict[str, str]],
defined_names: Optional[set[str]],
)
| 6817 | return False |
| 6818 | |
| 6819 | def _handle_r_call( |
| 6820 | self, node, source: bytes, language: str, file_path: str, |
| 6821 | nodes: list[NodeInfo], edges: list[EdgeInfo], |
| 6822 | enclosing_class: Optional[str], enclosing_func: Optional[str], |
| 6823 | import_map: Optional[dict[str, str]], |
| 6824 | defined_names: Optional[set[str]], |
| 6825 | ) -> bool: |
| 6826 | """Handle R call nodes for imports and class definitions.""" |
| 6827 | func_name = self._r_call_func_name(node) |
| 6828 | if not func_name: |
| 6829 | return False |
| 6830 | |
| 6831 | if func_name in ("library", "require", "source"): |
| 6832 | imports = self._extract_import(node, language, source) |
| 6833 | for imp_target in imports: |
| 6834 | edges.append(EdgeInfo( |
| 6835 | kind="IMPORTS_FROM", |
| 6836 | source=file_path, |
| 6837 | target=imp_target, |
| 6838 | file_path=file_path, |
| 6839 | line=node.start_point[0] + 1, |
| 6840 | )) |
| 6841 | return True |
| 6842 | |
| 6843 | if func_name in ("setRefClass", "setClass", "setGeneric"): |
| 6844 | return self._handle_r_class_call( |
| 6845 | node, source, language, file_path, nodes, edges, |
| 6846 | enclosing_class, enclosing_func, |
| 6847 | import_map, defined_names, |
| 6848 | ) |
| 6849 | |
| 6850 | # Module-scope R calls attribute to the File node. |
| 6851 | call_name = self._get_call_name(node, language, source) |
| 6852 | if call_name: |
| 6853 | caller = ( |
| 6854 | self._qualify(enclosing_func, file_path, enclosing_class) |
| 6855 | if enclosing_func |
| 6856 | else file_path |
| 6857 | ) |
| 6858 | target = self._resolve_call_target( |
| 6859 | call_name, file_path, language, |
| 6860 | import_map or {}, defined_names or set(), |
| 6861 | ) |
| 6862 | edges.append(EdgeInfo( |
| 6863 | kind="CALLS", |
| 6864 | source=caller, |
| 6865 | target=target, |
| 6866 | file_path=file_path, |
| 6867 | line=node.start_point[0] + 1, |
| 6868 | )) |
| 6869 | |
| 6870 | self._extract_from_tree( |
| 6871 | node, source, language, file_path, nodes, edges, |
| 6872 | enclosing_class=enclosing_class, enclosing_func=enclosing_func, |
| 6873 | import_map=import_map, defined_names=defined_names, |
| 6874 | ) |
| 6875 | return True |
| 6876 |
no test coverage detected