MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extract_instantiation

Method extract_instantiation

codegraph-kernel/src/tsjs/extractors.rs:2013–2049  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

2011 }
2012
2013 pub(super) fn extract_instantiation(&mut self, node: Node<'t>) {
2014 if self.stack.is_empty() {
2015 return;
2016 }
2017 let ctor = node
2018 .child_by_field_name("constructor")
2019 .or_else(|| node.child_by_field_name("type"))
2020 .or_else(|| node.child_by_field_name("name"))
2021 .or_else(|| node.named_child(0));
2022 let Some(ctor) = ctor else { return };
2023
2024 let mut class_name = self.text(ctor).to_string();
2025 // `new Map<K, V>()` → Map.
2026 if let Some(lt) = class_name.find('<') {
2027 if lt > 0 {
2028 class_name.truncate(lt);
2029 }
2030 }
2031 // `new ns.Foo()` → Foo.
2032 let last_dot = class_name
2033 .rfind('.')
2034 .map(|i| i as isize)
2035 .unwrap_or(-1)
2036 .max(class_name.rfind("::").map(|i| i as isize).unwrap_or(-1));
2037 if last_dot >= 0 {
2038 class_name = class_name[(last_dot as usize + 1)..].to_string();
2039 // TS: .replace(/^[:.]/, '') — one leading colon-or-dot.
2040 if class_name.starts_with(':') || class_name.starts_with('.') {
2041 class_name.remove(0);
2042 }
2043 }
2044 let class_name = class_name.trim().to_string();
2045 if !class_name.is_empty() {
2046 let from = self.top_row();
2047 self.push_ref(from, &class_name, edge_kind_index("instantiates").unwrap(), node);
2048 }
2049 }
2050
2051 // --- extractDecoratorsFor --------------------------------------------------------------
2052

Callers 2

visit_nodeMethod · 0.45

Calls 6

edge_kind_indexFunction · 0.85
mapMethod · 0.80
textMethod · 0.65
unwrapMethod · 0.60
top_rowMethod · 0.45
push_refMethod · 0.45

Tested by

no test coverage detected