diff --git a/cldk/analysis/java/codeanalyzer/codeanalyzer.py b/cldk/analysis/java/codeanalyzer/codeanalyzer.py index 41d260bd..7dccd9ba 100644 --- a/cldk/analysis/java/codeanalyzer/codeanalyzer.py +++ b/cldk/analysis/java/codeanalyzer/codeanalyzer.py @@ -51,15 +51,15 @@ class JCodeanalyzer: """ def __init__( - self, - project_dir: Union[str, Path], - source_code: str | None, - analysis_backend_path: Union[str, Path, None], - analysis_json_path: Union[str, Path, None], - analysis_level: str, - use_graalvm_binary: bool, - eager_analysis: bool, - target_files: List[str] | None + self, + project_dir: Union[str, Path], + source_code: str | None, + analysis_backend_path: Union[str, Path, None], + analysis_json_path: Union[str, Path, None], + analysis_level: str, + use_graalvm_binary: bool, + eager_analysis: bool, + target_files: List[str] | None ) -> None: self.project_dir = project_dir self.source_code = source_code @@ -173,7 +173,7 @@ def _get_codeanalyzer_exec(self) -> List[str]: resources.files("cldk.analysis.java.codeanalyzer.bin") / "codeanalyzer") as codeanalyzer_bin_path: codeanalyzer_exec = shlex.split(codeanalyzer_bin_path.__str__()) else: - + if self.analysis_backend_path: analysis_backend_path = Path(self.analysis_backend_path) logger.info(f"Using codeanalyzer.jar from {analysis_backend_path}") @@ -207,7 +207,7 @@ def _init_codeanalyzer(self, analysis_level=1) -> JApplication: if self.target_files: target_file_options = ' -t '.join([s.strip() for s in self.target_files]) codeanalyzer_args = codeanalyzer_exec + shlex.split( - f"-i {Path(self.project_dir)} --analysis-level={analysis_level} -t {target_file_options}" + f"-i {Path(self.project_dir)} --analysis-level={analysis_level} -t {target_file_options}" ) else: codeanalyzer_args = codeanalyzer_exec + shlex.split( @@ -244,8 +244,8 @@ def _init_codeanalyzer(self, analysis_level=1) -> JApplication: # of the existence of the analysis file. # Create the executable command for codeanalyzer. codeanalyzer_args = codeanalyzer_exec + shlex.split( - f"-i {Path(self.project_dir)} --analysis-level={analysis_level} -o {self.analysis_json_path}" - ) + f"-i {Path(self.project_dir)} --analysis-level={analysis_level} -o {self.analysis_json_path}" + ) is_run_code_analyzer = True if is_run_code_analyzer: @@ -430,8 +430,9 @@ def get_all_callers(self, target_class_name: str, target_method_signature: str, caller_detail_dict = {} call_graph = None if using_symbol_table: - call_graph = self.__raw_call_graph_using_symbol_table_target_method(target_class_name=target_class_name, - target_method_signature=target_method_signature) + call_graph = self.__call_graph_using_symbol_table(qualified_class_name=target_class_name, + method_signature=target_method_signature, + is_target_method=True) else: call_graph = self.call_graph 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, def __call_graph_using_symbol_table(self, qualified_class_name: str, - method_signature: str, is_target_method: bool = False)-> DiGraph: + method_signature: str, is_target_method: bool = False) -> DiGraph: """ Generate call graph using symbol table Args: @@ -782,10 +783,11 @@ def __call_graph_using_symbol_table(self, cg = nx.DiGraph() sdg = None if is_target_method: - sdg = None + sdg = self.__raw_call_graph_using_symbol_table_target_method(target_class_name=qualified_class_name, + target_method_signature=method_signature) else: sdg = self.__raw_call_graph_using_symbol_table(qualified_class_name=qualified_class_name, - method_signature=method_signature) + method_signature=method_signature) tsu = JavaSitter() edge_list = [ ( @@ -812,8 +814,8 @@ def __call_graph_using_symbol_table(self, return cg def __raw_call_graph_using_symbol_table_target_method(self, - target_class_name: str, - target_method_signature: str, + target_class_name: str, + target_method_signature: str, cg=None) -> list[JGraphEdgesST]: """ 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, for class_name in self.get_all_classes(): for method in self.get_all_methods_in_class(qualified_class_name=class_name): method_details = self.get_method(qualified_class_name=class_name, - method_signature=method) + method_signature=method) for call_site in method_details.call_sites: source_method_details = None source_class = '' @@ -856,9 +858,9 @@ def __raw_call_graph_using_symbol_table_target_method(self, if call_site.receiver_type != "": # call to any class if self.get_class(qualified_class_name=call_site.receiver_type): - if callee_signature==target_method_signature and call_site.receiver_type == target_class_name: + if callee_signature == target_method_signature and call_site.receiver_type == target_class_name: source_method_details = self.get_method(method_signature=method, - qualified_class_name=class_name) + qualified_class_name=class_name) source_class = class_name else: # check if any method exists with the signature in the class even if the receiver type is blank