Skip to content

Commit 9f68af0

Browse files
committed
Updates for call argument expr and fully qualified parameter types in method signatures
Signed-off-by: Saurabh Sinha <[email protected]>
1 parent 1109a80 commit 9f68af0

File tree

6 files changed

+133570
-105569
lines changed

6 files changed

+133570
-105569
lines changed

cldk/analysis/java/codeanalyzer/codeanalyzer.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -729,20 +729,21 @@ def __raw_call_graph_using_symbol_table_target_method(self, target_class_name: s
729729
source_class = ""
730730
callee_signature = ""
731731
if call_site.callee_signature != "":
732-
pattern = r"\b(?:[a-zA-Z_][\w\.]*\.)+([a-zA-Z_][\w]*)\b|<[^>]*>"
733-
734-
# Find the part within the parentheses
735-
start = call_site.callee_signature.find("(") + 1
736-
end = call_site.callee_signature.rfind(")")
737-
738-
# Extract the elements inside the parentheses
739-
elements = call_site.callee_signature[start:end].split(",")
740-
741-
# Apply the regex to each element
742-
simplified_elements = [re.sub(pattern, r"\1", element.strip()) for element in elements]
743-
744-
# Reconstruct the string with simplified elements
745-
callee_signature = f"{call_site.callee_signature[:start]}{', '.join(simplified_elements)}{call_site.callee_signature[end:]}"
732+
# pattern = r"\b(?:[a-zA-Z_][\w\.]*\.)+([a-zA-Z_][\w]*)\b|<[^>]*>"
733+
#
734+
# # Find the part within the parentheses
735+
# start = call_site.callee_signature.find("(") + 1
736+
# end = call_site.callee_signature.rfind(")")
737+
#
738+
# # Extract the elements inside the parentheses
739+
# elements = call_site.callee_signature[start:end].split(",")
740+
#
741+
# # Apply the regex to each element
742+
# simplified_elements = [re.sub(pattern, r"\1", element.strip()) for element in elements]
743+
#
744+
# # Reconstruct the string with simplified elements
745+
# callee_signature = f"{call_site.callee_signature[:start]}{', '.join(simplified_elements)}{call_site.callee_signature[end:]}"
746+
callee_signature = call_site.callee_signature
746747

747748
if call_site.receiver_type != "":
748749
# call to any class
@@ -796,20 +797,21 @@ def __raw_call_graph_using_symbol_table(self, qualified_class_name: str, method_
796797
# Currently the callee signature returns the fully qualified type, whereas
797798
# the key for JCallable does not. The below logic converts the fully qualified signature
798799
# to the desider format. Only limitation is the nested generic type.
799-
pattern = r"\b(?:[a-zA-Z_][\w\.]*\.)+([a-zA-Z_][\w]*)\b|<[^>]*>"
800-
801-
# Find the part within the parentheses
802-
start = call_site.callee_signature.find("(") + 1
803-
end = call_site.callee_signature.rfind(")")
804-
805-
# Extract the elements inside the parentheses
806-
elements = call_site.callee_signature[start:end].split(",")
807-
808-
# Apply the regex to each element
809-
simplified_elements = [re.sub(pattern, r"\1", element.strip()) for element in elements]
810-
811-
# Reconstruct the string with simplified elements
812-
callee_signature = f"{call_site.callee_signature[:start]}{', '.join(simplified_elements)}{call_site.callee_signature[end:]}"
800+
# pattern = r"\b(?:[a-zA-Z_][\w\.]*\.)+([a-zA-Z_][\w]*)\b|<[^>]*>"
801+
#
802+
# # Find the part within the parentheses
803+
# start = call_site.callee_signature.find("(") + 1
804+
# end = call_site.callee_signature.rfind(")")
805+
#
806+
# # Extract the elements inside the parentheses
807+
# elements = call_site.callee_signature[start:end].split(",")
808+
#
809+
# # Apply the regex to each element
810+
# simplified_elements = [re.sub(pattern, r"\1", element.strip()) for element in elements]
811+
#
812+
# # Reconstruct the string with simplified elements
813+
# callee_signature = f"{call_site.callee_signature[:start]}{', '.join(simplified_elements)}{call_site.callee_signature[end:]}"
814+
callee_signature = call_site.callee_signature
813815

814816
if call_site.receiver_type != "":
815817
# call to any class
28.7 MB
Binary file not shown.

cldk/models/java/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class JCallSite(BaseModel):
158158
receiver_expr (str): Expression for the receiver of the method call.
159159
receiver_type (str): Name of type declaring the called method.
160160
argument_types (List[str]): Types of actual parameters for the call.
161+
argument_expr (List[str]): Actual parameter expressions for the call.
161162
return_type (str): Return type of the method call (resolved type of the method call expression; empty string if expression is unresolved).
162163
callee_signature (str): Signature of the callee.
163164
is_static_call (bool): Flag indicating whether the call is a static call.
@@ -179,6 +180,7 @@ class JCallSite(BaseModel):
179180
receiver_expr: str = ""
180181
receiver_type: str
181182
argument_types: List[str]
183+
argument_expr: List[str]
182184
return_type: str = ""
183185
callee_signature: str = ""
184186
is_static_call: bool | None = None

tests/analysis/java/test_java_analysis.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def test_get_callers(test_fixture, analysis_json):
370370
)
371371

372372
# Test using call graph
373-
callers = java_analysis.get_callers("com.ibm.websphere.samples.daytrader.util.Log", "log(String)", False)
373+
callers = java_analysis.get_callers("com.ibm.websphere.samples.daytrader.util.Log", "log(java.lang.String)", False)
374374
assert callers is not None
375375
assert isinstance(callers, Dict)
376376
assert "caller_details" in callers
@@ -383,7 +383,7 @@ def test_get_callers(test_fixture, analysis_json):
383383
# Uncomment this next test section when fixed
384384

385385
# Test using symbol table
386-
callers = java_analysis.get_callers("com.ibm.websphere.samples.daytrader.util.Log", "log(String)", True)
386+
callers = java_analysis.get_callers("com.ibm.websphere.samples.daytrader.util.Log", "log(java.lang.String)", True)
387387
assert callers is not None
388388
assert isinstance(callers, Dict)
389389
assert "caller_details" in callers
@@ -415,14 +415,14 @@ def test_get_callees(test_fixture, analysis_json):
415415
)
416416

