3
3
from typing import Dict , List , Tuple , Set
4
4
from networkx import DiGraph
5
5
6
- from cldk .analysis import SymbolTable , CallGraph
6
+ from cldk .analysis import SymbolTable , CallGraph , AnalysisLevel
7
7
from cldk .models .java import JCallable
8
8
from cldk .models .java import JApplication
9
9
from cldk .models .java .models import JCompilationUnit , JMethodDetail , JType , JField
@@ -157,7 +157,8 @@ def get_call_graph_json(self) -> str:
157
157
raise NotImplementedError ("Producing a call graph over a single file is not implemented yet." )
158
158
return self .backend .get_call_graph_json ()
159
159
160
- def get_callers (self , target_class_name : str , target_method_declaration : str ):
160
+ def get_callers (self , target_class_name : str , target_method_declaration : str ,
161
+ using_symbol_table : bool = False ) -> Dict :
161
162
"""
162
163
Get all the caller details for a given java method.
163
164
@@ -168,7 +169,7 @@ def get_callers(self, target_class_name: str, target_method_declaration: str):
168
169
"""
169
170
if self .source_code :
170
171
raise NotImplementedError ("Generating all callers over a single file is not implemented yet." )
171
- return self .backend .get_all_callers (target_class_name , target_method_declaration )
172
+ return self .backend .get_all_callers (target_class_name , target_method_declaration , using_symbol_table )
172
173
173
174
def get_callees (self , source_class_name : str , source_method_declaration : str ):
174
175
"""
@@ -437,25 +438,50 @@ def get_implemented_interfaces(self, qualified_class_name) -> List[str]:
437
438
raise NotImplementedError (f"Support for this functionality has not been implemented yet." )
438
439
return self .backend .get_implemented_interfaces (qualified_class_name )
439
440
440
- def get_class_call_graph (self , qualified_class_name : str , method_name : str | None = None ) -> (List )[Tuple [JMethodDetail , JMethodDetail ]]:
441
+ def __get_class_call_graph_using_symbol_table (self , qualified_class_name : str , method_signature : str | None = None ) -> (List )[Tuple [JMethodDetail , JMethodDetail ]]:
442
+ """
443
+ A call graph using symbol table for a given class and a given method.
444
+ Args:
445
+ qualified_class_name:
446
+ method_signature:
447
+
448
+ Returns:
449
+ List[Tuple[JMethodDetail, JMethodDetail]]
450
+ An edge list of the call graph for the given class and method.
451
+ """
452
+ if self .analysis_backend in [AnalysisEngine .CODEQL , AnalysisEngine .TREESITTER ]:
453
+ raise NotImplementedError (f"Support for this functionality has not been implemented yet." )
454
+ return self .backend .get_class_call_graph_using_symbol_table (qualified_class_name , method_signature )
455
+
456
+ def get_class_call_graph (self , qualified_class_name : str , method_signature : str | None = None ,
457
+ using_symbol_table : bool = False ) -> List [Tuple [JMethodDetail , JMethodDetail ]]:
441
458
"""
442
459
A call graph for a given class and (optionally) a given method.
443
460
444
461
Parameters
445
462
----------
463
+ using_symbol_table: bool
464
+ Generate call graph using symbol table
446
465
qualified_class_name : str
447
466
The qualified name of the class.
448
467
method_name : str, optional
449
- The name of the method in the class.
468
+ The signature of the method in the class.
450
469
451
470
Returns
452
471
-------
453
472
List[Tuple[JMethodDetail, JMethodDetail]]
454
473
An edge list of the call graph for the given class and method.
474
+
475
+ Args:
476
+ using_symbol_table:
477
+ using_symbol_table:
455
478
"""
479
+ if using_symbol_table :
480
+ return self .__get_class_call_graph_using_symbol_table (qualified_class_name = qualified_class_name ,
481
+ method_signature = method_signature )
456
482
if self .analysis_backend in [AnalysisEngine .CODEQL , AnalysisEngine .TREESITTER ]:
457
483
raise NotImplementedError (f"Support for this functionality has not been implemented yet." )
458
- return self .backend .get_class_call_graph (qualified_class_name , method_name )
484
+ return self .backend .get_class_call_graph (qualified_class_name , method_signature )
459
485
460
486
def get_entry_point_classes (self ) -> Dict [str , JType ]:
461
487
"""
0 commit comments