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

Method maybe_capture_fn_refs

codegraph-kernel/src/java.rs:1120–1193  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

1118 // --- function-as-value refs (JAVA_SPEC: method references only) ----------------
1119
1120 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1121 let mode_field: Option<&str> = match node.kind() {
1122 "argument_list" => Some(""), // args: every named child
1123 "assignment_expression" => Some("right"),
1124 "variable_declarator" => Some("value"),
1125 _ => None,
1126 };
1127 let Some(field) = mode_field else { return };
1128 if self.stack.is_empty() {
1129 return;
1130 }
1131 let from = self.top_row();
1132
1133 let mut values: Vec<Node> = Vec::new();
1134 if field.is_empty() {
1135 for i in 0..node.named_child_count() {
1136 if let Some(c) = node.named_child(i) {
1137 values.push(c);
1138 }
1139 }
1140 } else if field == "right" {
1141 if let Some(rhs) = node.child_by_field_name("right") {
1142 let lhs_text = node
1143 .child_by_field_name("left")
1144 .map(|l| self.text(l))
1145 .unwrap_or("");
1146 let lhs_last = util::lhs_last_name()
1147 .captures(lhs_text)
1148 .and_then(|c| c.get(1))
1149 .map(|m| m.as_str());
1150 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
1151 values.push(rhs);
1152 }
1153 }
1154 } else if let Some(v) = node.child_by_field_name("value") {
1155 // varinit — destructuring patterns don't exist in Java.
1156 values.push(v);
1157 }
1158
1159 for v in values {
1160 if v.kind() != "method_reference" {
1161 continue; // idTypes is EMPTY for Java — only method references
1162 }
1163 let mut last_ident: Option<Node> = None;
1164 for i in 0..v.named_child_count() {
1165 if let Some(c) = v.named_child(i) {
1166 if c.kind() == "identifier" {
1167 last_ident = Some(c);
1168 }
1169 }
1170 }
1171 let Some(last) = last_ident else { continue };
1172 let m = self.text(last);
1173 let text = self.text(v);
1174 let name = if text.starts_with("this::") || text.starts_with("super::") {
1175 format!("this.{m}")
1176 } else if let Some(c) = method_ref_type_re().captures(text) {
1177 if m == "new" {

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 4

method_ref_type_reFunction · 0.85
getMethod · 0.65
top_rowMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected