1
+ // script
2
+ use coref::java::*
3
+
4
+ fn default_java_db() -> JavaDB {
5
+ return JavaDB::load("coref_java_src.db")
6
+ }
7
+
8
+ // Given one or more function signatures, only one is given in the current example, which can be modified
9
+ // signature
10
+ fn isChecked(signature: string) -> bool {
11
+ [
12
+ {"HelloWorld.test2:void()"},
13
+ ]
14
+ }
15
+
16
+ // You can view the signature, line number, and file location of each callable by outputting the following function:
17
+ fn signature_name(signature: string, line: int, fileName: string) -> bool {
18
+ let (db = default_java_db()){
19
+ for (callable in Callable(db)){
20
+ if (signature = callable.getSignature() && fileName = callable.getLocation().getFile().getName()
21
+ && line = callable.getLocation().getStartLineNumber()) {
22
+ return true
23
+ }
24
+ }
25
+ }
26
+ }
27
+
28
+ // Determine whether it is a callable corresponding to the function signature
29
+ fn checkCallable(c: Callable)-> bool {
30
+ if (isChecked(c.getSignature())) {
31
+ return true
32
+ }
33
+ }
34
+
35
+
36
+ // Do an upward search
37
+ fn getAncestorCallerEndWithLimit(c: Callable) -> *Callable {
38
+ // Get the calling function of the current functio
39
+ yield c.getCaller()
40
+ // The current node is multiple layers above, and recursive calls are required to obtain all calling functions
41
+ for (tmp in c.getCaller()) {
42
+ yield getAncestorCallerEndWithLimit(tmp)
43
+ }
44
+ }
45
+
46
+ fn getAllLimitedCallable(c:Callable)->*Callable{
47
+ yield c
48
+ yield getAncestorCallerEndWithLimit(c)
49
+ }
50
+
51
+ // At the same time, output the class corresponding to callable
52
+ fn getCallGraph(callMethodName:string, callClassName: string,
53
+ calleeMethodName:string, calleeClassName: string) -> bool {
54
+ let (db = default_java_db()){
55
+ for (callable in Callable(db)){
56
+ if (checkCallable(callable)) {
57
+ for (call in getAllLimitedCallable(callable), callee in getAllLimitedCallable(callable)){
58
+ if (call != callee && callee in call.getCallee()) {
59
+ for (callMethod in Method(db), calleeMethod in Method(db)) {
60
+ if (callMethod.key_eq(call) && calleeMethod.key_eq(callee)) {
61
+ if (callMethodName = callMethod.getName() && callClassName = callMethod.getBelongedClass().getQualifiedName() &&
62
+ calleeMethodName = callee.getName() && calleeClassName = calleeMethod.getBelongedClass().getQualifiedName()) {
63
+ return true
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
70
+
71
+ }
72
+ }
73
+ }
74
+
75
+ fn main() {
76
+ output(getCallGraph())
77
+ // If you want to see the signature in the output add the following line back
78
+ // output(signature_name())
79
+ }
0 commit comments