Skip to content

Commit 624e7c5

Browse files
authored
Merge pull request #139 from codellm-devkit/callsite-argexpr-update
Callsite argument expression update
2 parents a1c0bef + 991fd8b commit 624e7c5

File tree

7 files changed

+133576
-105575
lines changed

7 files changed

+133576
-105575
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

tests/analysis/java/test_jcodeanalyzer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def test_get_all_callers(test_fixture, analysis_json):
342342
)
343343

344344
# Call without using symbol table
345-
all_callers = code_analyzer.get_all_callers("com.ibm.websphere.samples.daytrader.util.Log", "log(String)", False)
345+
all_callers = code_analyzer.get_all_callers("com.ibm.websphere.samples.daytrader.util.Log", "log(java.lang.String)", False)
346346
assert all_callers is not None
347347
assert isinstance(all_callers, Dict)
348348
assert len(all_callers) > 0
@@ -355,7 +355,7 @@ def test_get_all_callers(test_fixture, analysis_json):
355355

356356
# TODO: This currently doesn't work. Code has bad call as seen in this error message:
357357
# TypeError: TreesitterJava.get_calling_lines() missing 1 required positional argument: 'is_target_method_a_constructor'
358-
all_callers = code_analyzer.get_all_callers("com.ibm.websphere.samples.daytrader.util.Log", "log(String)", True)
358+
all_callers = code_analyzer.get_all_callers("com.ibm.websphere.samples.daytrader.util.Log", "log(java.lang.String)", True)
359359
assert all_callers is not None
360360
assert isinstance(all_callers, Dict)
361361
assert "caller_details" in all_callers
@@ -378,7 +378,7 @@ def test_get_all_callees(test_fixture, analysis_json):
378378
)
379379

380380
# Call without using symbol table
381-
all_callees = code_analyzer.get_all_callees("com.ibm.websphere.samples.daytrader.util.Log", "printCollection(String, Collection)", False)
381+
all_callees = code_analyzer.get_all_callees("com.ibm.websphere.samples.daytrader.util.Log", "printCollection(java.lang.String, java.util.Collection)", False)
382382
assert all_callees is not None
383383
assert isinstance(all_callees, Dict)
384384
assert "callee_details" in all_callees
@@ -388,7 +388,7 @@ def test_get_all_callees(test_fixture, analysis_json):
388388

389389
# TODO: Throws the following exception
390390
# TypeError: TreesitterJava.get_calling_lines() missing 1 required positional argument: 'is_target_method_a_constructor'
391-
all_callees = code_analyzer.get_all_callees("com.ibm.websphere.samples.daytrader.util.Log", "printCollection(String, Collection)", True)
391+
all_callees = code_analyzer.get_all_callees("com.ibm.websphere.samples.daytrader.util.Log", "printCollection(java.lang.String, java.util.Collection)", True)
392392
assert all_callees is not None
393393
assert isinstance(all_callees, Dict)
394394
assert "callee_details" in all_callees
@@ -458,7 +458,7 @@ def test_get_method(test_fixture, analysis_json):
458458
target_files=None,
459459
)
460460

461-
method = code_analyzer.get_method("com.ibm.websphere.samples.daytrader.impl.direct.TradeDirect", "publishQuotePriceChange(QuoteDataBean, BigDecimal, BigDecimal, double)")
461+
method = code_analyzer.get_method("com.ibm.websphere.samples.daytrader.impl.direct.TradeDirect", "publishQuotePriceChange(com.ibm.websphere.samples.daytrader.entities.QuoteDataBean, java.math.BigDecimal, java.math.BigDecimal, double)")
462462
assert method is not None
463463
assert isinstance(method, JCallable)
464464

@@ -730,7 +730,7 @@ def test_get_class_call_graph(test_fixture, analysis_json):
730730

731731
# Call with method signature
732732
class_call_graph = code_analyzer.get_class_call_graph(
733-
"com.ibm.websphere.samples.daytrader.impl.direct.TradeDirect", "createHolding(Connection, int, String, double, BigDecimal)"
733+
"com.ibm.websphere.samples.daytrader.impl.direct.TradeDirect", "createHolding(java.sql.Connection, int, java.lang.String, double, java.math.BigDecimal)"
734734
)
735735
assert class_call_graph is not None
736736
assert isinstance(class_call_graph, List)

0 commit comments

Comments
 (0)