From 913e9f12ff23f70ef98f9dbea4aaa8148561a70f Mon Sep 17 00:00:00 2001 From: Rangeet Pan Date: Mon, 9 Sep 2024 12:31:58 -0400 Subject: [PATCH 1/2] add call for entry point detection code --- cldk/analysis/java/java.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cldk/analysis/java/java.py b/cldk/analysis/java/java.py index 0b02684..e97e547 100644 --- a/cldk/analysis/java/java.py +++ b/cldk/analysis/java/java.py @@ -83,10 +83,14 @@ def get_variables(self, **kwargs): raise NotImplementedError(f"Support for this functionality has not been implemented yet.") def get_service_entry_point_classes(self, **kwargs): - raise NotImplementedError(f"Support for this functionality has not been implemented yet.") + if self.analysis_backend in [AnalysisEngine.CODEQL, AnalysisEngine.TREESITTER]: + raise NotImplementedError(f"Support for this functionality has not been implemented yet.") + return self.get_entry_point_classes() def get_service_entry_point_methods(self, **kwargs): - raise NotImplementedError(f"Support for this functionality has not been implemented yet.") + if self.analysis_backend in [AnalysisEngine.CODEQL, AnalysisEngine.TREESITTER]: + raise NotImplementedError(f"Support for this functionality has not been implemented yet.") + return self.get_service_entry_point_methods() def get_application_view(self) -> JApplication: """ From 2287ec6b68d6e2e03c314ec07a45486f4ac58013 Mon Sep 17 00:00:00 2001 From: Rangeet Pan Date: Mon, 9 Sep 2024 12:35:22 -0400 Subject: [PATCH 2/2] add call for entry point detection code --- cldk/analysis/java/java.py | 58 +++++++++++----------- tests/example.py | 98 -------------------------------------- 2 files changed, 29 insertions(+), 127 deletions(-) delete mode 100644 tests/example.py diff --git a/cldk/analysis/java/java.py b/cldk/analysis/java/java.py index e97e547..419c2ad 100644 --- a/cldk/analysis/java/java.py +++ b/cldk/analysis/java/java.py @@ -85,12 +85,12 @@ def get_variables(self, **kwargs): def get_service_entry_point_classes(self, **kwargs): if self.analysis_backend in [AnalysisEngine.CODEQL, AnalysisEngine.TREESITTER]: raise NotImplementedError(f"Support for this functionality has not been implemented yet.") - return self.get_entry_point_classes() + return self.backend.get_all_entry_point_classes() def get_service_entry_point_methods(self, **kwargs): if self.analysis_backend in [AnalysisEngine.CODEQL, AnalysisEngine.TREESITTER]: raise NotImplementedError(f"Support for this functionality has not been implemented yet.") - return self.get_service_entry_point_methods() + return self.backend.get_all_entry_point_methods() def get_application_view(self) -> JApplication: """ @@ -487,33 +487,33 @@ def get_class_call_graph(self, qualified_class_name: str, method_signature: str raise NotImplementedError(f"Support for this functionality has not been implemented yet.") return self.backend.get_class_call_graph(qualified_class_name, method_signature) - def get_entry_point_classes(self) -> Dict[str, JType]: - """ - Returns a dictionary of all entry point classes in the Java code. - - Returns: - -------- - Dict[str, JType] - A dict of all entry point classes in the Java code, with qualified class names as keys - """ - if self.analysis_backend in [AnalysisEngine.CODEQL, AnalysisEngine.TREESITTER]: - raise NotImplementedError(f"Support for this functionality has not been implemented yet.") - return self.backend.get_all_entry_point_classes() - - def get_entry_point_methods(self) -> Dict[str, Dict[str, JCallable]]: - """ - Returns a dictionary of all entry point methods in the Java code with - qualified class name as key and dictionary of methods in that class - as value - - Returns: - -------- - Dict[str, Dict[str, JCallable]]: - A dictionary of dictionaries of entry point methods in the Java code. - """ - if self.analysis_backend in [AnalysisEngine.CODEQL, AnalysisEngine.TREESITTER]: - raise NotImplementedError(f"Support for this functionality has not been implemented yet.") - return self.backend.get_all_entry_point_methods() + # def get_entry_point_classes(self) -> Dict[str, JType]: + # """ + # Returns a dictionary of all entry point classes in the Java code. + # + # Returns: + # -------- + # Dict[str, JType] + # A dict of all entry point classes in the Java code, with qualified class names as keys + # """ + # if self.analysis_backend in [AnalysisEngine.CODEQL, AnalysisEngine.TREESITTER]: + # raise NotImplementedError(f"Support for this functionality has not been implemented yet.") + # return self.backend.get_all_entry_point_classes() + # + # def get_entry_point_methods(self) -> Dict[str, Dict[str, JCallable]]: + # """ + # Returns a dictionary of all entry point methods in the Java code with + # qualified class name as key and dictionary of methods in that class + # as value + # + # Returns: + # -------- + # Dict[str, Dict[str, JCallable]]: + # A dictionary of dictionaries of entry point methods in the Java code. + # """ + # if self.analysis_backend in [AnalysisEngine.CODEQL, AnalysisEngine.TREESITTER]: + # raise NotImplementedError(f"Support for this functionality has not been implemented yet.") + # return self.backend.get_all_entry_point_methods() def remove_all_comments(self) -> str: """ diff --git a/tests/example.py b/tests/example.py deleted file mode 100644 index ad612e0..0000000 --- a/tests/example.py +++ /dev/null @@ -1,98 +0,0 @@ -"""Example: Use CLDK to build a code summarization model -""" - -from cldk import CLDK -from cldk.analysis.java import JavaAnalysis - -# Initialize the Codellm-DevKit object with the project directory, language, and analysis_backend. -ns = CLDK( - project_dir="/Users/rajupavuluri/development/sample.daytrader8/", - language="java", - analysis_json_path="/Users/rkrsn/Downloads/sample.daytrader8/", -) - - -# Get the java application view for the project. -java_analysis: JavaAnalysis = ns.get_analysis() - -classes_dict = ns.preprocessing.get_classes() -# print(classes_dict) -entry_point_classes_dict = ns.preprocessing.get_entry_point_classes() -print(entry_point_classes_dict) - -entry_point_methods_dict = ns.preprocessing.get_entry_point_methods() -print(entry_point_methods_dict) - - -# ##get the first class in this dictionary for testing purposes -test_class_name = next(iter(classes_dict)) -print(test_class_name) -test_class = classes_dict[test_class_name] -# print(test_class) -# print(test_class.is_entry_point) - -# constructors = ns.preprocessing.get_all_constructors(test_class_name) -# print(constructors) - -# fields = ns.preprocessing.get_all_fields(test_class_name) -# print("fields :", fields) - -# methods = ns.preprocessing.get_all_methods_in_class(test_class_name) -# # print("number of methods in class ",test_class_name, ": ",len(methods)) -# nested_classes = ns.preprocessing.get_all_nested_classes(test_class_name) -# # print("nested_classes: ",nested_classes) -# extended_classes = ns.preprocessing.get_extended_classes(test_class_name) -# # print("extended_classes: ",extended_classes) -# implemented_interfaces = ns.preprocessing.get_implemented_interfaces( -# test_class_name -# ) -# # print("implemented_interfaces: ",implemented_interfaces) -# class_result = ns.preprocessing.get_class(test_class_name) -# print("class_result: ", class_result) -# java_file_name = ns.preprocessing.get_java_file(test_class_name) -# # print("java_file_name ",java_file_name) -# all_methods = ns.preprocessing.get_all_methods_in_application() -# # print(all_methods) -# method = ns.preprocessing.get_method( -# "com.ibm.websphere.samples.daytrader.util.Log", -# "public static void trace(String message)", -# ) -# print(method) -# # Get the call graph. - -# cg = ns.preprocessing.get_call_graph() -# print(cg) -# # print(ns.preprocessing.get_call_graph_json()) - -# # print(cg.edges) -# # d = ns.preprocessing.get_all_callers("com.ibm.websphere.samples.daytrader.util.Log","public static void trace(String message)") -# # print("caller details::") -# # print(d) -# # v = ns.preprocessing.get_all_callees("com.ibm.websphere.samples.daytrader.impl.ejb3.MarketSummarySingleton","private void updateMarketSummary()") -# # print("callee details::") -# # print(v) - -# """ -# # Get the user specified method. -# method: JCallable = app.get_method("com.example.foo.Bar.baz") # <- User specified method. - -# # Get the slices that contain the method. -# slices: nx.Generator = ns.preprocessing.get_slices_containing_method(method, sdg=app.sdg) - -# # Optional: Get samples for RAG from (say) elasticsearch -# few_shot_samples: List[str] = ns.prompting.rag( -# database={"hostname": "https://localhost:9200", "index": "summarization"} -# ).retrive_few_shot_samples(method=method, slices=slices) - -# # Natively we'll support PDL as the prompting engine to get summaries from the LLM. - -# summaries: List[str] = ns.prompting(engine="pdl").summarize(method, context=slices, few_shot_samples=few_shot_samples) - -# # Optionally, we will also support other open-source engines such as LMQL, Guidance, user defined Jinja, etc. -# summaries: List[str] = ns.prompting(engine="lmql").summarize(slices=slices, few_shot_samples=few_shot_samples) -# summaries: List[str] = ns.prompting(engine="guidance").summarize(slices=slices, few_shot_samples=few_shot_samples) -# summaries: List[str] = ns.prompting(engine="jinja", template="