MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / visit_import

Method visit_import

src/extraction/java_extractor.rs:279–346  ·  view source on GitHub ↗

Extract an import declaration as a Use node.

(state: &mut ExtractionState, node: TsNode<'_>)

Source from the content-addressed store, hash-verified

277
278 /// Extract an import declaration as a Use node.
279 fn visit_import(state: &mut ExtractionState, node: TsNode<'_>) {
280 let text = state.node_text(node);
281 // Strip "import " prefix, optional "static ", and trailing ";"
282 let path = text
283 .trim()
284 .strip_prefix("import ")
285 .unwrap_or(&text)
286 .trim()
287 .strip_prefix("static ")
288 .unwrap_or(text.trim().strip_prefix("import ").unwrap_or(&text).trim())
289 .trim_end_matches(';')
290 .trim()
291 .to_string();
292
293 let start_line = node.start_position().row as u32;
294 let end_line = node.end_position().row as u32;
295 let start_column = node.start_position().column as u32;
296 let end_column = node.end_position().column as u32;
297 let qualified_name = format!("{}::{}", state.qualified_prefix(), path);
298 let id = generate_node_id(&state.file_path, &NodeKind::Use, &path, start_line);
299
300 let graph_node = Node {
301 id: id.clone(),
302 kind: NodeKind::Use,
303 name: path.clone(),
304 qualified_name,
305 file_path: state.file_path.clone(),
306 start_line,
307 attrs_start_line: start_line,
308 end_line,
309 start_column,
310 end_column,
311 signature: Some(text.trim().to_string()),
312 docstring: None,
313 visibility: Visibility::Private,
314 is_async: false,
315 branches: 0,
316 loops: 0,
317 returns: 0,
318 max_nesting: 0,
319 unsafe_blocks: 0,
320 unchecked_calls: 0,
321 assertions: 0,
322 updated_at: state.timestamp,
323 parent_id: None,
324 };
325 state.nodes.push(graph_node);
326
327 // Contains edge from parent.
328 if let Some(parent_id) = state.parent_node_id() {
329 state.edges.push(Edge {
330 source: parent_id.to_string(),
331 target: id.clone(),
332 kind: EdgeKind::Contains,
333 line: Some(start_line),
334 });
335 }
336

Callers

nothing calls this directly

Calls 4

generate_node_idFunction · 0.85
pushMethod · 0.80
node_textMethod · 0.45
parent_node_idMethod · 0.45

Tested by

no test coverage detected