MCPcopy Create free account
hub / github.com/TtTRz/graphify-rs / extract_java

Function extract_java

crates/graphify-extract/src/ast_extract/java.rs:12–95  ·  view source on GitHub ↗
(path: &Path, source: &str)

Source from the content-addressed store, hash-verified

10use graphify_core::model::{ExtractionResult, GraphNode, NodeType};
11
12pub(crate) fn extract_java(path: &Path, source: &str) -> ExtractionResult {
13 let mut result = ExtractionResult::default();
14 let file_node = make_file_node(path);
15 let file_id = file_node.id.clone();
16 result.nodes.push(file_node);
17
18 let lines: Vec<&str> = source.lines().collect();
19 let ps = path_str(path);
20
21 for cap in RE_JAVA_CLASS.captures_iter(source) {
22 let kind = &cap[1];
23 let name = &cap[2];
24 let line = line_of(source, &cap);
25 let node_type = match kind {
26 "interface" => NodeType::Interface,
27 "enum" => NodeType::Enum,
28 _ => NodeType::Class,
29 };
30 let node = make_node(name, path, node_type, line);
31 let node_id = node.id.clone();
32 result.nodes.push(node);
33 result.edges.push(make_edge(
34 &file_id,
35 &node_id,
36 "defines",
37 path,
38 Confidence::Extracted,
39 ));
40 }
41
42 let mut functions: Vec<(String, String, usize, usize)> = Vec::new();
43 let func_matches: Vec<_> = RE_JAVA_METHOD.captures_iter(source).collect();
44 for (i, cap) in func_matches.iter().enumerate() {
45 let name = cap[1].to_string();
46 if [
47 "if", "for", "while", "switch", "catch", "return", "new", "throw",
48 ]
49 .contains(&name.as_str())
50 {
51 continue;
52 }
53 let start_line = line_of(source, cap);
54 let end_line = end_line_at(source, func_matches.get(i + 1));
55
56 let node = make_node(&name, path, NodeType::Method, start_line);
57 let node_id = node.id.clone();
58 functions.push((name, node_id.clone(), start_line, end_line));
59 result.nodes.push(node);
60 result.edges.push(make_edge(
61 &file_id,
62 &node_id,
63 "defines",
64 path,
65 Confidence::Extracted,
66 ));
67 }
68
69 for cap in RE_JAVA_IMPORT.captures_iter(source) {

Callers 1

extract_fileFunction · 0.85

Calls 8

make_file_nodeFunction · 0.85
path_strFunction · 0.85
line_ofFunction · 0.85
end_line_atFunction · 0.85
make_idFunction · 0.85
infer_callsFunction · 0.85
make_nodeFunction · 0.70
make_edgeFunction · 0.70

Tested by

no test coverage detected