417417
# Test with a class that has no callees
418-
callees = java_analysis.get_callees("com.ibm.websphere.samples.daytrader.util.Log", "log(String)", False)
418+
callees = java_analysis.get_callees("com.ibm.websphere.samples.daytrader.util.Log", "log(java.lang.String)", False)
419419
assert callees is not None
420420
assert isinstance(callees, Dict)
421421
assert "callee_details" in callees
422422
assert len(callees["callee_details"]) == 0
423423

424424
# Test with a class that has callees
425-
callees = java_analysis.get_callees("com.ibm.websphere.samples.daytrader.web.websocket.ActionMessage", "doDecoding(String)", False)
425+
callees = java_analysis.get_callees("com.ibm.websphere.samples.daytrader.web.websocket.ActionMessage", "doDecoding(java.lang.String)", False)
426426
assert callees is not None
427427
assert isinstance(callees, Dict)
428428
assert "callee_details" in callees
@@ -435,7 +435,7 @@ def test_get_callees(test_fixture, analysis_json):
435435
# Uncomment this next test section when fixed
436436

437437
# # Test using symbol table
438-
callees = java_analysis.get_callees("com.ibm.websphere.samples.daytrader.web.websocket.ActionMessage", "doDecoding(String)", True)
438+
callees = java_analysis.get_callees("com.ibm.websphere.samples.daytrader.web.websocket.ActionMessage", "doDecoding(java.lang.String)", True)
439439
assert callees is not None
440440
assert isinstance(callees, Dict)
441441
assert "callee_details" in callees
@@ -572,7 +572,7 @@ def test_get_method(test_fixture, analysis_json):
572572
eager_analysis=False,
573573
)
574574

575-
the_method = java_analysis.get_method("com.ibm.websphere.samples.daytrader.util.Log", "trace(String)")
575+
the_method = java_analysis.get_method("com.ibm.websphere.samples.daytrader.util.Log", "trace(java.lang.String)")
576576
assert the_method is not None
577577
assert isinstance(the_method, JCallable)
578578
assert the_method.declaration == "public static void trace(String message)"
@@ -594,7 +594,7 @@ def test_get_method_parameters(test_fixture, analysis_json):
594594
eager_analysis=False,
595595
)
596596

597-
the_method_parameters = java_analysis.get_method_parameters("com.ibm.websphere.samples.daytrader.util.Log", "trace(String)")
597+
the_method_parameters = java_analysis.get_method_parameters("com.ibm.websphere.samples.daytrader.util.Log", "trace(java.lang.String)")
598598
assert the_method_parameters is not None
599599
assert isinstance(the_method_parameters, List)
600600
assert len(the_method_parameters) == 1

0 commit comments

Comments
 (0)