codegraph_python/relationships/
calls.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5pub struct CallRelation {
6 pub caller: String,
8
9 pub callee: String,
11
12 pub line: usize,
14
15 pub is_method_call: bool,
17}
18
19impl CallRelation {
20 pub fn new(caller: impl Into<String>, callee: impl Into<String>, line: usize) -> Self {
22 Self {
23 caller: caller.into(),
24 callee: callee.into(),
25 line,
26 is_method_call: false,
27 }
28 }
29
30 pub fn method_call(caller: impl Into<String>, callee: impl Into<String>, line: usize) -> Self {
32 Self {
33 caller: caller.into(),
34 callee: callee.into(),
35 line,
36 is_method_call: true,
37 }
38 }
39
40 pub fn set_method_call(mut self, is_method_call: bool) -> Self {
42 self.is_method_call = is_method_call;
43 self
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_call_relation_new() {
53 let call = CallRelation::new("foo", "bar", 10);
54 assert_eq!(call.caller, "foo");
55 assert_eq!(call.callee, "bar");
56 assert_eq!(call.line, 10);
57 assert!(!call.is_method_call);
58 }
59
60 #[test]
61 fn test_method_call() {
62 let call = CallRelation::method_call("foo", "bar", 20);
63 assert_eq!(call.caller, "foo");
64 assert_eq!(call.callee, "bar");
65 assert_eq!(call.line, 20);
66 assert!(call.is_method_call);
67 }
68}