Skip to content

Commit 817b4ac

Browse files
committed
add comments on java example
1 parent 354f07d commit 817b4ac

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

example/java/CallChainWithSignature.gdl

+27-17
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@ fn isChecked(signature: string) -> bool {
1515

1616
// You can view the signature, line number, and file location of each callable by outputting the following function:
1717
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
2423
}
2524
}
2625
}
2726

2827
// Determine whether it is a callable corresponding to the function signature
29-
fn checkCallable(c: Callable)-> bool {
28+
fn checkCallable(c: Callable) -> bool {
3029
if (isChecked(c.getSignature())) {
3130
return true
3231
}
@@ -35,39 +34,50 @@ fn checkCallable(c: Callable)-> bool {
3534

3635
// Do an upward search
3736
fn getAncestorCallerEndWithLimit(c: Callable) -> *Callable {
38-
// Get the calling function of the current functio
37+
// Get the calling function of the current function
3938
yield c.getCaller()
4039
// The current node is multiple layers above, and recursive calls are required to obtain all calling functions
4140
for (tmp in c.getCaller()) {
4241
yield getAncestorCallerEndWithLimit(tmp)
4342
}
4443
}
4544

46-
fn getAllLimitedCallable(c:Callable)->*Callable{
45+
fn getAllLimitedCallable(c: Callable) -> *Callable {
4746
yield c
4847
yield getAncestorCallerEndWithLimit(c)
4948
}
5049

5150
// 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)) {
5657
if (checkCallable(callable)) {
57-
for (call in getAllLimitedCallable(callable), callee in getAllLimitedCallable(callable)){
58+
for (call in getAllLimitedCallable(callable), callee in getAllLimitedCallable(callable)) {
5859
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
5963
for (callMethod in Method(db), calleeMethod in Method(db)) {
6064
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()) {
6374
return true
6475
}
6576
}
6677
}
6778
}
6879
}
6980
}
70-
7181
}
7282
}
7383
}

0 commit comments

Comments
 (0)