MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / extract_import

Method extract_import

atomic-semantic/src/parsers/java.rs:403–424  ·  view source on GitHub ↗

Extract an import declaration.

(&self, node: &Node, source: &str, file_path: &str)

Source from the content-addressed store, hash-verified

401
402 /// Extract an import declaration.
403 fn extract_import(&self, node: &Node, source: &str, file_path: &str) -> Option<Entity> {
404 let line = node.start_position().row as u32 + 1;
405 let end_line = node.end_position().row as u32 + 1;
406
407 let text = self.node_text(node, source);
408
409 // Extract the imported path: `import java.util.List;` → `java.util.List`
410 let name = text
411 .strip_prefix("import ")
412 .unwrap_or(&text)
413 .strip_prefix("static ")
414 .unwrap_or(&text)
415 .trim()
416 .trim_end_matches(';')
417 .trim()
418 .to_string();
419
420 let mut entity = Entity::new(name, EntityKind::Import, file_path, line, end_line);
421 entity = entity.with_signature(text.trim_end_matches(';').trim().to_string());
422
423 Some(entity)
424 }
425
426 // ── Signature builders ──────────────────────────────────────────
427

Callers 1

walk_treeMethod · 0.45

Calls 2

with_signatureMethod · 0.80
node_textMethod · 0.45

Tested by

no test coverage detected