Skip to content

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
class 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.
    """

    def __init__(
        self,
        project_dir: str | Path | None,
        source_code: str | None,
        analysis_backend_path: str | None,
        analysis_json_path: str | Path | None,
        analysis_level: str,
        target_files: List[str] | None,
        eager_analysis: bool,
    ) -> None:
        """Initialize the Java analysis backend.

        Args:
            project_dir (str | Path | None): Directory path of the project.
            source_code (str | None): Source text for single-file analysis.
            analysis_backend_path (str | None): Path to the analysis backend. For
                CodeQL, the CLI must be installed and on PATH. For CodeAnalyzer,
                the JAR is downloaded from the latest release when not provided.
            analysis_json_path (str | Path | None): Path to persist the analysis
                database (analysis.json). If None, results are not persisted.
            analysis_level (str): Analysis level. For example, "symbol-table" or
                "call-graph".
            target_files (list[str] | None): Optional list of target file paths to
                constrain analysis (primarily supported for symbol-table).
            eager_analysis (bool): If True, forces regeneration of analysis.json
                on each run even if it exists.

        Raises:
            NotImplementedError: If the requested analysis backend is unsupported.
        """

        self.project_dir = project_dir
        self.source_code = source_code
        self.analysis_level = analysis_level
        self.analysis_json_path = analysis_json_path
        self.analysis_backend_path = analysis_backend_path
        self.eager_analysis = eager_analysis
        self.target_files = target_files
        self.treesitter_java: TreesitterJava = TreesitterJava()
        # Initialize the analysis analysis_backend
        self.backend: JCodeanalyzer = JCodeanalyzer(
            project_dir=self.project_dir,
            source_code=self.source_code,
            eager_analysis=self.eager_analysis,
            analysis_level=self.analysis_level,
            analysis_json_path=self.analysis_json_path,
            analysis_backend_path=self.analysis_backend_path,
            target_files=self.target_files,
        )

    def get_imports(self) -> List[str]:
        """Return all import statements in the source code.

        Returns:
            list[str]: All import statements.

        Raises:
            NotImplementedError: If this functionality is not supported.
        """
        raise NotImplementedError("Support for this functionality has not been implemented yet.")

    def get_variables(self, **kwargs):
        """Return all variables discovered in the source code.

        Returns:
            Any: Implementation-defined variable view.

        Raises:
            NotImplementedError: If this functionality is not supported.
        """
        raise NotImplementedError("Support for this functionality has not been implemented yet.")

    def get_service_entry_point_classes(self, **kwargs):
        """Return all service entry-point classes.

        Returns:
            Any: Implementation-defined list or mapping of service classes.

        Raises:
            NotImplementedError: If this functionality is not supported.
        """
        raise NotImplementedError("Support for this functionality has not been implemented yet.")

    def get_service_entry_point_methods(self, **kwargs):
        """Return all service entry-point methods.

        Returns:
            Any: Implementation-defined list or mapping of service methods.

        Raises:
            NotImplementedError: If this functionality is not supported.
        """
        raise NotImplementedError("Support for this functionality has not been implemented yet.")

    def get_application_view(self) -> JApplication:
        """Return the application view of the Java code.

        Returns:
            JApplication: Application view of the Java code.

        Raises:
            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
        """
        if self.source_code:
            raise NotImplementedError("Support for this functionality has not been implemented yet.")
        return self.backend.get_application_view()

    def get_symbol_table(self) -> Dict[str, JCompilationUnit]:
        """Return the symbol table.

        Returns:
            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)  # doctest: +SKIP
            True
        """
        return self.backend.get_symbol_table()

    def get_compilation_units(self) -> List[JCompilationUnit]:
        """Return all compilation units in the Java code.

        Returns:
            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)  # doctest: +SKIP
            True
        """
        return self.backend.get_compilation_units()

    def get_class_hierarchy(self) -> nx.DiGraph:
        """Return the class hierarchy of the Java code.

        Returns:
            networkx.DiGraph: Class hierarchy.

        Raises:
            NotImplementedError: Always, as the feature is not implemented yet.
        """

        raise NotImplementedError("Class hierarchy is not implemented yet.")

    def is_parsable(self, source_code: str) -> bool:
        """Check if the source code is parsable.

        Args:
            source_code (str): Source code to parse.

        Returns:
            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
        """
        return self.treesitter_java.is_parsable(source_code)

    def get_raw_ast(self, source_code: str) -> Tree:
        """Parse and return the raw AST.

        Args:
            source_code (str): Source code to parse.

        Returns:
            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
        """
        return self.treesitter_java.get_raw_ast(source_code)

    def get_call_graph(self) -> nx.DiGraph:
        """Return the call graph of the Java code.

        Returns:
            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)  # doctest: +SKIP
            True
        """
        return self.backend.get_call_graph()

    def get_call_graph_json(self) -> str:
        """Return the call graph serialized as JSON.

        Returns:
            str: Call graph encoded as JSON.

        Raises:
            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)  # doctest: +SKIP
            True
        """
        if self.source_code:
            raise NotImplementedError("Producing a call graph over a single file is not implemented yet.")
        return self.backend.get_call_graph_json()

    def get_callers(self, target_class_name: str, target_method_declaration: str, using_symbol_table: bool = False) -> Dict:
        """Return all callers of a target method.

        Args:
            target_class_name (str): Qualified name of the target class.
            target_method_declaration (str): Target method signature.
            using_symbol_table (bool): Whether to use the symbol table. Defaults to False.

        Returns:
            dict: Mapping of callers to call sites/details.

        Raises:
            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()')  # doctest: +SKIP
            >>> isinstance(callers, dict)  # doctest: +SKIP
            True
        """

        if self.source_code:
            raise NotImplementedError("Generating all callers over a single file is not implemented yet.")
        return self.backend.get_all_callers(target_class_name, target_method_declaration, using_symbol_table)

    def get_callees(self, source_class_name: str, source_method_declaration: str, using_symbol_table: bool = False) -> Dict:
        """Return all callees of a given method.

        Args:
            source_class_name (str): Qualified class name containing the method.
            source_method_declaration (str): Method signature.
            using_symbol_table (bool): Whether to use the symbol table. Defaults to False.

        Returns:
            dict: Mapping of callees to call sites/details.

        Raises:
            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()')  # doctest: +SKIP
            >>> isinstance(callees, dict)  # doctest: +SKIP
            True
        """
        if self.source_code:
            raise NotImplementedError("Generating all callees over a single file is not implemented yet.")
        return self.backend.get_all_callees(source_class_name, source_method_declaration, using_symbol_table)

    def get_methods(self) -> Dict[str, Dict[str, JCallable]]:
        """Return all methods in the Java code.

        Returns:
            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()  # doctest: +SKIP
            >>> isinstance(methods, dict)  # doctest: +SKIP
            True
        """
        return self.backend.get_all_methods_in_application()

    def get_classes(self) -> Dict[str, JType]:
        """Return all classes in the Java code.

        Returns:
            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()  # doctest: +SKIP
            >>> isinstance(classes, dict)  # doctest: +SKIP
            True
        """
        return self.backend.get_all_classes()

    def get_classes_by_criteria(self, inclusions=None, exclusions=None) -> Dict[str, JType]:
        """Return classes filtered by simple inclusion/exclusion criteria.

        Args:
            inclusions (list[str] | None): If provided, only classes whose name
                contains any of these substrings are included.
            exclusions (list[str] | None): If provided, classes whose name contains
                any of these substrings are excluded.

        Returns:
            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'])  # doctest: +SKIP
            >>> isinstance(filtered, dict)  # doctest: +SKIP
            True
        """
        if exclusions is None:
            exclusions = []
        if inclusions is None:
            inclusions = []
        class_dict: Dict[str, JType] = {}
        all_classes = self.backend.get_all_classes()
        for application_class in all_classes:
            is_selected = False
            for inclusion in inclusions:
                if inclusion in application_class:
                    is_selected = True

            for exclusion in exclusions:
                if exclusion in application_class:
                    is_selected = False
            if is_selected:
                class_dict[application_class] = all_classes[application_class]
        return class_dict

    def get_class(self, qualified_class_name: str) -> JType:
        """Return a class object.

        Args:
            qualified_class_name (str): Qualified class name.

        Returns:
            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')  # doctest: +SKIP
            >>> c is not None  # doctest: +SKIP
            True
        """

        return self.backend.get_class(qualified_class_name)

    def get_method(self, qualified_class_name: str, qualified_method_name: str) -> JCallable:
        """Return a method object.

        Args:
            qualified_class_name (str): Qualified class name.
            qualified_method_name (str): Qualified method name.

        Returns:
            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()')  # doctest: +SKIP
            >>> m is not None  # doctest: +SKIP
            True
        """
        return self.backend.get_method(qualified_class_name, qualified_method_name)

    def get_method_parameters(self, qualified_class_name: str, qualified_method_name: str) -> List[str]:
        """Return the parameter types/names for a method.

        Args:
            qualified_class_name (str): Qualified class name.
            qualified_method_name (str): Qualified method name.

        Returns:
            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)')  # doctest: +SKIP
            >>> isinstance(params, list)  # doctest: +SKIP
            True
        """
        return self.backend.get_method_parameters(qualified_class_name, qualified_method_name)

    def get_java_file(self, qualified_class_name: str) -> str:
        """Return the Java file path containing a class.

        Args:
            qualified_class_name (str): Qualified class name.

        Returns:
            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')  # doctest: +SKIP
            >>> isinstance(path, str)  # doctest: +SKIP
            True
        """
        return self.backend.get_java_file(qualified_class_name)

    def get_java_compilation_unit(self, file_path: str) -> JCompilationUnit:
        """Return the compilation unit for a Java source file.

        Args:
            file_path (str): Absolute path to a Java source file.

        Returns:
            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')  # doctest: +SKIP
            >>> cu is not None  # doctest: +SKIP
            True
        """
        return self.backend.get_java_compilation_unit(file_path)

    def get_methods_in_class(self, qualified_class_name) -> Dict[str, JCallable]:
        """Return all methods of a class.

        Args:
            qualified_class_name (str): Qualified class name.

        Returns:
            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')  # doctest: +SKIP
            >>> isinstance(methods, dict)  # doctest: +SKIP
            True
        """
        return self.backend.get_all_methods_in_class(qualified_class_name)

    def get_constructors(self, qualified_class_name) -> Dict[str, JCallable]:
        """Return all constructors of a class.

        Args:
            qualified_class_name (str): Qualified class name.

        Returns:
            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')  # doctest: +SKIP
            >>> isinstance(ctors, dict)  # doctest: +SKIP
            True
        """
        return self.backend.get_all_constructors(qualified_class_name)

    def get_fields(self, qualified_class_name) -> List[JField]:
        """Return all fields of a class.

        Args:
            qualified_class_name (str): Qualified class name.

        Returns:
            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')  # doctest: +SKIP
            >>> isinstance(fields, list)  # doctest: +SKIP
            True
        """
        return self.backend.get_all_fields(qualified_class_name)

    def get_nested_classes(self, qualified_class_name) -> List[JType]:
        """Return all nested classes of a class.

        Args:
            qualified_class_name (str): Qualified class name.

        Returns:
            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')  # doctest: +SKIP
            >>> isinstance(nested, list)  # doctest: +SKIP
            True
        """
        return self.backend.get_all_nested_classes(qualified_class_name)

    def get_sub_classes(self, qualified_class_name) -> Dict[str, JType]:
        """Return all subclasses of a class.

        Args:
            qualified_class_name (str): Qualified class name.

        Returns:
            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')  # doctest: +SKIP
            >>> isinstance(subs, dict)  # doctest: +SKIP
            True
        """
        return self.backend.get_all_sub_classes(qualified_class_name=qualified_class_name)

    def get_extended_classes(self, qualified_class_name) -> List[str]:
        """Return all extended superclasses for a class.

        Args:
            qualified_class_name (str): Qualified class name.

        Returns:
            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')  # doctest: +SKIP
            >>> isinstance(supers, list)  # doctest: +SKIP
            True
        """
        return self.backend.get_extended_classes(qualified_class_name)

    def get_implemented_interfaces(self, qualified_class_name: str) -> List[str]:
        """Return all implemented interfaces for a class.

        Args:
            qualified_class_name (str): Qualified class name.

        Returns:
            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')  # doctest: +SKIP
            >>> isinstance(ifaces, list)  # doctest: +SKIP
            True
        """
        return self.backend.get_implemented_interfaces(qualified_class_name)

    def __get_class_call_graph_using_symbol_table(self, qualified_class_name: str, method_signature: str | None = None) -> (List)[Tuple[JMethodDetail, JMethodDetail]]:
        """Return class-level call graph using the symbol table.

        Args:
            qualified_class_name (str): Qualified class name.
            method_signature (str | None): Optional method signature to scope the graph.

        Returns:
            list[tuple[JMethodDetail, JMethodDetail]]: Edge list of caller -> callee.
        """
        return self.backend.get_class_call_graph_using_symbol_table(qualified_class_name, method_signature)

    def get_class_call_graph(self, qualified_class_name: str, method_signature: str | None = None, using_symbol_table: bool = False) -> List[Tuple[JMethodDetail, JMethodDetail]]:
        """Return a class-level call graph.

        Args:
            qualified_class_name (str): Qualified class name.
            method_signature (str | None): Optional method signature to scope the graph.
            using_symbol_table (bool): If True, use the symbol table for resolution.

        Returns:
            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')  # doctest: +SKIP
            >>> isinstance(edges, list)  # doctest: +SKIP
            True
        """
        if using_symbol_table:
            return self.__get_class_call_graph_using_symbol_table(qualified_class_name=qualified_class_name, method_signature=method_signature)
        return self.backend.get_class_call_graph(qualified_class_name, method_signature)

    def get_entry_point_classes(self) -> Dict[str, JType]:
        """Return all entry-point classes.

        Returns:
            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()  # doctest: +SKIP
            >>> isinstance(eps, dict)  # doctest: +SKIP
            True
        """
        return self.backend.get_all_entry_point_classes()

    def get_entry_point_methods(self) -> Dict[str, Dict[str, JCallable]]:
        """Return all entry-point methods grouped by class.

        Returns:
            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()  # doctest: +SKIP
            >>> isinstance(epms, dict)  # doctest: +SKIP
            True
        """
        return self.backend.get_all_entry_point_methods()

    def remove_all_comments(self) -> str:
        """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\n void f(){} }'.replace('\n', ' ')
            >>> ja = CLDK(language="java").analysis(source_code=src)
            >>> cleaned = ja.remove_all_comments()  # doctest: +SKIP
            >>> '/*' in cleaned or '//' in cleaned  # doctest: +SKIP
            False
        """
        return self.backend.remove_all_comments(self.source_code)

    def get_methods_with_annotations(self, annotations: List[str]) -> Dict[str, List[Dict]]:
        """Return methods grouped by the given annotations.

        Args:
            annotations (list[str]): Annotations to search for.

        Returns:
            dict[str, list[dict]]: Methods and bodies keyed by annotation.

        Raises:
            NotImplementedError: This functionality is not implemented yet.
        """
        # TODO: This call is missing some implementation. The logic currently resides in java_sitter but tree_sitter will no longer be option, rather it will be default and common. Need to implement this differently. Somthing like, self.commons.treesitter.get_methods_with_annotations(annotations)
        raise NotImplementedError("Support for this functionality has not been implemented yet.")

    def get_test_methods(self) -> Dict[str, str]:
        """Return test methods discovered in the source code.

        Returns:
            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()  # doctest: +SKIP
            >>> isinstance(tests, dict)  # doctest: +SKIP
            True
        """

        return self.treesitter_java.get_test_methods(source_class_code=self.source_code)

    def get_calling_lines(self, target_method_name: str) -> List[int]:
        """Return line numbers where a target method is called within a method body.

        Args:
            target_method_name (str): Target method name.

        Returns:
            list[int]: Line numbers within the source method code block.

        Raises:
            NotImplementedError: This functionality is not implemented yet.
        """
        raise NotImplementedError("Support for this functionality has not been implemented yet.")

    def get_call_targets(self, declared_methods: dict) -> Set[str]:
        """Return call targets using simple name resolution over the AST.

        Args:
            declared_methods (dict): All methods declared in the class.

        Returns:
            set[str]: Discovered call targets.

        Raises:
            NotImplementedError: This functionality is not implemented yet.
        """
        raise NotImplementedError("Support for this functionality has not been implemented yet.")

    def get_all_crud_operations(self) -> List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]:
        """Return all CRUD operations in the source code.

        Returns:
            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()  # doctest: +SKIP
            >>> isinstance(ops, list)  # doctest: +SKIP
            True
        """
        return self.backend.get_all_crud_operations()

    def get_all_create_operations(self) -> List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]:
        """Return all create operations in the source code.

        Returns:
            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()  # doctest: +SKIP
            >>> isinstance(creates, list)  # doctest: +SKIP
            True
        """
        return self.backend.get_all_create_operations()

    def get_all_read_operations(self) -> List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]:
        """Return all read operations in the source code.

        Returns:
            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()  # doctest: +SKIP
            >>> isinstance(reads, list)  # doctest: +SKIP
            True
        """
        return self.backend.get_all_read_operations()

    def get_all_update_operations(self) -> List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]:
        """Return all update operations in the source code.

        Returns:
            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()  # doctest: +SKIP
            >>> isinstance(updates, list)  # doctest: +SKIP
            True
        """
        return self.backend.get_all_update_operations()

    def get_all_delete_operations(self) -> List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]:
        """Return all delete operations in the source code.

        Returns:
            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()  # doctest: +SKIP
            >>> isinstance(deletes, list)  # doctest: +SKIP
            True
        """
        return self.backend.get_all_delete_operations()

    # Some APIs to process comments
    def get_comments_in_a_method(self, qualified_class_name: str, method_signature: str) -> List[JComment]:
        """Return all comments in a method.

        Args:
            qualified_class_name (str): Qualified class name.
            method_signature (str): Method signature.

        Returns:
            list[JComment]: Comments in the method.
        """
        return self.backend.get_comments_in_a_method(qualified_class_name, method_signature)

    def get_comments_in_a_class(self, qualified_class_name: str) -> List[JComment]:
        """Return all comments in a class.

        Args:
            qualified_class_name (str): Qualified class name.

        Returns:
            list[JComment]: Comments in the class.
        """
        return self.backend.get_comments_in_a_class(qualified_class_name)

    def get_comment_in_file(self, file_path: str) -> List[JComment]:
        """Return all comments in a file.

        Args:
            file_path (str): Absolute file path.

        Returns:
            list[JComment]: Comments in the file.
        """
        return self.backend.get_comment_in_file(file_path)

    def get_all_comments(self) -> Dict[str, List[JComment]]:
        """Return all comments grouped by file.

        Returns:
            dict[str, list[JComment]]: Mapping of file path to comments.
        """
        return self.backend.get_all_comments()

    def get_all_docstrings(self) -> Dict[str, List[JComment]]:
        """Return all docstrings grouped by file.

        Returns:
            dict[str, list[JComment]]: Mapping of file path to docstrings.
        """
        return self.backend.get_all_docstrings()

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
def get_imports(self) -> List[str]:
    """Return all import statements in the source code.

    Returns:
        list[str]: All import statements.

    Raises:
        NotImplementedError: If this functionality is not supported.
    """
    raise NotImplementedError("Support for this functionality has not been implemented yet.")

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
def get_variables(self, **kwargs):
    """Return all variables discovered in the source code.

    Returns:
        Any: Implementation-defined variable view.

    Raises:
        NotImplementedError: If this functionality is not supported.
    """
    raise NotImplementedError("Support for this functionality has not been implemented yet.")

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
def get_service_entry_point_classes(self, **kwargs):
    """Return all service entry-point classes.

    Returns:
        Any: Implementation-defined list or mapping of service classes.

    Raises:
        NotImplementedError: If this functionality is not supported.
    """
    raise NotImplementedError("Support for this functionality has not been implemented yet.")

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
def get_service_entry_point_methods(self, **kwargs):
    """Return all service entry-point methods.

    Returns:
        Any: Implementation-defined list or mapping of service methods.

    Raises:
        NotImplementedError: If this functionality is not supported.
    """
    raise NotImplementedError("Support for this functionality has not been implemented yet.")

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
def get_application_view(self) -> JApplication:
    """Return the application view of the Java code.

    Returns:
        JApplication: Application view of the Java code.

    Raises:
        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
    """
    if self.source_code:
        raise NotImplementedError("Support for this functionality has not been implemented yet.")
    return self.backend.get_application_view()

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
def get_symbol_table(self) -> Dict[str, JCompilationUnit]:
    """Return the symbol table.

    Returns:
        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)  # doctest: +SKIP
        True
    """
    return self.backend.get_symbol_table()

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
def get_compilation_units(self) -> List[JCompilationUnit]:
    """Return all compilation units in the Java code.

    Returns:
        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)  # doctest: +SKIP
        True
    """
    return self.backend.get_compilation_units()

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
def get_class_hierarchy(self) -> nx.DiGraph:
    """Return the class hierarchy of the Java code.

    Returns:
        networkx.DiGraph: Class hierarchy.

    Raises:
        NotImplementedError: Always, as the feature is not implemented yet.
    """

    raise NotImplementedError("Class hierarchy is not implemented yet.")

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
def is_parsable(self, source_code: str) -> bool:
    """Check if the source code is parsable.

    Args:
        source_code (str): Source code to parse.

    Returns:
        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
    """
    return self.treesitter_java.is_parsable(source_code)

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
def get_raw_ast(self, source_code: str) -> Tree:
    """Parse and return the raw AST.

    Args:
        source_code (str): Source code to parse.

    Returns:
        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
    """
    return self.treesitter_java.get_raw_ast(source_code)

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
def get_call_graph(self) -> nx.DiGraph:
    """Return the call graph of the Java code.

    Returns:
        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)  # doctest: +SKIP
        True
    """
    return self.backend.get_call_graph()

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
def get_call_graph_json(self) -> str:
    """Return the call graph serialized as JSON.

    Returns:
        str: Call graph encoded as JSON.

    Raises:
        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)  # doctest: +SKIP
        True
    """
    if self.source_code:
        raise NotImplementedError("Producing a call graph over a single file is not implemented yet.")
    return self.backend.get_call_graph_json()

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
def get_callers(self, target_class_name: str, target_method_declaration: str, using_symbol_table: bool = False) -> Dict:
    """Return all callers of a target method.

    Args:
        target_class_name (str): Qualified name of the target class.
        target_method_declaration (str): Target method signature.
        using_symbol_table (bool): Whether to use the symbol table. Defaults to False.

    Returns:
        dict: Mapping of callers to call sites/details.

    Raises:
        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()')  # doctest: +SKIP
        >>> isinstance(callers, dict)  # doctest: +SKIP
        True
    """

    if self.source_code:
        raise NotImplementedError("Generating all callers over a single file is not implemented yet.")
    return self.backend.get_all_callers(target_class_name, target_method_declaration, using_symbol_table)

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
def get_callees(self, source_class_name: str, source_method_declaration: str, using_symbol_table: bool = False) -> Dict:
    """Return all callees of a given method.

    Args:
        source_class_name (str): Qualified class name containing the method.
        source_method_declaration (str): Method signature.
        using_symbol_table (bool): Whether to use the symbol table. Defaults to False.

    Returns:
        dict: Mapping of callees to call sites/details.

    Raises:
        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()')  # doctest: +SKIP
        >>> isinstance(callees, dict)  # doctest: +SKIP
        True
    """
    if self.source_code:
        raise NotImplementedError("Generating all callees over a single file is not implemented yet.")
    return self.backend.get_all_callees(source_class_name, source_method_declaration, using_symbol_table)

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
def get_methods(self) -> Dict[str, Dict[str, JCallable]]:
    """Return all methods in the Java code.

    Returns:
        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()  # doctest: +SKIP
        >>> isinstance(methods, dict)  # doctest: +SKIP
        True
    """
    return self.backend.get_all_methods_in_application()

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
def get_classes(self) -> Dict[str, JType]:
    """Return all classes in the Java code.

    Returns:
        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()  # doctest: +SKIP
        >>> isinstance(classes, dict)  # doctest: +SKIP
        True
    """
    return self.backend.get_all_classes()

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
def get_classes_by_criteria(self, inclusions=None, exclusions=None) -> Dict[str, JType]:
    """Return classes filtered by simple inclusion/exclusion criteria.

    Args:
        inclusions (list[str] | None): If provided, only classes whose name
            contains any of these substrings are included.
        exclusions (list[str] | None): If provided, classes whose name contains
            any of these substrings are excluded.

    Returns:
        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'])  # doctest: +SKIP
        >>> isinstance(filtered, dict)  # doctest: +SKIP
        True
    """
    if exclusions is None:
        exclusions = []
    if inclusions is None:
        inclusions = []
    class_dict: Dict[str, JType] = {}
    all_classes = self.backend.get_all_classes()
    for application_class in all_classes:
        is_selected = False
        for inclusion in inclusions:
            if inclusion in application_class:
                is_selected = True

        for exclusion in exclusions:
            if exclusion in application_class:
                is_selected = False
        if is_selected:
            class_dict[application_class] = all_classes[application_class]
    return class_dict

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
def get_class(self, qualified_class_name: str) -> JType:
    """Return a class object.

    Args:
        qualified_class_name (str): Qualified class name.

    Returns:
        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')  # doctest: +SKIP
        >>> c is not None  # doctest: +SKIP
        True
    """

    return self.backend.get_class(qualified_class_name)

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
def get_method(self, qualified_class_name: str, qualified_method_name: str) -> JCallable:
    """Return a method object.

    Args:
        qualified_class_name (str): Qualified class name.
        qualified_method_name (str): Qualified method name.

    Returns:
        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()')  # doctest: +SKIP
        >>> m is not None  # doctest: +SKIP
        True
    """
    return self.backend.get_method(qualified_class_name, qualified_method_name)

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
def get_method_parameters(self, qualified_class_name: str, qualified_method_name: str) -> List[str]:
    """Return the parameter types/names for a method.

    Args:
        qualified_class_name (str): Qualified class name.
        qualified_method_name (str): Qualified method name.

    Returns:
        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)')  # doctest: +SKIP
        >>> isinstance(params, list)  # doctest: +SKIP
        True
    """
    return self.backend.get_method_parameters(qualified_class_name, qualified_method_name)

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
def get_java_file(self, qualified_class_name: str) -> str:
    """Return the Java file path containing a class.

    Args:
        qualified_class_name (str): Qualified class name.

    Returns:
        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')  # doctest: +SKIP
        >>> isinstance(path, str)  # doctest: +SKIP
        True
    """
    return self.backend.get_java_file(qualified_class_name)

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
def get_java_compilation_unit(self, file_path: str) -> JCompilationUnit:
    """Return the compilation unit for a Java source file.

    Args:
        file_path (str): Absolute path to a Java source file.

    Returns:
        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')  # doctest: +SKIP
        >>> cu is not None  # doctest: +SKIP
        True
    """
    return self.backend.get_java_compilation_unit(file_path)

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
def get_methods_in_class(self, qualified_class_name) -> Dict[str, JCallable]:
    """Return all methods of a class.

    Args:
        qualified_class_name (str): Qualified class name.

    Returns:
        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')  # doctest: +SKIP
        >>> isinstance(methods, dict)  # doctest: +SKIP
        True
    """
    return self.backend.get_all_methods_in_class(qualified_class_name)

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
def get_constructors(self, qualified_class_name) -> Dict[str, JCallable]:
    """Return all constructors of a class.

    Args:
        qualified_class_name (str): Qualified class name.

    Returns:
        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')  # doctest: +SKIP
        >>> isinstance(ctors, dict)  # doctest: +SKIP
        True
    """
    return self.backend.get_all_constructors(qualified_class_name)

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
def get_fields(self, qualified_class_name) -> List[JField]:
    """Return all fields of a class.

    Args:
        qualified_class_name (str): Qualified class name.

    Returns:
        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')  # doctest: +SKIP
        >>> isinstance(fields, list)  # doctest: +SKIP
        True
    """
    return self.backend.get_all_fields(qualified_class_name)

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
def get_nested_classes(self, qualified_class_name) -> List[JType]:
    """Return all nested classes of a class.

    Args:
        qualified_class_name (str): Qualified class name.

    Returns:
        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')  # doctest: +SKIP
        >>> isinstance(nested, list)  # doctest: +SKIP
        True
    """
    return self.backend.get_all_nested_classes(qualified_class_name)

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
def get_sub_classes(self, qualified_class_name) -> Dict[str, JType]:
    """Return all subclasses of a class.

    Args:
        qualified_class_name (str): Qualified class name.

    Returns:
        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')  # doctest: +SKIP
        >>> isinstance(subs, dict)  # doctest: +SKIP
        True
    """
    return self.backend.get_all_sub_classes(qualified_class_name=qualified_class_name)

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
def get_extended_classes(self, qualified_class_name) -> List[str]:
    """Return all extended superclasses for a class.

    Args:
        qualified_class_name (str): Qualified class name.

    Returns:
        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')  # doctest: +SKIP
        >>> isinstance(supers, list)  # doctest: +SKIP
        True
    """
    return self.backend.get_extended_classes(qualified_class_name)

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
def get_implemented_interfaces(self, qualified_class_name: str) -> List[str]:
    """Return all implemented interfaces for a class.

    Args:
        qualified_class_name (str): Qualified class name.

    Returns:
        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')  # doctest: +SKIP
        >>> isinstance(ifaces, list)  # doctest: +SKIP
        True
    """
    return self.backend.get_implemented_interfaces(qualified_class_name)

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
def get_class_call_graph(self, qualified_class_name: str, method_signature: str | None = None, using_symbol_table: bool = False) -> List[Tuple[JMethodDetail, JMethodDetail]]:
    """Return a class-level call graph.

    Args:
        qualified_class_name (str): Qualified class name.
        method_signature (str | None): Optional method signature to scope the graph.
        using_symbol_table (bool): If True, use the symbol table for resolution.

    Returns:
        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')  # doctest: +SKIP
        >>> isinstance(edges, list)  # doctest: +SKIP
        True
    """
    if using_symbol_table:
        return self.__get_class_call_graph_using_symbol_table(qualified_class_name=qualified_class_name, method_signature=method_signature)
    return self.backend.get_class_call_graph(qualified_class_name, method_signature)

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
def get_entry_point_classes(self) -> Dict[str, JType]:
    """Return all entry-point classes.

    Returns:
        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()  # doctest: +SKIP
        >>> isinstance(eps, dict)  # doctest: +SKIP
        True
    """
    return self.backend.get_all_entry_point_classes()

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
def get_entry_point_methods(self) -> Dict[str, Dict[str, JCallable]]:
    """Return all entry-point methods grouped by class.

    Returns:
        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()  # doctest: +SKIP
        >>> isinstance(epms, dict)  # doctest: +SKIP
        True
    """
    return self.backend.get_all_entry_point_methods()

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
def remove_all_comments(self) -> str:
    """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\n void f(){} }'.replace('\n', ' ')
        >>> ja = CLDK(language="java").analysis(source_code=src)
        >>> cleaned = ja.remove_all_comments()  # doctest: +SKIP
        >>> '/*' in cleaned or '//' in cleaned  # doctest: +SKIP
        False
    """
    return self.backend.remove_all_comments(self.source_code)

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
def get_methods_with_annotations(self, annotations: List[str]) -> Dict[str, List[Dict]]:
    """Return methods grouped by the given annotations.

    Args:
        annotations (list[str]): Annotations to search for.

    Returns:
        dict[str, list[dict]]: Methods and bodies keyed by annotation.

    Raises:
        NotImplementedError: This functionality is not implemented yet.
    """
    # TODO: This call is missing some implementation. The logic currently resides in java_sitter but tree_sitter will no longer be option, rather it will be default and common. Need to implement this differently. Somthing like, self.commons.treesitter.get_methods_with_annotations(annotations)
    raise NotImplementedError("Support for this functionality has not been implemented yet.")

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
def get_test_methods(self) -> Dict[str, str]:
    """Return test methods discovered in the source code.

    Returns:
        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()  # doctest: +SKIP
        >>> isinstance(tests, dict)  # doctest: +SKIP
        True
    """

    return self.treesitter_java.get_test_methods(source_class_code=self.source_code)

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
def get_calling_lines(self, target_method_name: str) -> List[int]:
    """Return line numbers where a target method is called within a method body.

    Args:
        target_method_name (str): Target method name.

    Returns:
        list[int]: Line numbers within the source method code block.

    Raises:
        NotImplementedError: This functionality is not implemented yet.
    """
    raise NotImplementedError("Support for this functionality has not been implemented yet.")

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
def get_call_targets(self, declared_methods: dict) -> Set[str]:
    """Return call targets using simple name resolution over the AST.

    Args:
        declared_methods (dict): All methods declared in the class.

    Returns:
        set[str]: Discovered call targets.

    Raises:
        NotImplementedError: This functionality is not implemented yet.
    """
    raise NotImplementedError("Support for this functionality has not been implemented yet.")

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
def get_all_crud_operations(self) -> List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]:
    """Return all CRUD operations in the source code.

    Returns:
        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()  # doctest: +SKIP
        >>> isinstance(ops, list)  # doctest: +SKIP
        True
    """
    return self.backend.get_all_crud_operations()

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
def get_all_create_operations(self) -> List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]:
    """Return all create operations in the source code.

    Returns:
        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()  # doctest: +SKIP
        >>> isinstance(creates, list)  # doctest: +SKIP
        True
    """
    return self.backend.get_all_create_operations()

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
def get_all_read_operations(self) -> List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]:
    """Return all read operations in the source code.

    Returns:
        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()  # doctest: +SKIP
        >>> isinstance(reads, list)  # doctest: +SKIP
        True
    """
    return self.backend.get_all_read_operations()

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
def get_all_update_operations(self) -> List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]:
    """Return all update operations in the source code.

    Returns:
        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()  # doctest: +SKIP
        >>> isinstance(updates, list)  # doctest: +SKIP
        True
    """
    return self.backend.get_all_update_operations()

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
def get_all_delete_operations(self) -> List[Dict[str, Union[JType, JCallable, List[JCRUDOperation]]]]:
    """Return all delete operations in the source code.

    Returns:
        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()  # doctest: +SKIP
        >>> isinstance(deletes, list)  # doctest: +SKIP
        True
    """
    return self.backend.get_all_delete_operations()

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
def get_comments_in_a_method(self, qualified_class_name: str, method_signature: str) -> List[JComment]:
    """Return all comments in a method.

    Args:
        qualified_class_name (str): Qualified class name.
        method_signature (str): Method signature.

    Returns:
        list[JComment]: Comments in the method.
    """
    return self.backend.get_comments_in_a_method(qualified_class_name, method_signature)

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
def get_comments_in_a_class(self, qualified_class_name: str) -> List[JComment]:
    """Return all comments in a class.

    Args:
        qualified_class_name (str): Qualified class name.

    Returns:
        list[JComment]: Comments in the class.
    """
    return self.backend.get_comments_in_a_class(qualified_class_name)

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
def get_comment_in_file(self, file_path: str) -> List[JComment]:
    """Return all comments in a file.

    Args:
        file_path (str): Absolute file path.

    Returns:
        list[JComment]: Comments in the file.
    """
    return self.backend.get_comment_in_file(file_path)

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.

Source code in cldk/analysis/java/java_analysis.py
def get_all_comments(self) -> Dict[str, List[JComment]]:
    """Return all comments grouped by file.

    Returns:
        dict[str, list[JComment]]: Mapping of file path to comments.
    """
    return self.backend.get_all_comments()

get_all_docstrings() #

Return all docstrings grouped by file.

Returns:

Type Description
Dict[str, List[JComment]]

dict[str, list[JComment]]: Mapping of file path to docstrings.

Source code in cldk/analysis/java/java_analysis.py
def get_all_docstrings(self) -> Dict[str, List[JComment]]:
    """Return all docstrings grouped by file.

    Returns:
        dict[str, list[JComment]]: Mapping of file path to docstrings.
    """
    return self.backend.get_all_docstrings()

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
class JComment(BaseModel):
    """Represents a comment in Java code.

    Attributes:
        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.
    """

    content: str | None = None
    start_line: int = -1
    end_line: int = -1
    start_column: int = -1
    end_column: int = -1
    is_javadoc: bool = False

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
class JRecordComponent(BaseModel):
    """Represents a component of a Java record.

    Attributes:
        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.
    """

    comment: JComment | None
    name: str
    type: str
    modifiers: List[str]
    annotations: List[str]
    default_value: Union[str, None, Any] = None
    is_var_args: bool = False

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
class JField(BaseModel):
    """Represents a field in a Java class or interface.

    Attributes:
        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.
    """

    comment: JComment | None
    type: str
    start_line: int
    end_line: int
    variables: List[str]
    modifiers: List[str]
    annotations: List[str]

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
class JCallableParameter(BaseModel):
    """Represents a parameter of a Java callable.

    Attributes:
        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.
    """

    name: str | None
    type: str
    annotations: List[str]
    modifiers: List[str]
    start_line: int
    end_line: int
    start_column: int
    end_column: int

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
class JEnumConstant(BaseModel):
    """Represents a constant in an enumeration.

    Attributes:
        name (str): The name of the enum constant.
        arguments (List[str]): The arguments associated with the enum constant.
    """

    name: str
    arguments: List[str]

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
class JCRUDOperation(BaseModel):
    """Represents a CRUD operation.

    Attributes:
        line_number (int): The line number of the operation.
        operation_type (JCRUDOperationType): The type of the operation.
    """

    line_number: int
    operation_type: CRUDOperationType | None

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
class JCRUDQuery(BaseModel):
    """Represents a CRUD query.

    Attributes:
        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.
    """

    line_number: int
    query_arguments: List[str] | None
    query_type: CRUDQueryType | None

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
class JCallSite(BaseModel):
    """Represents a call site.

    Attributes:
        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.
    """

    comment: JComment | None
    method_name: str
    receiver_expr: str = ""
    receiver_type: str
    argument_types: List[str]
    argument_expr: List[str]
    return_type: str = ""
    callee_signature: str = ""
    is_static_call: bool | None = None
    is_private: bool | None = None
    is_public: bool | None = None
    is_protected: bool | None = None
    is_unspecified: bool | None = None
    is_constructor_call: bool
    crud_operation: JCRUDOperation | None
    crud_query: JCRUDQuery | None
    start_line: int
    start_column: int
    end_line: int
    end_column: int

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
class JVariableDeclaration(BaseModel):
    """Represents a variable declaration.

    Attributes:
        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.
    """

    comment: JComment | None
    name: str
    type: str
    initializer: str
    start_line: int
    start_column: int
    end_line: int
    end_column: int

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
class InitializationBlock(BaseModel):
    """Represents an initialization block in Java.

    Attributes:
        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.
    """

    file_path: str
    comments: List[JComment]
    annotations: List[str]
    thrown_exceptions: List[str]
    code: str
    start_line: int
    end_line: int
    is_static: bool
    referenced_types: List[str]
    accessed_fields: List[str]
    call_sites: List[JCallSite]
    variable_declarations: List[JVariableDeclaration]
    cyclomatic_complexity: int

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
class JCallable(BaseModel):
    """Represents a callable entity such as a method or constructor in Java.

    Attributes:
        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.
    """

    signature: str
    is_implicit: bool
    is_constructor: bool
    comments: List[JComment]
    annotations: List[str]
    modifiers: List[str]
    thrown_exceptions: List[str] = []
    declaration: str
    parameters: List[JCallableParameter]
    return_type: Optional[str] = None  # Pythonic way to denote a nullable field
    code: str
    start_line: int
    end_line: int
    code_start_line: int
    referenced_types: List[str]
    accessed_fields: List[str]
    call_sites: List[JCallSite]
    is_entrypoint: bool = False
    variable_declarations: List[JVariableDeclaration]
    crud_operations: List[JCRUDOperation] | None
    crud_queries: List[JCRUDQuery] | None
    cyclomatic_complexity: int | None

    def __hash__(self):
        """
        Returns the hash value of the declaration.
        """
        return hash(self.declaration)

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
class JType(BaseModel):
    """Represents a Java class or interface.

    Attributes:
        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.
    """

    is_interface: bool = False
    is_inner_class: bool = False
    is_local_class: bool = False
    is_nested_type: bool = False
    is_class_or_interface_declaration: bool = False
    is_enum_declaration: bool = False
    is_annotation_declaration: bool = False
    is_record_declaration: bool = False
    is_concrete_class: bool = False
    comments: List[JComment] | None = []
    extends_list: List[str] | None = []
    implements_list: List[str] | None = []
    modifiers: List[str] | None = []
    annotations: List[str] | None = []
    parent_type: str
    nested_type_declarations: List[str] | None = []
    callable_declarations: Dict[str, JCallable] = {}
    field_declarations: List[JField] = []
    enum_constants: List[JEnumConstant] | None = []
    record_components: List[JRecordComponent] | None = []
    initialization_blocks: List[InitializationBlock] | None = []
    is_entrypoint_class: bool = False

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
class JCompilationUnit(BaseModel):
    """Represents a compilation unit in Java.

    Attributes:
        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.
    """

    file_path: str
    package_name: str
    comments: List[JComment]
    imports: List[str]
    type_declarations: Dict[str, JType]
    is_modified: bool = False

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
class JMethodDetail(BaseModel):
    """Represents details about a method in a Java class.

    Attributes:
        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.
    """

    method_declaration: str
    # class is a reserved keyword in python. we'll use klass.
    klass: str
    method: JCallable

    def __repr__(self):
        return f"JMethodDetail({self.method_declaration})"

    def __hash__(self):
        return hash(tuple(self))

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
class JGraphEdgesST(BaseModel):
    """Represents an edge in a graph structure for method dependencies.

    Attributes:
        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: JMethodDetail
    target: JMethodDetail
    type: str
    weight: str
    source_kind: str | None = None
    destination_kind: str | None = None

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.

Source code in cldk/models/java/models.py
class JApplication(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.
    """

    symbol_table: Dict[str, JCompilationUnit]
    call_graph: List[JGraphEdges] = None
    system_dependency_graph: List[JGraphEdges] = None

    @field_validator("symbol_table", mode="after")
    @classmethod
    def validate_source(cls, symbol_table) -> Dict[str, JCompilationUnit]:
        # Populate the lookup table for callables
        for _, j_compulation_unit in symbol_table.items():
            for type_declaration, jtype in j_compulation_unit.type_declarations.items():
                for __, j_callable in jtype.callable_declarations.items():
                    _CALLABLES_LOOKUP_TABLE[(type_declaration, j_callable.signature)] = j_callable

        return symbol_table