Java Analysis
Analysis#
Java analysis utilities.
Provides a high-level API to analyze Java projects or single-source inputs using a Treesitter-based parser and the Code Analyzer backend.
JavaAnalysis
#
Analysis façade for Java code.
This class exposes methods to query symbol tables, classes, methods, call graphs, comments, and CRUD operations for a Java project or a single source file, depending on the initialization parameters.
Source code in cldk/analysis/java/java_analysis.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 |
|
get_imports()
#
Return all import statements in the source code.
Returns:
Type | Description |
---|---|
List[str]
|
list[str]: All import statements. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If this functionality is not supported. |
Source code in cldk/analysis/java/java_analysis.py
get_variables(**kwargs)
#
Return all variables discovered in the source code.
Returns:
Name | Type | Description |
---|---|---|
Any |
Implementation-defined variable view. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If this functionality is not supported. |
Source code in cldk/analysis/java/java_analysis.py
get_service_entry_point_classes(**kwargs)
#
Return all service entry-point classes.
Returns:
Name | Type | Description |
---|---|---|
Any |
Implementation-defined list or mapping of service classes. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If this functionality is not supported. |
Source code in cldk/analysis/java/java_analysis.py
get_service_entry_point_methods(**kwargs)
#
Return all service entry-point methods.
Returns:
Name | Type | Description |
---|---|---|
Any |
Implementation-defined list or mapping of service methods. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If this functionality is not supported. |
Source code in cldk/analysis/java/java_analysis.py
get_application_view()
#
Return the application view of the Java code.
Returns:
Name | Type | Description |
---|---|---|
JApplication |
JApplication
|
Application view of the Java code. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If single-file mode is used (unsupported here). |
Examples:
Get an application view using a project directory (backend required):
>>> from cldk.analysis import AnalysisLevel
>>> ja = JavaAnalysis(project_dir='path/to/project', source_code=None,
... analysis_backend_path=None, analysis_json_path=None,
... analysis_level=AnalysisLevel.symbol_table,
... target_files=None, eager_analysis=False)
>>> isinstance(ja.source_code, type(None))
True
Source code in cldk/analysis/java/java_analysis.py
get_symbol_table()
#
Return the symbol table.
Returns:
Type | Description |
---|---|
Dict[str, JCompilationUnit]
|
dict[str, JCompilationUnit]: Symbol table keyed by file path. |
Examples:
>>> from cldk.analysis import AnalysisLevel
>>> ja = JavaAnalysis(project_dir='path/to/project', source_code=None,
... analysis_backend_path=None, analysis_json_path=None,
... analysis_level=AnalysisLevel.symbol_table,
... target_files=None, eager_analysis=False)
>>> isinstance(ja.get_symbol_table(), dict)
True
Source code in cldk/analysis/java/java_analysis.py
get_compilation_units()
#
Return all compilation units in the Java code.
Returns:
Type | Description |
---|---|
List[JCompilationUnit]
|
list[JCompilationUnit]: Compilation units of the Java code. |
Examples:
List all compilation units for a project (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> isinstance(ja.get_compilation_units(), list)
True
Source code in cldk/analysis/java/java_analysis.py
get_class_hierarchy()
#
Return the class hierarchy of the Java code.
Returns:
Type | Description |
---|---|
DiGraph
|
networkx.DiGraph: Class hierarchy. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
Always, as the feature is not implemented yet. |
Source code in cldk/analysis/java/java_analysis.py
is_parsable(source_code)
#
Check if the source code is parsable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_code
|
str
|
Source code to parse. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if parsable, False otherwise. |
Examples:
>>> src = 'class A { void f(){} }'
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(source_code=src)
>>> ja.is_parsable(src)
True
Source code in cldk/analysis/java/java_analysis.py
get_raw_ast(source_code)
#
Parse and return the raw AST.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_code
|
str
|
Source code to parse. |
required |
Returns:
Name | Type | Description |
---|---|---|
Tree |
Tree
|
Raw syntax tree. |
Examples:
>>> src = 'class A { void f(){} }'
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(source_code=src)
>>> ast = ja.get_raw_ast(src)
>>> ast.root_node is not None
True
Source code in cldk/analysis/java/java_analysis.py
get_call_graph()
#
Return the call graph of the Java code.
Returns:
Type | Description |
---|---|
DiGraph
|
networkx.DiGraph: Call graph. |
Examples:
>>> from cldk.analysis import AnalysisLevel
>>> ja = JavaAnalysis(project_dir='path/to/project', source_code=None,
... analysis_backend_path=None, analysis_json_path=None,
... analysis_level=AnalysisLevel.call_graph,
... target_files=None, eager_analysis=False)
>>> isinstance(ja.get_call_graph(), nx.DiGraph)
True
Source code in cldk/analysis/java/java_analysis.py
get_call_graph_json()
#
Return the call graph serialized as JSON.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Call graph encoded as JSON. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If single-file mode is used (unsupported here). |
Examples:
>>> from cldk.analysis import AnalysisLevel
>>> ja = JavaAnalysis(project_dir='path/to/project', source_code=None,
... analysis_backend_path=None, analysis_json_path=None,
... analysis_level=AnalysisLevel.call_graph,
... target_files=None, eager_analysis=False)
>>> isinstance(ja.get_call_graph_json(), str)
True
Source code in cldk/analysis/java/java_analysis.py
get_callers(target_class_name, target_method_declaration, using_symbol_table=False)
#
Return all callers of a target method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_class_name
|
str
|
Qualified name of the target class. |
required |
target_method_declaration
|
str
|
Target method signature. |
required |
using_symbol_table
|
bool
|
Whether to use the symbol table. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
dict |
Dict
|
Mapping of callers to call sites/details. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If single-file mode is used (unsupported here). |
Examples:
>>> from cldk.analysis import AnalysisLevel
>>> ja = JavaAnalysis(project_dir='path/to/project', source_code=None,
... analysis_backend_path=None, analysis_json_path=None,
... analysis_level=AnalysisLevel.call_graph,
... target_files=None, eager_analysis=False)
>>> callers = ja.get_callers('com.example.A', 'f()')
>>> isinstance(callers, dict)
True
Source code in cldk/analysis/java/java_analysis.py
get_callees(source_class_name, source_method_declaration, using_symbol_table=False)
#
Return all callees of a given method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_class_name
|
str
|
Qualified class name containing the method. |
required |
source_method_declaration
|
str
|
Method signature. |
required |
using_symbol_table
|
bool
|
Whether to use the symbol table. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
dict |
Dict
|
Mapping of callees to call sites/details. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If single-file mode is used (unsupported here). |
Examples:
>>> from cldk.analysis import AnalysisLevel
>>> ja = JavaAnalysis(project_dir='path/to/project', source_code=None,
... analysis_backend_path=None, analysis_json_path=None,
... analysis_level=AnalysisLevel.call_graph,
... target_files=None, eager_analysis=False)
>>> callees = ja.get_callees('com.example.A', 'f()')
>>> isinstance(callees, dict)
True
Source code in cldk/analysis/java/java_analysis.py
get_methods()
#
Return all methods in the Java code.
Returns:
Type | Description |
---|---|
Dict[str, Dict[str, JCallable]]
|
dict[str, dict[str, JCallable]]: Methods grouped by qualified class name. |
Examples:
>>> from cldk.analysis import AnalysisLevel
>>> ja = JavaAnalysis(project_dir='path/to/project', source_code=None,
... analysis_backend_path=None, analysis_json_path=None,
... analysis_level=AnalysisLevel.symbol_table,
... target_files=None, eager_analysis=False)
>>> methods = ja.get_methods()
>>> isinstance(methods, dict)
True
Source code in cldk/analysis/java/java_analysis.py
get_classes()
#
Return all classes in the Java code.
Returns:
Type | Description |
---|---|
Dict[str, JType]
|
dict[str, JType]: Classes keyed by qualified class name. |
Examples:
>>> from cldk.analysis import AnalysisLevel
>>> ja = JavaAnalysis(project_dir='path/to/project', source_code=None,
... analysis_backend_path=None, analysis_json_path=None,
... analysis_level=AnalysisLevel.symbol_table,
... target_files=None, eager_analysis=False)
>>> classes = ja.get_classes()
>>> isinstance(classes, dict)
True
Source code in cldk/analysis/java/java_analysis.py
get_classes_by_criteria(inclusions=None, exclusions=None)
#
Return classes filtered by simple inclusion/exclusion criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inclusions
|
list[str] | None
|
If provided, only classes whose name contains any of these substrings are included. |
None
|
exclusions
|
list[str] | None
|
If provided, classes whose name contains any of these substrings are excluded. |
None
|
Returns:
Type | Description |
---|---|
Dict[str, JType]
|
dict[str, JType]: Matching classes keyed by qualified class name. |
Examples:
Filter classes using simple contains checks (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> filtered = ja.get_classes_by_criteria(inclusions=['Service'], exclusions=['Test'])
>>> isinstance(filtered, dict)
True
Source code in cldk/analysis/java/java_analysis.py
get_class(qualified_class_name)
#
Return a class object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qualified_class_name
|
str
|
Qualified class name. |
required |
Returns:
Name | Type | Description |
---|---|---|
JType |
JType
|
Class object for the given class. |
Examples:
Look up a class by its qualified name (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> c = ja.get_class('com.example.A')
>>> c is not None
True
Source code in cldk/analysis/java/java_analysis.py
get_method(qualified_class_name, qualified_method_name)
#
Return a method object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qualified_class_name
|
str
|
Qualified class name. |
required |
qualified_method_name
|
str
|
Qualified method name. |
required |
Returns:
Name | Type | Description |
---|---|---|
JCallable |
JCallable
|
Method object. |
Examples:
Look up a method by its qualified signature (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> m = ja.get_method('com.example.A', 'f()')
>>> m is not None
True
Source code in cldk/analysis/java/java_analysis.py
get_method_parameters(qualified_class_name, qualified_method_name)
#
Return the parameter types/names for a method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qualified_class_name
|
str
|
Qualified class name. |
required |
qualified_method_name
|
str
|
Qualified method name. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
list[str]: Method parameters. |
Examples:
List parameters for a method (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> params = ja.get_method_parameters('com.example.A', 'g(int, java.lang.String)')
>>> isinstance(params, list)
True
Source code in cldk/analysis/java/java_analysis.py
get_java_file(qualified_class_name)
#
Return the Java file path containing a class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qualified_class_name
|
str
|
Qualified class name. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Path to the Java file. |
Examples:
Get the source file path for a class (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> path = ja.get_java_file('com.example.A')
>>> isinstance(path, str)
True
Source code in cldk/analysis/java/java_analysis.py
get_java_compilation_unit(file_path)
#
Return the compilation unit for a Java source file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
Absolute path to a Java source file. |
required |
Returns:
Name | Type | Description |
---|---|---|
JCompilationUnit |
JCompilationUnit
|
Compilation unit object. |
Examples:
Parse a Java file into a compilation unit (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> cu = ja.get_java_compilation_unit('/abs/path/to/A.java')
>>> cu is not None
True
Source code in cldk/analysis/java/java_analysis.py
get_methods_in_class(qualified_class_name)
#
Return all methods of a class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qualified_class_name
|
str
|
Qualified class name. |
required |
Returns:
Type | Description |
---|---|
Dict[str, JCallable]
|
dict[str, JCallable]: Methods keyed by signature. |
Examples:
List methods declared in a class (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> methods = ja.get_methods_in_class('com.example.A')
>>> isinstance(methods, dict)
True
Source code in cldk/analysis/java/java_analysis.py
get_constructors(qualified_class_name)
#
Return all constructors of a class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qualified_class_name
|
str
|
Qualified class name. |
required |
Returns:
Type | Description |
---|---|
Dict[str, JCallable]
|
dict[str, JCallable]: Constructors keyed by signature. |
Examples:
List constructors declared in a class (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> ctors = ja.get_constructors('com.example.A')
>>> isinstance(ctors, dict)
True
Source code in cldk/analysis/java/java_analysis.py
get_fields(qualified_class_name)
#
Return all fields of a class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qualified_class_name
|
str
|
Qualified class name. |
required |
Returns:
Type | Description |
---|---|
List[JField]
|
list[JField]: All fields of the class. |
Examples:
List fields declared in a class (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> fields = ja.get_fields('com.example.A')
>>> isinstance(fields, list)
True
Source code in cldk/analysis/java/java_analysis.py
get_nested_classes(qualified_class_name)
#
Return all nested classes of a class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qualified_class_name
|
str
|
Qualified class name. |
required |
Returns:
Type | Description |
---|---|
List[JType]
|
list[JType]: Nested classes. |
Examples:
List nested classes declared in a class (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> nested = ja.get_nested_classes('com.example.A')
>>> isinstance(nested, list)
True
Source code in cldk/analysis/java/java_analysis.py
get_sub_classes(qualified_class_name)
#
Return all subclasses of a class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qualified_class_name
|
str
|
Qualified class name. |
required |
Returns:
Type | Description |
---|---|
Dict[str, JType]
|
dict[str, JType]: Subclasses keyed by qualified name. |
Examples:
List subclasses of a class (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> subs = ja.get_sub_classes('com.example.A')
>>> isinstance(subs, dict)
True
Source code in cldk/analysis/java/java_analysis.py
get_extended_classes(qualified_class_name)
#
Return all extended superclasses for a class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qualified_class_name
|
str
|
Qualified class name. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
list[str]: Extended classes. |
Examples:
List extended classes for a class (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> supers = ja.get_extended_classes('com.example.A')
>>> isinstance(supers, list)
True
Source code in cldk/analysis/java/java_analysis.py
get_implemented_interfaces(qualified_class_name)
#
Return all implemented interfaces for a class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qualified_class_name
|
str
|
Qualified class name. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
list[str]: Implemented interfaces. |
Examples:
List implemented interfaces for a class (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> ifaces = ja.get_implemented_interfaces('com.example.A')
>>> isinstance(ifaces, list)
True
Source code in cldk/analysis/java/java_analysis.py
get_class_call_graph(qualified_class_name, method_signature=None, using_symbol_table=False)
#
Return a class-level call graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qualified_class_name
|
str
|
Qualified class name. |
required |
method_signature
|
str | None
|
Optional method signature to scope the graph. |
None
|
using_symbol_table
|
bool
|
If True, use the symbol table for resolution. |
False
|
Returns:
Type | Description |
---|---|
List[Tuple[JMethodDetail, JMethodDetail]]
|
list[tuple[JMethodDetail, JMethodDetail]]: Edge list of caller -> callee. |
Examples:
Build a class-level call graph (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project', analysis_level='call-graph')
>>> edges = ja.get_class_call_graph('com.example.A')
>>> isinstance(edges, list)
True
Source code in cldk/analysis/java/java_analysis.py
get_entry_point_classes()
#
Return all entry-point classes.
Returns:
Type | Description |
---|---|
Dict[str, JType]
|
dict[str, JType]: Entry-point classes keyed by qualified class name. |
Examples:
List entry-point classes in an application (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> eps = ja.get_entry_point_classes()
>>> isinstance(eps, dict)
True
Source code in cldk/analysis/java/java_analysis.py
get_entry_point_methods()
#
Return all entry-point methods grouped by class.
Returns:
Type | Description |
---|---|
Dict[str, Dict[str, JCallable]]
|
dict[str, dict[str, JCallable]]: Entry-point methods keyed by class. |
Examples:
List entry-point methods in an application (backend required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> epms = ja.get_entry_point_methods()
>>> isinstance(epms, dict)
True
Source code in cldk/analysis/java/java_analysis.py
remove_all_comments()
#
Remove all comments from the source code.
Returns:
str: Source code with comments removed.
Examples:
Remove comments from inline source code:
>>> from cldk import CLDK
>>> src = 'class A { /* c */ // d
void f(){} }'.replace(' ', ' ') >>> ja = CLDK(language="java").analysis(source_code=src) >>> cleaned = ja.remove_all_comments() # doctest: +SKIP >>> '/*' in cleaned or '//' in cleaned # doctest: +SKIP False
Source code in cldk/analysis/java/java_analysis.py
get_methods_with_annotations(annotations)
#
Return methods grouped by the given annotations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotations
|
list[str]
|
Annotations to search for. |
required |
Returns:
Type | Description |
---|---|
Dict[str, List[Dict]]
|
dict[str, list[dict]]: Methods and bodies keyed by annotation. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
This functionality is not implemented yet. |
Source code in cldk/analysis/java/java_analysis.py
get_test_methods()
#
Return test methods discovered in the source code.
Returns:
Type | Description |
---|---|
Dict[str, str]
|
dict[str, str]: Mapping of method signature to body. |
Examples:
Extract test methods from inline source code:
>>> from cldk import CLDK
>>> src = 'import org.junit.Test; class A { @Test public void t(){} }'
>>> ja = CLDK(language="java").analysis(source_code=src)
>>> tests = ja.get_test_methods()
>>> isinstance(tests, dict)
True
Source code in cldk/analysis/java/java_analysis.py
get_calling_lines(target_method_name)
#
Return line numbers where a target method is called within a method body.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_method_name
|
str
|
Target method name. |
required |
Returns:
Type | Description |
---|---|
List[int]
|
list[int]: Line numbers within the source method code block. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
This functionality is not implemented yet. |
Source code in cldk/analysis/java/java_analysis.py
get_call_targets(declared_methods)
#
Return call targets using simple name resolution over the AST.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
declared_methods
|
dict
|
All methods declared in the class. |
required |
Returns:
Type | Description |
---|---|
Set[str]
|
set[str]: Discovered call targets. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
This functionality is not implemented yet. |
Source code in cldk/analysis/java/java_analysis.py
get_all_crud_operations()
#
Return all CRUD operations in the source code.
Returns:
Type | Description |
---|---|
List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]
|
list[dict[str, Union[JType, JCallable, list[JCRUDOperation]]]]: CRUD operations grouped by class/method. |
Examples:
Get all CRUD operations discovered by the backend (project required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> ops = ja.get_all_crud_operations()
>>> isinstance(ops, list)
True
Source code in cldk/analysis/java/java_analysis.py
get_all_create_operations()
#
Return all create operations in the source code.
Returns:
Type | Description |
---|---|
List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]
|
list[dict[str, Union[JType, JCallable, list[JCRUDOperation]]]]: Create operations. |
Examples:
Get create operations (project required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> creates = ja.get_all_create_operations()
>>> isinstance(creates, list)
True
Source code in cldk/analysis/java/java_analysis.py
get_all_read_operations()
#
Return all read operations in the source code.
Returns:
Type | Description |
---|---|
List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]
|
list[dict[str, Union[JType, JCallable, list[JCRUDOperation]]]]: Read operations. |
Examples:
Get read operations (project required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> reads = ja.get_all_read_operations()
>>> isinstance(reads, list)
True
Source code in cldk/analysis/java/java_analysis.py
get_all_update_operations()
#
Return all update operations in the source code.
Returns:
Type | Description |
---|---|
List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]
|
list[dict[str, Union[JType, JCallable, list[JCRUDOperation]]]]: Update operations. |
Examples:
Get update operations (project required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> updates = ja.get_all_update_operations()
>>> isinstance(updates, list)
True
Source code in cldk/analysis/java/java_analysis.py
get_all_delete_operations()
#
Return all delete operations in the source code.
Returns:
Type | Description |
---|---|
List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]
|
list[dict[str, Union[JType, JCallable, list[JCRUDOperation]]]]: Delete operations. |
Examples:
Get delete operations (project required):
>>> from cldk import CLDK
>>> ja = CLDK(language="java").analysis(project_path='path/to/project')
>>> deletes = ja.get_all_delete_operations()
>>> isinstance(deletes, list)
True
Source code in cldk/analysis/java/java_analysis.py
get_comments_in_a_method(qualified_class_name, method_signature)
#
Return all comments in a method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qualified_class_name
|
str
|
Qualified class name. |
required |
method_signature
|
str
|
Method signature. |
required |
Returns:
Type | Description |
---|---|
List[JComment]
|
list[JComment]: Comments in the method. |
Source code in cldk/analysis/java/java_analysis.py
get_comments_in_a_class(qualified_class_name)
#
Return all comments in a class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qualified_class_name
|
str
|
Qualified class name. |
required |
Returns:
Type | Description |
---|---|
List[JComment]
|
list[JComment]: Comments in the class. |
Source code in cldk/analysis/java/java_analysis.py
get_comment_in_file(file_path)
#
Return all comments in a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
Absolute file path. |
required |
Returns:
Type | Description |
---|---|
List[JComment]
|
list[JComment]: Comments in the file. |
Source code in cldk/analysis/java/java_analysis.py
get_all_comments()
#
Return all comments grouped by file.
Returns:
Type | Description |
---|---|
Dict[str, List[JComment]]
|
dict[str, list[JComment]]: Mapping of file path to comments. |
Schema#
Models module
JComment
#
Bases: BaseModel
Represents a comment in Java code.
Attributes:
Name | Type | Description |
---|---|---|
content |
str
|
The content of the comment. |
start_line |
int
|
The starting line number of the comment in the source file. |
end_line |
int
|
The ending line number of the comment in the source file. |
start_column |
int
|
The starting column of the comment in the source file. |
end_column |
int
|
The ending column of the comment in the source file. |
is_javadoc |
bool
|
A flag indicating whether the comment is a Javadoc comment. |
Source code in cldk/models/java/models.py
JRecordComponent
#
Bases: BaseModel
Represents a component of a Java record.
Attributes:
Name | Type | Description |
---|---|---|
comment |
JComment
|
The comment associated with the component. |
name |
str
|
The name of the component. |
type |
str
|
The type of the component. |
annotations |
List[str]
|
The annotations applied to the component. |
modifiers |
List[str]
|
The modifiers applied to the component. |
Source code in cldk/models/java/models.py
JField
#
Bases: BaseModel
Represents a field in a Java class or interface.
Attributes:
Name | Type | Description |
---|---|---|
comment |
JComment
|
The comment associated with the field. |
name |
str
|
The name of the field. |
type |
str
|
The type of the field. |
start_line |
int
|
The starting line number of the field in the source file. |
end_line |
int
|
The ending line number of the field in the source file. |
variables |
List[str]
|
The variables declared in the field. |
modifiers |
List[str]
|
The modifiers applied to the field (e.g., public, static). |
annotations |
List[str]
|
The annotations applied to the field. |
Source code in cldk/models/java/models.py
JCallableParameter
#
Bases: BaseModel
Represents a parameter of a Java callable.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the parameter. |
type |
str
|
The type of the parameter. |
annotations |
List[str]
|
The annotations applied to the parameter. |
modifiers |
List[str]
|
The modifiers applied to the parameter. |
start_line |
int
|
The starting line number of the parameter in the source file. |
end_line |
int
|
The ending line number of the parameter in the source file. |
start_column |
int
|
The starting column of the parameter in the source file. |
end_column |
int
|
The ending column of the parameter in the source file. |
Source code in cldk/models/java/models.py
JEnumConstant
#
Bases: BaseModel
Represents a constant in an enumeration.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the enum constant. |
arguments |
List[str]
|
The arguments associated with the enum constant. |
Source code in cldk/models/java/models.py
JCRUDOperation
#
Bases: BaseModel
Represents a CRUD operation.
Attributes:
Name | Type | Description |
---|---|---|
line_number |
int
|
The line number of the operation. |
operation_type |
JCRUDOperationType
|
The type of the operation. |
Source code in cldk/models/java/models.py
JCRUDQuery
#
Bases: BaseModel
Represents a CRUD query.
Attributes:
Name | Type | Description |
---|---|---|
line_number |
int
|
The line number of the query. |
query_arguments |
List[str]
|
The arguments of the query. |
query_type |
JCRUDQueryType
|
The type of the query. |
Source code in cldk/models/java/models.py
JCallSite
#
Bases: BaseModel
Represents a call site.
Attributes:
Name | Type | Description |
---|---|---|
comment |
JComment
|
The comment associated with the call site. |
method_name |
str
|
The name of the method called at the call site. |
receiver_expr |
str
|
Expression for the receiver of the method call. |
receiver_type |
str
|
Name of type declaring the called method. |
argument_types |
List[str]
|
Types of actual parameters for the call. |
argument_expr |
List[str]
|
Actual parameter expressions for the call. |
return_type |
str
|
Return type of the method call (resolved type of the method call expression; empty string if expression is unresolved). |
callee_signature |
str
|
Signature of the callee. |
is_static_call |
bool
|
Flag indicating whether the call is a static call. |
is_private |
bool
|
Flag indicating whether the call is a private call. |
is_public |
bool
|
Flag indicating whether the call is a public call. |
is_protected |
bool
|
Flag indicating whether the call is a protected call. |
is_unspecified |
bool
|
Flag indicating whether the call is an unspecified call. |
is_constructor_call |
bool
|
Flag indicating whether the call is a constructor call. |
crud_operation |
CRUDOperationType
|
The CRUD operation type of the call site. |
crud_query |
CRUDQueryType
|
The CRUD query type of the call site. |
start_line |
int
|
The starting line number of the call site. |
start_column |
int
|
The starting column of the call site. |
end_line |
int
|
The ending line number of the call site. |
end_column |
int
|
The ending column of the call site. |
Source code in cldk/models/java/models.py
JVariableDeclaration
#
Bases: BaseModel
Represents a variable declaration.
Attributes:
Name | Type | Description |
---|---|---|
comment |
JComment
|
The comment associated with the variable declaration. |
name |
str
|
The name of the variable. |
type |
str
|
The type of the variable. |
initializer |
str
|
The initialization expression (if present) for the variable declaration. |
start_line |
int
|
The starting line number of the declaration. |
start_column |
int
|
The starting column of the declaration. |
end_line |
int
|
The ending line number of the declaration. |
end_column |
int
|
The ending column of the declaration. |
Source code in cldk/models/java/models.py
InitializationBlock
#
Bases: BaseModel
Represents an initialization block in Java.
Attributes:
Name | Type | Description |
---|---|---|
file_path |
str
|
The path to the source file. |
comments |
List[JComment]
|
The comments associated with the block. |
annotations |
List[str]
|
The annotations applied to the block. |
thrown_exceptions |
List[str]
|
Exceptions declared via "throws". |
code |
str
|
The code block. |
start_line |
int
|
The starting line number of the block in the source file. |
end_line |
int
|
The ending line number of the block in the source file. |
is_static |
bool
|
A flag indicating whether the block is static. |
referenced_types |
List[str]
|
The types referenced within the block. |
accessed_fields |
List[str]
|
Fields accessed in the block. |
call_sites |
List[JCallSite]
|
Call sites in the block. |
variable_declarations |
List[JVariableDeclaration]
|
Local variable declarations in the block. |
cyclomatic_complexity |
int
|
Cyclomatic complexity of the block. |
Source code in cldk/models/java/models.py
JCallable
#
Bases: BaseModel
Represents a callable entity such as a method or constructor in Java.
Attributes:
Name | Type | Description |
---|---|---|
signature |
str
|
The signature of the callable. |
is_implicit |
bool
|
A flag indicating whether the callable is implicit (e.g., a default constructor). |
is_constructor |
bool
|
A flag indicating whether the callable is a constructor. |
comment |
List[JComment]
|
A list of comments associated with the callable. |
annotations |
List[str]
|
The annotations applied to the callable. |
modifiers |
List[str]
|
The modifiers applied to the callable (e.g., public, static). |
thrown_exceptions |
List[str]
|
Exceptions declared via "throws". |
declaration |
str
|
The declaration of the callable. |
parameters |
List[JCallableParameter]
|
The parameters of the callable. |
return_type |
Optional[str]
|
The return type of the callable. None if the callable does not return a value (e.g., a constructor). |
code |
str
|
The code block of the callable. |
start_line |
int
|
The starting line number of the callable in the source file. |
end_line |
int
|
The ending line number of the callable in the source file. |
code_start_line |
int
|
The starting line number of the code block of a callable in the source file. |
referenced_types |
List[str]
|
The types referenced within the callable. |
accessed_fields |
List[str]
|
Fields accessed in the callable. |
call_sites |
List[JCallSite]
|
Call sites in the callable. |
is_entrypoint |
bool
|
A flag indicating whether this is a service entry point method. |
variable_declarations |
List[JVariableDeclaration]
|
Local variable declarations in the callable. |
crud_operations |
List[JCRUDOperation]
|
CRUD operations in the callable. |
crud_queries |
List[JCRUDQuery]
|
CRUD queries in the callable. |
cyclomatic_complexity |
int
|
Cyclomatic complexity of the callable. |
Source code in cldk/models/java/models.py
JType
#
Bases: BaseModel
Represents a Java class or interface.
Attributes:
Name | Type | Description |
---|---|---|
is_interface |
bool
|
A flag indicating whether the object is an interface. |
is_inner_class |
bool
|
A flag indicating whether the object is an inner class. |
is_local_class |
bool
|
A flag indicating whether the object is a local class. |
is_nested_type |
bool
|
A flag indicating whether the object is a nested type. |
is_class_or_interface_declaration |
bool
|
A flag indicating whether the object is a class or interface declaration. |
is_enum_declaration |
bool
|
A flag indicating whether the object is an enum declaration. |
is_annotation_declaration |
bool
|
A flag indicating whether the object is an annotation declaration. |
is_record_declaration |
bool
|
A flag indicating whether this object is a record declaration. |
is_concrete_class |
bool
|
A flag indicating whether this is a concrete class. |
comments |
List[JComment]
|
A list of comments associated with the class/type. |
extends_list |
List[str]
|
The list of classes or interfaces that the object extends. |
implements_list |
List[str]
|
The list of interfaces that the object implements. |
modifiers |
List[str]
|
The list of modifiers of the object. |
annotations |
List[str]
|
The list of annotations of the object. |
parent_type |
str
|
The name of the parent class (if it exists). |
is_entrypoint_class |
bool
|
A flag indicating whether this is a service entry point class. |
nested_type_declarations |
List[str]
|
All the class declarations nested under this class. |
callable_declarations |
Dict[str, JCallable]
|
The list of constructors and methods of the object. |
field_declarations |
List[JField]
|
The list of fields of the object. |
enum_constants |
List[JEnumConstant]
|
The list of enum constants in the object. |
Source code in cldk/models/java/models.py
JCompilationUnit
#
Bases: BaseModel
Represents a compilation unit in Java.
Attributes:
Name | Type | Description |
---|---|---|
file_path |
str
|
The path to the source file. |
package_name |
str
|
The name of the package for the comppilation unit. |
comments |
List[JComment]
|
A list of comments in the compilation unit. |
imports |
List[str]
|
A list of import statements in the compilation unit. |
type_declarations |
Dict[str, JType]
|
A dictionary mapping type names to their corresponding JType representations. |
Source code in cldk/models/java/models.py
JMethodDetail
#
Bases: BaseModel
Represents details about a method in a Java class.
Attributes:
Name | Type | Description |
---|---|---|
method_declaration |
str
|
The declaration string of the method. |
klass |
str
|
The name of the class containing the method. 'class' is a reserved keyword in Python. |
method |
JCallable
|
An instance of JCallable representing the callable details of the method. |
Source code in cldk/models/java/models.py
JGraphEdgesST
#
Bases: BaseModel
Represents an edge in a graph structure for method dependencies.
Attributes:
Name | Type | Description |
---|---|---|
source |
JMethodDetail
|
The source method of the edge. |
target |
JMethodDetail
|
The target method of the edge. |
type |
str
|
The type of the edge. |
weight |
str
|
The weight of the edge, indicating the strength or significance of the connection. |
source_kind |
Optional[str]
|
The kind of the source method. Default is None. |
destination_kind |
Optional[str]
|
The kind of the target method. Default is None. |
Source code in cldk/models/java/models.py
JApplication
#
Bases: BaseModel
Represents a Java application.
Parameters#
symbol_table : List[JCompilationUnit] The symbol table representation system_dependency : List[JGraphEdges] The edges of the system dependency graph. Default None.