@@ -51,15 +51,15 @@ class JCodeanalyzer:
51
51
"""
52
52
53
53
def __init__ (
54
- self ,
55
- project_dir : Union [str , Path ],
56
- source_code : str | None ,
57
- analysis_backend_path : Union [str , Path , None ],
58
- analysis_json_path : Union [str , Path , None ],
59
- analysis_level : str ,
60
- use_graalvm_binary : bool ,
61
- eager_analysis : bool ,
62
- target_files : List [str ] | None
54
+ self ,
55
+ project_dir : Union [str , Path ],
56
+ source_code : str | None ,
57
+ analysis_backend_path : Union [str , Path , None ],
58
+ analysis_json_path : Union [str , Path , None ],
59
+ analysis_level : str ,
60
+ use_graalvm_binary : bool ,
61
+ eager_analysis : bool ,
62
+ target_files : List [str ] | None
63
63
) -> None :
64
64
self .project_dir = project_dir
65
65
self .source_code = source_code
@@ -173,7 +173,7 @@ def _get_codeanalyzer_exec(self) -> List[str]:
173
173
resources .files ("cldk.analysis.java.codeanalyzer.bin" ) / "codeanalyzer" ) as codeanalyzer_bin_path :
174
174
codeanalyzer_exec = shlex .split (codeanalyzer_bin_path .__str__ ())
175
175
else :
176
-
176
+
177
177
if self .analysis_backend_path :
178
178
analysis_backend_path = Path (self .analysis_backend_path )
179
179
logger .info (f"Using codeanalyzer.jar from { analysis_backend_path } " )
@@ -207,7 +207,7 @@ def _init_codeanalyzer(self, analysis_level=1) -> JApplication:
207
207
if self .target_files :
208
208
target_file_options = ' -t ' .join ([s .strip () for s in self .target_files ])
209
209
codeanalyzer_args = codeanalyzer_exec + shlex .split (
210
- f"-i { Path (self .project_dir )} --analysis-level={ analysis_level } -t { target_file_options } "
210
+ f"-i { Path (self .project_dir )} --analysis-level={ analysis_level } -t { target_file_options } "
211
211
)
212
212
else :
213
213
codeanalyzer_args = codeanalyzer_exec + shlex .split (
@@ -244,8 +244,8 @@ def _init_codeanalyzer(self, analysis_level=1) -> JApplication:
244
244
# of the existence of the analysis file.
245
245
# Create the executable command for codeanalyzer.
246
246
codeanalyzer_args = codeanalyzer_exec + shlex .split (
247
- f"-i { Path (self .project_dir )} --analysis-level={ analysis_level } -o { self .analysis_json_path } "
248
- )
247
+ f"-i { Path (self .project_dir )} --analysis-level={ analysis_level } -o { self .analysis_json_path } "
248
+ )
249
249
is_run_code_analyzer = True
250
250
251
251
if is_run_code_analyzer :
@@ -430,8 +430,9 @@ def get_all_callers(self, target_class_name: str, target_method_signature: str,
430
430
caller_detail_dict = {}
431
431
call_graph = None
432
432
if using_symbol_table :
433
- call_graph = self .__raw_call_graph_using_symbol_table_target_method (target_class_name = target_class_name ,
434
- target_method_signature = target_method_signature )
433
+ call_graph = self .__call_graph_using_symbol_table (qualified_class_name = target_class_name ,
434
+ method_signature = target_method_signature ,
435
+ is_target_method = True )
435
436
else :
436
437
call_graph = self .call_graph
437
438
if (target_method_signature , target_class_name ) not in call_graph .nodes ():
@@ -768,7 +769,7 @@ def get_class_call_graph_using_symbol_table(self, qualified_class_name: str,
768
769
769
770
def __call_graph_using_symbol_table (self ,
770
771
qualified_class_name : str ,
771
- method_signature : str , is_target_method : bool = False )-> DiGraph :
772
+ method_signature : str , is_target_method : bool = False ) -> DiGraph :
772
773
"""
773
774
Generate call graph using symbol table
774
775
Args:
@@ -782,10 +783,11 @@ def __call_graph_using_symbol_table(self,
782
783
cg = nx .DiGraph ()
783
784
sdg = None
784
785
if is_target_method :
785
- sdg = None
786
+ sdg = self .__raw_call_graph_using_symbol_table_target_method (target_class_name = qualified_class_name ,
787
+ target_method_signature = method_signature )
786
788
else :
787
789
sdg = self .__raw_call_graph_using_symbol_table (qualified_class_name = qualified_class_name ,
788
- method_signature = method_signature )
790
+ method_signature = method_signature )
789
791
tsu = JavaSitter ()
790
792
edge_list = [
791
793
(
@@ -812,8 +814,8 @@ def __call_graph_using_symbol_table(self,
812
814
return cg
813
815
814
816
def __raw_call_graph_using_symbol_table_target_method (self ,
815
- target_class_name : str ,
816
- target_method_signature : str ,
817
+ target_class_name : str ,
818
+ target_method_signature : str ,
817
819
cg = None ) -> list [JGraphEdgesST ]:
818
820
"""
819
821
Generates call graph using symbol table information given the target method and target class
@@ -832,7 +834,7 @@ def __raw_call_graph_using_symbol_table_target_method(self,
832
834
for class_name in self .get_all_classes ():
833
835
for method in self .get_all_methods_in_class (qualified_class_name = class_name ):
834
836
method_details = self .get_method (qualified_class_name = class_name ,
835
- method_signature = method )
837
+ method_signature = method )
836
838
for call_site in method_details .call_sites :
837
839
source_method_details = None
838
840
source_class = ''
@@ -856,9 +858,9 @@ def __raw_call_graph_using_symbol_table_target_method(self,
856
858
if call_site .receiver_type != "" :
857
859
# call to any class
858
860
if self .get_class (qualified_class_name = call_site .receiver_type ):
859
- if callee_signature == target_method_signature and call_site .receiver_type == target_class_name :
861
+ if callee_signature == target_method_signature and call_site .receiver_type == target_class_name :
860
862
source_method_details = self .get_method (method_signature = method ,
861
- qualified_class_name = class_name )
863
+ qualified_class_name = class_name )
862
864
source_class = class_name
863
865
else :
864
866
# check if any method exists with the signature in the class even if the receiver type is blank
0 commit comments