@@ -15,18 +15,17 @@ fn isChecked(signature: string) -> bool {
15
15
16
16
// You can view the signature, line number, and file location of each callable by outputting the following function:
17
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
- }
18
+ for (callable in Callable(default_java_db())) {
19
+ if (signature = callable.getSignature() &&
20
+ fileName = callable.getLocation().getFile().getName() &&
21
+ line = callable.getLocation().getStartLineNumber()) {
22
+ return true
24
23
}
25
24
}
26
25
}
27
26
28
27
// Determine whether it is a callable corresponding to the function signature
29
- fn checkCallable(c: Callable)-> bool {
28
+ fn checkCallable(c: Callable) -> bool {
30
29
if (isChecked(c.getSignature())) {
31
30
return true
32
31
}
@@ -35,39 +34,50 @@ fn checkCallable(c: Callable)-> bool {
35
34
36
35
// Do an upward search
37
36
fn getAncestorCallerEndWithLimit(c: Callable) -> *Callable {
38
- // Get the calling function of the current functio
37
+ // Get the calling function of the current function
39
38
yield c.getCaller()
40
39
// The current node is multiple layers above, and recursive calls are required to obtain all calling functions
41
40
for (tmp in c.getCaller()) {
42
41
yield getAncestorCallerEndWithLimit(tmp)
43
42
}
44
43
}
45
44
46
- fn getAllLimitedCallable(c:Callable)-> *Callable{
45
+ fn getAllLimitedCallable(c: Callable) -> *Callable {
47
46
yield c
48
47
yield getAncestorCallerEndWithLimit(c)
49
48
}
50
49
51
50
// 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)){
51
+ fn getCallGraph(callMethodName: string,
52
+ callClassName: string,
53
+ calleeMethodName: string,
54
+ calleeClassName: string) -> bool {
55
+ let (db = default_java_db()) {
56
+ for (callable in Callable(db)) {
56
57
if (checkCallable(callable)) {
57
- for (call in getAllLimitedCallable(callable), callee in getAllLimitedCallable(callable)){
58
+ for (call in getAllLimitedCallable(callable), callee in getAllLimitedCallable(callable)) {
58
59
if (call != callee && callee in call.getCallee()) {
60
+ // Get the method corresponding to the callable
61
+ // But be aware that the callable is mixed with method and constructor
62
+ // So this call graph may not contain constructor
59
63
for (callMethod in Method(db), calleeMethod in Method(db)) {
60
64
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()) {
65
+ if (callMethodName = callMethod.getName() &&
66
+ callClassName = callMethod.getBelongedClass().getQualifiedName() &&
67
+ calleeMethodName = callee.getName() &&
68
+ // Also, method's getBelongedClass will get Class,
69
+ // but some of methods are belonged to interface.
70
+ // So this call graph may not contain methods in interfaces.
71
+ // If you want to get methods in interfaces, you can use the following code:
72
+ // calleeClassName = calleeMethod.getParent().getQualifiedName()
73
+ calleeClassName = calleeMethod.getBelongedClass().getQualifiedName()) {
63
74
return true
64
75
}
65
76
}
66
77
}
67
78
}
68
79
}
69
80
}
70
-
71
81
}
72
82
}
73
83
}
0 commit comments