From 2c79a45464f684209af0960e09e59634d1ab75ea Mon Sep 17 00:00:00 2001 From: John Rofrano Date: Fri, 11 Oct 2024 19:46:20 +0000 Subject: [PATCH 1/5] Added IBM Copyright to the Utils package Signed-off-by: John Rofrano --- cldk/utils/__init__.py | 19 +++++++++++++++ cldk/utils/analysis_engine.py | 23 ++++++++++++++++++- cldk/utils/exceptions/__init__.py | 20 ++++++++++++++++ cldk/utils/logging.py | 19 +++++++++++++++ cldk/utils/sanitization/__init__.py | 19 +++++++++++++++ .../sanitization/java/TreesitterSanitizer.py | 20 ++++++++++++++++ .../sanitization/java/TreesitterUtils.py | 20 ++++++++++++++++ cldk/utils/sanitization/java/__init__.py | 18 +++++++++++++++ cldk/utils/treesitter/__init__.py | 19 +++++++++++++++ cldk/utils/treesitter/tree_sitter_utils.py | 22 +++++++++++++++++- 10 files changed, 197 insertions(+), 2 deletions(-) diff --git a/cldk/utils/__init__.py b/cldk/utils/__init__.py index e69de29..d278d32 100644 --- a/cldk/utils/__init__.py +++ b/cldk/utils/__init__.py @@ -0,0 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Utils package +""" diff --git a/cldk/utils/analysis_engine.py b/cldk/utils/analysis_engine.py index ab169e1..8f93f52 100644 --- a/cldk/utils/analysis_engine.py +++ b/cldk/utils/analysis_engine.py @@ -1,4 +1,25 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Analysis Engine module +""" + + class AnalysisEngine: TREESITTER: str = "treesitter" CODEQL: str = "codeql" - CODEANALYZER: str = "codeanalyzer" \ No newline at end of file + CODEANALYZER: str = "codeanalyzer" diff --git a/cldk/utils/exceptions/__init__.py b/cldk/utils/exceptions/__init__.py index b48e77e..69c370c 100644 --- a/cldk/utils/exceptions/__init__.py +++ b/cldk/utils/exceptions/__init__.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Exceptions package +""" + from .exceptions import ( CldkInitializationException, CodeanalyzerExecutionException, diff --git a/cldk/utils/logging.py b/cldk/utils/logging.py index e69de29..d504cfe 100644 --- a/cldk/utils/logging.py +++ b/cldk/utils/logging.py @@ -0,0 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Logging module +""" diff --git a/cldk/utils/sanitization/__init__.py b/cldk/utils/sanitization/__init__.py index e69de29..97ad2de 100644 --- a/cldk/utils/sanitization/__init__.py +++ b/cldk/utils/sanitization/__init__.py @@ -0,0 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Sanitization package +""" diff --git a/cldk/utils/sanitization/java/TreesitterSanitizer.py b/cldk/utils/sanitization/java/TreesitterSanitizer.py index c4fd41e..43596d3 100644 --- a/cldk/utils/sanitization/java/TreesitterSanitizer.py +++ b/cldk/utils/sanitization/java/TreesitterSanitizer.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Treesitter Sanitizer module +""" + from copy import deepcopy from typing import Dict, List, Set diff --git a/cldk/utils/sanitization/java/TreesitterUtils.py b/cldk/utils/sanitization/java/TreesitterUtils.py index 0ece1d5..4156004 100644 --- a/cldk/utils/sanitization/java/TreesitterUtils.py +++ b/cldk/utils/sanitization/java/TreesitterUtils.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Treesitter Utils module +""" + import re from copy import deepcopy from typing import Dict, List, Any, LiteralString diff --git a/cldk/utils/sanitization/java/__init__.py b/cldk/utils/sanitization/java/__init__.py index 8b13789..b8cf380 100644 --- a/cldk/utils/sanitization/java/__init__.py +++ b/cldk/utils/sanitization/java/__init__.py @@ -1 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ +""" +Java package +""" diff --git a/cldk/utils/treesitter/__init__.py b/cldk/utils/treesitter/__init__.py index e69de29..35f5333 100644 --- a/cldk/utils/treesitter/__init__.py +++ b/cldk/utils/treesitter/__init__.py @@ -0,0 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Tree Sitter package +""" diff --git a/cldk/utils/treesitter/tree_sitter_utils.py b/cldk/utils/treesitter/tree_sitter_utils.py index 967e7f9..bf860cf 100644 --- a/cldk/utils/treesitter/tree_sitter_utils.py +++ b/cldk/utils/treesitter/tree_sitter_utils.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Three Sitter Utils module +""" + from tree_sitter import Query, Node from cldk.models.treesitter import Captures @@ -45,4 +65,4 @@ def safe_ascend(self, node: Node, ascend_count: int) -> Node: if ascend_count == 0: return node else: - return self.safe_ascend(node.parent, ascend_count - 1) \ No newline at end of file + return self.safe_ascend(node.parent, ascend_count - 1) From 17a510e785de7e7fde8df607b7b16004ea828ddb Mon Sep 17 00:00:00 2001 From: John Rofrano Date: Fri, 11 Oct 2024 19:52:41 +0000 Subject: [PATCH 2/5] Added IBM Copyright to cldk.models package Signed-off-by: John Rofrano --- cldk/models/__init__.py | 19 ++++++++++++++ cldk/models/c/__init__.py | 19 ++++++++++++++ cldk/models/c/models.py | 20 +++++++++++++++ cldk/models/go/__init__.py | 19 ++++++++++++++ cldk/models/go/models.py | 20 +++++++++++++++ cldk/models/java/__init__.py | 29 ++++++++++++++++------ cldk/models/java/constants_namespace.py | 33 ++++++++++++++++++++++--- cldk/models/java/models.py | 20 +++++++++++++++ cldk/models/javascript/__init__.py | 19 ++++++++++++++ cldk/models/javascript/models.py | 20 +++++++++++++++ cldk/models/python/__init__.py | 19 ++++++++++++++ cldk/models/python/models.py | 20 +++++++++++++++ cldk/models/treesitter/__init__.py | 20 +++++++++++++++ cldk/models/treesitter/models.py | 20 +++++++++++++++ 14 files changed, 285 insertions(+), 12 deletions(-) diff --git a/cldk/models/__init__.py b/cldk/models/__init__.py index e69de29..e0d98ce 100644 --- a/cldk/models/__init__.py +++ b/cldk/models/__init__.py @@ -0,0 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Models package +""" diff --git a/cldk/models/c/__init__.py b/cldk/models/c/__init__.py index e69de29..a47394b 100644 --- a/cldk/models/c/__init__.py +++ b/cldk/models/c/__init__.py @@ -0,0 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +C package +""" diff --git a/cldk/models/c/models.py b/cldk/models/c/models.py index 10f3d82..8419e52 100644 --- a/cldk/models/c/models.py +++ b/cldk/models/c/models.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Models module +""" + from typing import List, Optional from pydantic import BaseModel diff --git a/cldk/models/go/__init__.py b/cldk/models/go/__init__.py index e69de29..5e39e5c 100644 --- a/cldk/models/go/__init__.py +++ b/cldk/models/go/__init__.py @@ -0,0 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Go package +""" diff --git a/cldk/models/go/models.py b/cldk/models/go/models.py index c741cb4..4d5ce7c 100644 --- a/cldk/models/go/models.py +++ b/cldk/models/go/models.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Models module +""" + from typing import List, Optional from pydantic import BaseModel diff --git a/cldk/models/java/__init__.py b/cldk/models/java/__init__.py index 9904d84..09717c5 100644 --- a/cldk/models/java/__init__.py +++ b/cldk/models/java/__init__.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Java package +""" + from .models import ( JApplication, JCallable, @@ -8,11 +28,4 @@ from .constants_namespace import ConstantsNamespace -__all__ = [ - JApplication, - JCallable, - JType, - JCompilationUnit, - JGraphEdges, - ConstantsNamespace -] +__all__ = [JApplication, JCallable, JType, JCompilationUnit, JGraphEdges, ConstantsNamespace] diff --git a/cldk/models/java/constants_namespace.py b/cldk/models/java/constants_namespace.py index 1f96afc..17c616d 100644 --- a/cldk/models/java/constants_namespace.py +++ b/cldk/models/java/constants_namespace.py @@ -1,16 +1,41 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Constants Namespace module +""" + + class ConstantsNamespace: @property def ENTRY_POINT_SERVLET_CLASSES(self): - return ("javax.servlet.GenericServlet","javax.servlet.Filter","javax.servlet.http.HttpServlet") + return ("javax.servlet.GenericServlet", "javax.servlet.Filter", "javax.servlet.http.HttpServlet") + @property def ENTRY_POINT_METHOD_SERVLET_PARAM_TYPES(self): - return ("javax.servlet.ServletRequest","javax.servlet.ServletResponse","javax.servlet.http.HttpServletRequest","javax.servlet.http.HttpServletResponse") + return ("javax.servlet.ServletRequest", "javax.servlet.ServletResponse", "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse") + @property def ENTRY_POINT_METHOD_JAVAX_WS_ANNOTATIONS(self): return ("javax.ws.rs.POST", "javax.ws.rs.PUT", "javax.ws.rs.GET", "javax.ws.rs.HEAD", "javax.ws.rs.DELETE") + @property def ENTRY_POINT_CLASS_SPRING_ANNOTATIONS(self): - return ("Controller","RestController") + return ("Controller", "RestController") + @property def ENTRY_POINT_METHOD_SPRING_ANNOTATIONS(self): - return ("GetMapping","PathMapping","PostMapping","PutMapping","RequestMapping","DeleteMapping") \ No newline at end of file + return ("GetMapping", "PathMapping", "PostMapping", "PutMapping", "RequestMapping", "DeleteMapping") diff --git a/cldk/models/java/models.py b/cldk/models/java/models.py index 5ea3573..458056b 100644 --- a/cldk/models/java/models.py +++ b/cldk/models/java/models.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Models module +""" + import json import re from typing import Dict, List, Optional diff --git a/cldk/models/javascript/__init__.py b/cldk/models/javascript/__init__.py index e69de29..3dbaddb 100644 --- a/cldk/models/javascript/__init__.py +++ b/cldk/models/javascript/__init__.py @@ -0,0 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +JavaScript package +""" diff --git a/cldk/models/javascript/models.py b/cldk/models/javascript/models.py index fe8e75a..fb66dd9 100644 --- a/cldk/models/javascript/models.py +++ b/cldk/models/javascript/models.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Models module +""" + from typing import List, Optional from pydantic import BaseModel diff --git a/cldk/models/python/__init__.py b/cldk/models/python/__init__.py index e69de29..def0083 100644 --- a/cldk/models/python/__init__.py +++ b/cldk/models/python/__init__.py @@ -0,0 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Python package +""" diff --git a/cldk/models/python/models.py b/cldk/models/python/models.py index 176dcf5..bdaf519 100644 --- a/cldk/models/python/models.py +++ b/cldk/models/python/models.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Models module +""" + from typing import List from pydantic import BaseModel diff --git a/cldk/models/treesitter/__init__.py b/cldk/models/treesitter/__init__.py index 50dae79..c4abf4f 100644 --- a/cldk/models/treesitter/__init__.py +++ b/cldk/models/treesitter/__init__.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Treesitter package +""" + from .models import Captures __all__ = ["Captures"] diff --git a/cldk/models/treesitter/models.py b/cldk/models/treesitter/models.py index 349876d..eb19ea1 100644 --- a/cldk/models/treesitter/models.py +++ b/cldk/models/treesitter/models.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Models module +""" + from dataclasses import dataclass from typing import Dict, List, Tuple from ipdb import set_trace From cc5ea3e47d41da436ea0613335beac6629a6a13e Mon Sep 17 00:00:00 2001 From: John Rofrano Date: Fri, 11 Oct 2024 20:10:11 +0000 Subject: [PATCH 3/5] Added IBM Copyright to the cldk.analysis package source Signed-off-by: John Rofrano --- cldk/analysis/__init__.py | 20 ++ cldk/analysis/analysis_level.py | 21 ++ cldk/analysis/c/__init__.py | 19 ++ cldk/analysis/c/treesitter/__init__.py | 20 ++ cldk/analysis/c/treesitter/c_sitter.py | 20 ++ cldk/analysis/call_graph.py | 20 ++ cldk/analysis/go/__init__.py | 19 ++ cldk/analysis/go/treesitter/__init__.py | 20 ++ cldk/analysis/go/treesitter/go_sitter.py | 20 ++ cldk/analysis/java/__init__.py | 20 ++ cldk/analysis/java/codeanalyzer/__init__.py | 20 ++ .../java/codeanalyzer/bin/__init__.py | 19 ++ .../java/codeanalyzer/codeanalyzer.py | 20 ++ .../java/codeanalyzer/jar/__init__.py | 19 ++ cldk/analysis/java/codeql/__init__.py | 20 ++ cldk/analysis/java/codeql/backend.py | 24 ++- cldk/analysis/java/codeql/codeql.py | 20 ++ cldk/analysis/java/java.py | 186 ++++++++++-------- cldk/analysis/java/treesitter/__init__.py | 23 ++- cldk/analysis/java/treesitter/javasitter.py | 20 ++ cldk/analysis/javascript/__init__.py | 19 ++ .../javascript/treesitter/__init__.py | 20 ++ .../treesitter/javascript_sitter.py | 20 ++ cldk/analysis/program_dependence_graph.py | 20 ++ cldk/analysis/python/__init__.py | 22 ++- cldk/analysis/python/python.py | 38 +++- cldk/analysis/python/treesitter/__init__.py | 20 ++ .../python/treesitter/python_sitter.py | 93 +++++---- cldk/analysis/symbol_table.py | 28 ++- cldk/analysis/system_dependence_graph.py | 22 ++- cldk/utils/exceptions/exceptions.py | 21 ++ cldk/utils/treesitter/__init__.py | 2 +- 32 files changed, 748 insertions(+), 147 deletions(-) diff --git a/cldk/analysis/__init__.py b/cldk/analysis/__init__.py index e702380..171ace3 100644 --- a/cldk/analysis/__init__.py +++ b/cldk/analysis/__init__.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Analysis package +""" + from .call_graph import CallGraph from .program_dependence_graph import ProgramDependenceGraph diff --git a/cldk/analysis/analysis_level.py b/cldk/analysis/analysis_level.py index 1e640af..93dcdf9 100644 --- a/cldk/analysis/analysis_level.py +++ b/cldk/analysis/analysis_level.py @@ -1,8 +1,29 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +AnalysisLevel module +""" + from enum import Enum class AnalysisLevel(str, Enum): """Analysis levels""" + symbol_table = "symbol-table" call_graph = "call-graph" program_dependency_graph = "program-dependency-graph" diff --git a/cldk/analysis/c/__init__.py b/cldk/analysis/c/__init__.py index e69de29..a47394b 100644 --- a/cldk/analysis/c/__init__.py +++ b/cldk/analysis/c/__init__.py @@ -0,0 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +C package +""" diff --git a/cldk/analysis/c/treesitter/__init__.py b/cldk/analysis/c/treesitter/__init__.py index 036c721..aa31c2c 100644 --- a/cldk/analysis/c/treesitter/__init__.py +++ b/cldk/analysis/c/treesitter/__init__.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Treesitter package +""" + from cldk.analysis.c.treesitter.c_sitter import CSitter __all__ = ["CSitter"] diff --git a/cldk/analysis/c/treesitter/c_sitter.py b/cldk/analysis/c/treesitter/c_sitter.py index e3954fd..44e926a 100644 --- a/cldk/analysis/c/treesitter/c_sitter.py +++ b/cldk/analysis/c/treesitter/c_sitter.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +CSitter module +""" + from typing import List from tree_sitter import Language, Parser, Query, Node import tree_sitter_c as tsc diff --git a/cldk/analysis/call_graph.py b/cldk/analysis/call_graph.py index 2901a09..882b72a 100644 --- a/cldk/analysis/call_graph.py +++ b/cldk/analysis/call_graph.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +CallGraph module +""" + from abc import ABC, abstractmethod diff --git a/cldk/analysis/go/__init__.py b/cldk/analysis/go/__init__.py index e69de29..5e39e5c 100644 --- a/cldk/analysis/go/__init__.py +++ b/cldk/analysis/go/__init__.py @@ -0,0 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Go package +""" diff --git a/cldk/analysis/go/treesitter/__init__.py b/cldk/analysis/go/treesitter/__init__.py index 9b2531d..4319921 100644 --- a/cldk/analysis/go/treesitter/__init__.py +++ b/cldk/analysis/go/treesitter/__init__.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Treesitter package +""" + from cldk.analysis.go.treesitter.go_sitter import GoSitter __all__ = ["GoSitter"] diff --git a/cldk/analysis/go/treesitter/go_sitter.py b/cldk/analysis/go/treesitter/go_sitter.py index 48e1f58..54f502a 100644 --- a/cldk/analysis/go/treesitter/go_sitter.py +++ b/cldk/analysis/go/treesitter/go_sitter.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +GoSitter module +""" + from typing import List from tree_sitter import Language, Parser, Query, Node import tree_sitter_go as tsgo diff --git a/cldk/analysis/java/__init__.py b/cldk/analysis/java/__init__.py index 5378268..12165f7 100644 --- a/cldk/analysis/java/__init__.py +++ b/cldk/analysis/java/__init__.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Java package +""" + from .java import JavaAnalysis __all__ = ["JavaAnalysis"] diff --git a/cldk/analysis/java/codeanalyzer/__init__.py b/cldk/analysis/java/codeanalyzer/__init__.py index a3773e2..c806366 100644 --- a/cldk/analysis/java/codeanalyzer/__init__.py +++ b/cldk/analysis/java/codeanalyzer/__init__.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Codeanalyzer package +""" + from .codeanalyzer import JCodeanalyzer diff --git a/cldk/analysis/java/codeanalyzer/bin/__init__.py b/cldk/analysis/java/codeanalyzer/bin/__init__.py index e69de29..2c27e5f 100644 --- a/cldk/analysis/java/codeanalyzer/bin/__init__.py +++ b/cldk/analysis/java/codeanalyzer/bin/__init__.py @@ -0,0 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Bin package +""" diff --git a/cldk/analysis/java/codeanalyzer/codeanalyzer.py b/cldk/analysis/java/codeanalyzer/codeanalyzer.py index 7e96fa5..eac23c8 100644 --- a/cldk/analysis/java/codeanalyzer/codeanalyzer.py +++ b/cldk/analysis/java/codeanalyzer/codeanalyzer.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Codeanalyzer module +""" + import re import json import shlex diff --git a/cldk/analysis/java/codeanalyzer/jar/__init__.py b/cldk/analysis/java/codeanalyzer/jar/__init__.py index e69de29..e9f0326 100644 --- a/cldk/analysis/java/codeanalyzer/jar/__init__.py +++ b/cldk/analysis/java/codeanalyzer/jar/__init__.py @@ -0,0 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Jar package +""" diff --git a/cldk/analysis/java/codeql/__init__.py b/cldk/analysis/java/codeql/__init__.py index e8096d0..0c1a3f7 100644 --- a/cldk/analysis/java/codeql/__init__.py +++ b/cldk/analysis/java/codeql/__init__.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +CodeQL package +""" + from .codeql import JCodeQL __all__ = ["JCodeQL"] diff --git a/cldk/analysis/java/codeql/backend.py b/cldk/analysis/java/codeql/backend.py index 23f0d54..ce287de 100644 --- a/cldk/analysis/java/codeql/backend.py +++ b/cldk/analysis/java/codeql/backend.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Backend module +""" + import subprocess import tempfile from pathlib import Path @@ -107,7 +127,7 @@ def execute(self, query_string: str, column_names: List[str]) -> DataFrame: self.temp_file_path.write_text(query_string) # Construct and execute the CodeQL CLI command asking for a JSON output. - codeql_query_cmd = shlex.split(f"codeql query run {self.temp_file_path} --database={self.database_path} --output={self.temp_bqrs_file_path}",posix=False) + codeql_query_cmd = shlex.split(f"codeql query run {self.temp_file_path} --database={self.database_path} --output={self.temp_bqrs_file_path}", posix=False) call = subprocess.Popen(codeql_query_cmd, stdout=None, stderr=None) _, err = call.communicate() @@ -115,7 +135,7 @@ def execute(self, query_string: str, column_names: List[str]) -> DataFrame: raise CodeQLQueryExecutionException(f"Error executing query: {err.stderr}") # Convert the bqrs file to a CSV file - bqrs2csv_command = shlex.split(f"codeql bqrs decode --format=csv --output={self.csv_output_file} {self.temp_bqrs_file_path}",posix=False) + bqrs2csv_command = shlex.split(f"codeql bqrs decode --format=csv --output={self.csv_output_file} {self.temp_bqrs_file_path}", posix=False) # Read the CSV file content and cast it to a DataFrame diff --git a/cldk/analysis/java/codeql/codeql.py b/cldk/analysis/java/codeql/codeql.py index e64ee60..4390921 100644 --- a/cldk/analysis/java/codeql/codeql.py +++ b/cldk/analysis/java/codeql/codeql.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +CodeQL module +""" + from pathlib import Path import shlex import subprocess diff --git a/cldk/analysis/java/java.py b/cldk/analysis/java/java.py index a37a895..5b1bab1 100644 --- a/cldk/analysis/java/java.py +++ b/cldk/analysis/java/java.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Java module +""" + from pathlib import Path from typing import Dict, List, Tuple, Set @@ -15,19 +35,18 @@ class JavaAnalysis(SymbolTable, CallGraph): def __init__( - self, - project_dir: str | Path | None, - source_code: str | None, - analysis_backend: str, - analysis_backend_path: str | None, - analysis_json_path: str | Path | None, - analysis_level: str, - target_files: List[str] | None, - use_graalvm_binary: bool, - eager_analysis: bool, + self, + project_dir: str | Path | None, + source_code: str | None, + analysis_backend: str, + analysis_backend_path: str | None, + analysis_json_path: str | Path | None, + analysis_level: str, + target_files: List[str] | None, + use_graalvm_binary: bool, + eager_analysis: bool, ) -> None: - - """ Initialization method for Java Analysis backend. + """Initialization method for Java Analysis backend. Args: project_dir (str | Path | None): The directory path of the project. @@ -41,11 +60,11 @@ def __init__( Raises: NotImplementedError: Raised when anaysis backend is not supported. - + Attributes: application (JApplication): The application view of the Java code. - """ + """ self.project_dir = project_dir self.source_code = source_code @@ -68,118 +87,117 @@ def __init__( analysis_json_path=self.analysis_json_path, use_graalvm_binary=self.use_graalvm_binary, analysis_backend_path=self.analysis_backend_path, - target_files=self.target_files + target_files=self.target_files, ) else: raise NotImplementedError(f"Support for {analysis_backend} has not been implemented yet.") def get_imports(self) -> List[str]: - """ Returns all the imports in the source code. + """Returns all the imports in the source code. Raises: NotImplementedError: Raised when this functionality is not suported. Returns: List[str]: List of all the imports. - """ + """ raise NotImplementedError(f"Support for this functionality has not been implemented yet.") def get_variables(self, **kwargs): - """ _Returns all the variables. + """_Returns all the variables. Raises: NotImplementedError: Raised when this functionality is not suported. - """ + """ raise NotImplementedError(f"Support for this functionality has not been implemented yet.") def get_service_entry_point_classes(self, **kwargs): - """ Returns all service entry point classes. + """Returns all service entry point classes. Raises: NotImplementedError: Raised when this functionality is not suported. - """ + """ raise NotImplementedError(f"Support for this functionality has not been implemented yet.") def get_service_entry_point_methods(self, **kwargs): - """ Returns all the service entry point methods. + """Returns all the service entry point methods. Raises: NotImplementedError: Raised when this functionality is not suported. - """ + """ raise NotImplementedError(f"Support for this functionality has not been implemented yet.") def get_application_view(self) -> JApplication: - """ Returns application view of the java code. + """Returns application view of the java code. Raises: NotImplementedError: Raised when this functionality is not suported. Returns: JApplication: Application view of the java code. - """ + """ if self.source_code: raise NotImplementedError(f"Support for this functionality has not been implemented yet.") return self.backend.get_application_view() def get_symbol_table(self) -> Dict[str, JCompilationUnit]: - """ Returns symbol table. + """Returns symbol table. Returns: Dict[str, JCompilationUnit]: Symbol table - """ + """ return self.backend.get_symbol_table() def get_compilation_units(self) -> List[JCompilationUnit]: - """ Returns a list of all compilation units in the java code. + """Returns a list of all compilation units in the java code. Raises: NotImplementedError: Raised when this functionality is not suported. Returns: List[JCompilationUnit]: Compilation units of 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_compilation_units() def get_class_hierarchy(self) -> DiGraph: - """ Returns class hierarchy of the java code. + """Returns class hierarchy of the java code. Raises: NotImplementedError: Raised when this functionality is not suported. Returns: DiGraph: The class hierarchy of the Java code. - """ + """ if self.backend in [AnalysisEngine.CODEQL, AnalysisEngine.TREESITTER]: raise NotImplementedError(f"Support for this functionality has not been implemented yet.") raise NotImplementedError("Class hierarchy is not implemented yet.") def get_call_graph(self) -> DiGraph: - """ Returns the call graph of the Java code. + """Returns the call graph of the Java code. Returns: DiGraph: The call graph of the Java code. - """ + """ return self.backend.get_call_graph() def get_call_graph_json(self) -> str: - """ Returns a serialized call graph in json. + """Returns a serialized call graph in json. Raises: NotImplementedError: Raised when this functionality is not suported. Returns: str: Call graph in json. - """ + """ 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: - """ Returns a dictionary of callers of the target method. + def get_callers(self, target_class_name: str, target_method_declaration: str, using_symbol_table: bool = False) -> Dict: + """Returns a dictionary of callers of the target method. Args: target_class_name (str): Qualified target class name. @@ -191,19 +209,18 @@ def get_callers(self, target_class_name: str, target_method_declaration: str, Returns: Dict: A dictionary of callers of target method. - """ + """ 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: - """ Returns a dictionary of callees by the given method in the given class. + def get_callees(self, source_class_name: str, source_method_declaration: str, using_symbol_table: bool = False) -> Dict: + """Returns a dictionary of callees by the given method in the given class. Args: source_class_name (str): Qualified class name where the given method is. - source_method_declaration (str): Given method + source_method_declaration (str): Given method using_symbol_table (bool): Whether to use symbol table. Defaults to false. Raises: @@ -211,39 +228,39 @@ def get_callees(self, source_class_name: str, source_method_declaration: str, us Returns: Dict: Dictionary with callee details. - """ + """ 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]]: - """ Returns all methods in the Java code. + """Returns all methods in the Java code. Raises: NotImplementedError: Raised when current AnalysisEngine does not support this function. Returns: Dict[str, Dict[str, JCallable]]: Dictionary of dictionaries of all methods in the Java code with qualified class name as key and dictionary of methods in that class. - """ + """ 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_methods_in_application() def get_classes(self) -> Dict[str, JType]: - """ Returns all classes in the Java code. + """Returns all classes in the Java code. Raises: NotImplementedError: Raised when current AnalysisEngine does not support this function. Returns: Dict[str, JType]: A dictionary of all 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_classes() def get_classes_by_criteria(self, inclusions=None, exclusions=None) -> Dict[str, JType]: - """ Returns a dictionary of all classes with the given criteria, in the Java code. + """Returns a dictionary of all classes with the given criteria, in the Java code. Args: inclusions (List, optional): inlusion criteria for the classes. Defaults to None. @@ -254,7 +271,7 @@ def get_classes_by_criteria(self, inclusions=None, exclusions=None) -> Dict[str, Returns: Dict[str, JType]: A dict of all 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.") @@ -278,8 +295,8 @@ def get_classes_by_criteria(self, inclusions=None, exclusions=None) -> Dict[str, class_dict[application_class] = all_classes[application_class] return class_dict - def get_class(self, qualified_class_name:str) -> JType: - """ Returns a class object given qualified class name. + def get_class(self, qualified_class_name: str) -> JType: + """Returns a class object given qualified class name. Args: qualified_class_name (str): The qualified name of the class. @@ -289,14 +306,14 @@ def get_class(self, qualified_class_name:str) -> JType: Returns: JType: Class object for the given qualified class name. - """ + """ 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_class(qualified_class_name) - def get_method(self, qualified_class_name:str, qualified_method_name:str) -> JCallable: - """ Returns a method object given qualified class and method names. + def get_method(self, qualified_class_name: str, qualified_method_name: str) -> JCallable: + """Returns a method object given qualified class and method names. Args: qualified_class_name (str): The qualified name of the class. @@ -307,13 +324,13 @@ def get_method(self, qualified_class_name:str, qualified_method_name:str) -> JCa Returns: JCallable: A method for the given qualified method name. - """ + """ 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_method(qualified_class_name, qualified_method_name) def get_java_file(self, qualified_class_name: str) -> str: - """ Returns a class given qualified class name. + """Returns a class given qualified class name. Args: qualified_class_name (str): The qualified name of the class. @@ -323,13 +340,13 @@ def get_java_file(self, qualified_class_name: str) -> str: Returns: str: Java file name containing the given qualified class. - """ + """ 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_java_file(qualified_class_name) def get_java_compilation_unit(self, file_path: str) -> JCompilationUnit: - """ Given the path of a Java source file, returns the compilation unit object from the symbol table. + """Given the path of a Java source file, returns the compilation unit object from the symbol table. Args: file_path (str): Absolute path to Java source file @@ -339,13 +356,13 @@ def get_java_compilation_unit(self, file_path: str) -> JCompilationUnit: Returns: JCompilationUnit: Compilation unit object for Java source file - """ + """ 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_java_compilation_unit(file_path) def get_methods_in_class(self, qualified_class_name) -> Dict[str, JCallable]: - """ Returns a dictionary of all methods of the given class. + """Returns a dictionary of all methods of the given class. Args: qualified_class_name (str): qualified class name @@ -355,13 +372,13 @@ def get_methods_in_class(self, qualified_class_name) -> Dict[str, JCallable]: Returns: Dict[str, JCallable]: A dictionary of all constructors of the given class. - """ + """ 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_methods_in_class(qualified_class_name) def get_constructors(self, qualified_class_name) -> Dict[str, JCallable]: - """ Returns a dictionary of all constructors of the given class. + """Returns a dictionary of all constructors of the given class. Args: qualified_class_name (str): qualified class name @@ -371,13 +388,13 @@ def get_constructors(self, qualified_class_name) -> Dict[str, JCallable]: Returns: Dict[str, JCallable]: A dictionary of all constructors of the given class. - """ + """ 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_constructors(qualified_class_name) def get_fields(self, qualified_class_name) -> List[JField]: - """ Returns a dictionary of all fields of the given class + """Returns a dictionary of all fields of the given class Args: qualified_class_name (str): qualified class name @@ -387,13 +404,13 @@ def get_fields(self, qualified_class_name) -> List[JField]: Returns: List[JField]: A list of all fields of the given class. - """ + """ 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_fields(qualified_class_name) def get_nested_classes(self, qualified_class_name) -> List[JType]: - """ Returns a dictionary of all nested classes of the given class + """Returns a dictionary of all nested classes of the given class Args: qualified_class_name (str): qualified class name @@ -403,24 +420,24 @@ def get_nested_classes(self, qualified_class_name) -> List[JType]: Returns: List[JType]: A list of nested classes for the given class. - """ + """ 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_nested_classes(qualified_class_name) def get_sub_classes(self, qualified_class_name) -> Dict[str, JType]: - """ Returns a dictionary of all sub-classes of the given class + """Returns a dictionary of all sub-classes of the given class Args: qualified_class_name (str): qualified class name Returns: Dict[str, JType]: A dictionary of all sub-classes of the given class, and class details - """ + """ return self.backend.get_all_sub_classes(qualified_class_name=qualified_class_name) def get_extended_classes(self, qualified_class_name) -> List[str]: - """ Returns a list of all extended classes for the given class. + """Returns a list of all extended classes for the given class. Args: qualified_class_name (str): The qualified name of the class. @@ -456,7 +473,7 @@ def __get_class_call_graph_using_symbol_table(self, qualified_class_name: str, m Args: qualified_class_name (str): The qualified name of the class. method_signature (str | None, optional): The signature of the method in the class.. Defaults to None. - + Raises: NotImplementedError: Raised when current AnalysisEngine does not support this function. @@ -467,8 +484,7 @@ def __get_class_call_graph_using_symbol_table(self, qualified_class_name: str, m raise NotImplementedError(f"Support for this functionality has not been implemented yet.") 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]]: + def get_class_call_graph(self, qualified_class_name: str, method_signature: str | None = None, using_symbol_table: bool = False) -> List[Tuple[JMethodDetail, JMethodDetail]]: """A call graph for a given class and (optionally) a given method. Args: @@ -481,10 +497,9 @@ def get_class_call_graph(self, qualified_class_name: str, method_signature: str Returns: List[Tuple[JMethodDetail, JMethodDetail]]: An edge list of the call graph for the given class and method. - """ + """ 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.__get_class_call_graph_using_symbol_table(qualified_class_name=qualified_class_name, method_signature=method_signature) 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_class_call_graph(qualified_class_name, method_signature) @@ -510,7 +525,7 @@ def get_entry_point_methods(self) -> Dict[str, Dict[str, JCallable]]: 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() @@ -523,7 +538,7 @@ def remove_all_comments(self) -> str: Returns: str: The source code with all comments removed. - """ + """ # Remove any prefix comments/content before the package declaration if self.analysis_backend in [AnalysisEngine.CODEQL, AnalysisEngine.CODEANALYZER]: raise NotImplementedError(f"Support for this functionality has not been implemented yet.") @@ -540,7 +555,7 @@ def get_methods_with_annotations(self, annotations: List[str]) -> Dict[str, List Returns: Dict[str, List[Dict]]: Dictionary with annotations as keys and a list of dictionaries containing method names and bodies, as values. - """ + """ if self.analysis_backend in [AnalysisEngine.CODEQL, AnalysisEngine.CODEANALYZER]: raise NotImplementedError(f"Support for this functionality has not been implemented yet.") return self.backend.get_methods_with_annotations(self.source_code, annotations) @@ -556,8 +571,8 @@ def get_test_methods(self) -> Dict[str, str]: Returns: Dict[str, str]: Dictionary of method names and method bodies. - """ - + """ + if self.analysis_backend in [AnalysisEngine.CODEQL, AnalysisEngine.CODEANALYZER]: raise NotImplementedError(f"Support for this functionality has not been implemented yet.") return self.backend.get_test_methods(self.source_code) @@ -573,8 +588,8 @@ def get_calling_lines(self, target_method_name: str) -> List[int]: Returns: List[int]: List of line numbers within in source method code block. - """ - + """ + 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_calling_lines(self.source_code, target_method_name) @@ -590,8 +605,7 @@ def get_call_targets(self, declared_methods: dict) -> Set[str]: Returns: Set[str]: A list of call targets (methods). - """ + """ 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_call_targets(self.source_code, declared_methods) - \ No newline at end of file diff --git a/cldk/analysis/java/treesitter/__init__.py b/cldk/analysis/java/treesitter/__init__.py index 19d070b..1db32b2 100644 --- a/cldk/analysis/java/treesitter/__init__.py +++ b/cldk/analysis/java/treesitter/__init__.py @@ -1,2 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Treesitter package +""" + from cldk.analysis.java.treesitter.javasitter import JavaSitter -__all__ = ["JavaSitter"] \ No newline at end of file + +__all__ = ["JavaSitter"] diff --git a/cldk/analysis/java/treesitter/javasitter.py b/cldk/analysis/java/treesitter/javasitter.py index 20d9a5a..d7e67f8 100644 --- a/cldk/analysis/java/treesitter/javasitter.py +++ b/cldk/analysis/java/treesitter/javasitter.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +JavaSitter module +""" + from ipdb import set_trace from itertools import groupby from typing import List, Set, Dict diff --git a/cldk/analysis/javascript/__init__.py b/cldk/analysis/javascript/__init__.py index e69de29..3dbaddb 100644 --- a/cldk/analysis/javascript/__init__.py +++ b/cldk/analysis/javascript/__init__.py @@ -0,0 +1,19 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +JavaScript package +""" diff --git a/cldk/analysis/javascript/treesitter/__init__.py b/cldk/analysis/javascript/treesitter/__init__.py index 365fb7f..db754cb 100644 --- a/cldk/analysis/javascript/treesitter/__init__.py +++ b/cldk/analysis/javascript/treesitter/__init__.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Treesitter package +""" + from cldk.analysis.javascript.treesitter.javascript_sitter import JavascriptSitter __all__ = ["JavascriptSitter"] diff --git a/cldk/analysis/javascript/treesitter/javascript_sitter.py b/cldk/analysis/javascript/treesitter/javascript_sitter.py index 65d0671..432e360 100644 --- a/cldk/analysis/javascript/treesitter/javascript_sitter.py +++ b/cldk/analysis/javascript/treesitter/javascript_sitter.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +JavascriptSitter module +""" + from typing import List, Optional from tree_sitter import Language, Parser, Query, Node import tree_sitter_javascript as tsjavascript diff --git a/cldk/analysis/program_dependence_graph.py b/cldk/analysis/program_dependence_graph.py index 855e9f5..343ec20 100644 --- a/cldk/analysis/program_dependence_graph.py +++ b/cldk/analysis/program_dependence_graph.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +ProgramDependenceGraph module +""" + from abc import ABC, abstractmethod diff --git a/cldk/analysis/python/__init__.py b/cldk/analysis/python/__init__.py index 32097e0..e95052c 100644 --- a/cldk/analysis/python/__init__.py +++ b/cldk/analysis/python/__init__.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Python package +""" + from .python import PythonAnalysis -__all__ = ["PythonAnalysis"] \ No newline at end of file +__all__ = ["PythonAnalysis"] diff --git a/cldk/analysis/python/python.py b/cldk/analysis/python/python.py index a38f2b5..5852dae 100644 --- a/cldk/analysis/python/python.py +++ b/cldk/analysis/python/python.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Python module +""" + from abc import ABC from pathlib import Path from typing import Dict, List @@ -10,14 +30,14 @@ class PythonAnalysis(SymbolTable): def __init__( - self, - analysis_backend: str, - eager_analysis: bool, - project_dir: str | Path | None, - source_code: str | None, - analysis_backend_path: str | None, - analysis_json_path: str | Path | None, - use_graalvm_binary: bool = None, + self, + analysis_backend: str, + eager_analysis: bool, + project_dir: str | Path | None, + source_code: str | None, + analysis_backend_path: str | None, + analysis_json_path: str | Path | None, + use_graalvm_binary: bool = None, ) -> None: self.project_dir = project_dir self.source_code = source_code @@ -67,7 +87,7 @@ def get_method_details(self, method_signature: str) -> PyMethod: """ return self.analysis_backend.get_method_details(self.source_code, method_signature) - def get_imports(self) -> List[PyImport]: + def get_imports(self) -> List[PyImport]: """ Given an application or a source code, get all the imports """ diff --git a/cldk/analysis/python/treesitter/__init__.py b/cldk/analysis/python/treesitter/__init__.py index 44b9d0c..7774f00 100644 --- a/cldk/analysis/python/treesitter/__init__.py +++ b/cldk/analysis/python/treesitter/__init__.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Treesitter package +""" + from cldk.analysis.python.treesitter.python_sitter import PythonSitter __all__ = ["PythonSitter"] diff --git a/cldk/analysis/python/treesitter/python_sitter.py b/cldk/analysis/python/treesitter/python_sitter.py index df5dcc3..62caec1 100644 --- a/cldk/analysis/python/treesitter/python_sitter.py +++ b/cldk/analysis/python/treesitter/python_sitter.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +PythonSitter module +""" + import glob import os from pathlib import Path @@ -70,8 +90,9 @@ def get_all_functions(self, module: str) -> List[PyMethod]: method_details = self.__get_function_details(node=method_node.node) if method_details.full_signature not in method_signatures: functions.append(method_details) - elif method_signatures[method_details.full_signature][0] != method_details.start_line \ - and method_signatures[method_details.full_signature][1] != method_details.end_line: + elif ( + method_signatures[method_details.full_signature][0] != method_details.start_line and method_signatures[method_details.full_signature][1] != method_details.end_line + ): functions.append(method_details) return functions @@ -105,8 +126,7 @@ def get_all_imports(self, module: str) -> List[str]: List[str]: List of imports """ import_list = [] - captures_from_import: Captures = self.utils.frame_query_and_capture_output(self.parser, self.language, "(((import_from_statement) @imports))", - module) + captures_from_import: Captures = self.utils.frame_query_and_capture_output(self.parser, self.language, "(((import_from_statement) @imports))", module) captures_import: Captures = self.utils.frame_query_and_capture_output(self.parser, self.language, "(((import_statement) @imports))", module) for capture in captures_import: import_list.append(capture.node.text.decode()) @@ -115,10 +135,9 @@ def get_all_imports(self, module: str) -> List[str]: return import_list def get_module_details(self, module: str) -> PyModule: - return PyModule(functions=self.get_all_functions(module=module), - classes=self.get_all_classes(module=module), - imports=self.get_all_imports_details(module=module), - qualified_name='') + return PyModule( + functions=self.get_all_functions(module=module), classes=self.get_all_classes(module=module), imports=self.get_all_imports_details(module=module), qualified_name="" + ) def get_all_imports_details(self, module: str) -> List[PyImport]: """ @@ -132,8 +151,7 @@ def get_all_imports_details(self, module: str) -> List[PyImport]: List[PyImport]: List of imports """ import_list = [] - captures_from_import: Captures = self.utils.frame_query_and_capture_output(self.parser, self.language, "(((import_from_statement) @imports))", - module) + captures_from_import: Captures = self.utils.frame_query_and_capture_output(self.parser, self.language, "(((import_from_statement) @imports))", module) captures_import: Captures = self.utils.frame_query_and_capture_output(self.parser, self.language, "(((import_statement) @imports))", module) for capture in captures_import: imports = [] @@ -168,8 +186,7 @@ def get_all_classes(self, module: str) -> List[PyClass]: List[PyClass]: returns details of all classes in it """ classes: List[PyClass] = [] - all_class_details: Captures = self.utils.frame_query_and_capture_output(self.parser, self.language, "(((class_definition) @class_name))", - module) + all_class_details: Captures = self.utils.frame_query_and_capture_output(self.parser, self.language, "(((class_definition) @class_name))", module) for class_name in all_class_details: code_body = class_name.node.text.decode() class_full_signature = "" # TODO: what to fill here @@ -180,7 +197,7 @@ def get_all_classes(self, module: str) -> List[PyClass]: for child in class_name.node.children: if child.type == "argument_list": for arg in child.children: - if 'unittest' in arg.text.decode() or 'TestCase' in arg.text.decode(): + if "unittest" in arg.text.decode() or "TestCase" in arg.text.decode(): is_test_class = True super_classes.append(arg.text.decode()) if child.type == "block": @@ -193,12 +210,9 @@ def get_all_classes(self, module: str) -> List[PyClass]: if decorated_def.type == "function_definition": method = self.__get_function_details(node=decorated_def, klass_name=klass_name) methods.append(method) - classes.append(PyClass(code_body=code_body, - full_signature=class_full_signature, - methods=methods, - super_classes=super_classes, - class_name=klass_name, - is_test_class=is_test_class)) + classes.append( + PyClass(code_body=code_body, full_signature=class_full_signature, methods=methods, super_classes=super_classes, class_name=klass_name, is_test_class=is_test_class) + ) return classes def get_all_modules(self, application_dir: Path) -> List[PyModule]: @@ -213,26 +227,22 @@ def get_all_modules(self, application_dir: Path) -> List[PyModule]: List[PyModule]: returns a list of modules """ modules: List[PyModule] = [] - path_list = [os.path.join(dirpath, filename) for dirpath, _, filenames in os.walk(application_dir) for filename in filenames - if filename.endswith('.py')] + path_list = [os.path.join(dirpath, filename) for dirpath, _, filenames in os.walk(application_dir) for filename in filenames if filename.endswith(".py")] for p in path_list: modules.append(self.__get_module(path=p)) return modules def __get_module(self, path: Path): module_qualified_path = os.path.join(path) - module_qualified_name = str(module_qualified_path).replace(os.sep, '.') - with open(module_qualified_path, 'r') as file: + module_qualified_name = str(module_qualified_path).replace(os.sep, ".") + with open(module_qualified_path, "r") as file: py_module = self.get_module_details(module=file.read()) qualified_name: str methods: List[PyMethod] functions: List[PyMethod] classes: List[PyClass] imports: List[PyImport] - return PyModule(qualified_name=module_qualified_name, - imports=py_module.imports, - functions=py_module.functions, - classes=py_module.classes) + return PyModule(qualified_name=module_qualified_name, imports=py_module.imports, functions=py_module.functions, classes=py_module.classes) return None @staticmethod @@ -256,19 +266,21 @@ def __get_call_site_details(call_node: Node) -> PyCallSite: declaring_object = call_node.children[0].children[0].text.decode() arguments: List[str] = [] for arg in call_node.children[1].children: - if arg.type not in ['(', ')', ',']: + if arg.type not in ["(", ")", ","]: arguments.append(arg.text.decode()) except Exception: - method_name = '' - declaring_object = '' + method_name = "" + declaring_object = "" arguments = [] - return PyCallSite(method_name=method_name, - declaring_object=declaring_object, - arguments=arguments, - start_line=start_line, - start_column=start_column, - end_line=end_line, - end_column=end_column) + return PyCallSite( + method_name=method_name, + declaring_object=declaring_object, + arguments=arguments, + start_line=start_line, + start_column=start_column, + end_line=end_line, + end_column=end_column, + ) def __get_function_details(self, node: Node, klass_name: str = "") -> PyMethod: code_body: str = node.text.decode() @@ -316,8 +328,7 @@ def __get_function_details(self, node: Node, klass_name: str = "") -> PyMethod: if parameter.type == "identifier": formal_param = PyArg(arg_name=parameter.text.decode(), arg_type="") elif parameter.type == "typed_parameter": - formal_param = PyArg(arg_name=parameter.children[0].text.decode(), - arg_type=parameter.children[2].text.decode()) + formal_param = PyArg(arg_name=parameter.children[0].text.decode(), arg_type=parameter.children[2].text.decode()) elif parameter.type == "dictionary_splat_pattern": formal_param = PyArg(arg_name=parameter.text.decode(), arg_type="") if formal_param is not None: @@ -337,12 +348,10 @@ def __get_function_details(self, node: Node, klass_name: str = "") -> PyMethod: end_line=end_line, is_static=is_static, is_constructor=is_constructor, - call_sites=call_sites + call_sites=call_sites, ) return function - - def __get_class_nodes(self, module: str) -> Captures: captures: Captures = self.utils.frame_query_and_capture_output(self.parser, self.language, "(((class_definition) @class_name))", module) return captures diff --git a/cldk/analysis/symbol_table.py b/cldk/analysis/symbol_table.py index d26e9cf..0649251 100644 --- a/cldk/analysis/symbol_table.py +++ b/cldk/analysis/symbol_table.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +SymbolTable module +""" + from abc import ABC, abstractmethod @@ -5,9 +25,9 @@ class SymbolTable(ABC): def __init__(self) -> None: super().__init__() - ''' + """ Language agnostic functions - ''' + """ @abstractmethod def get_methods(self, **kwargs): @@ -30,9 +50,9 @@ def get_variables(self, **kwargs): """ pass - ''' + """ OOP-specific functions - ''' + """ @abstractmethod def get_classes(self, **kwargs): diff --git a/cldk/analysis/system_dependence_graph.py b/cldk/analysis/system_dependence_graph.py index 986194c..a3da24d 100644 --- a/cldk/analysis/system_dependence_graph.py +++ b/cldk/analysis/system_dependence_graph.py @@ -1,6 +1,26 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +SystemDependenceGraph module +""" + from abc import abstractmethod, ABC class SystemDependenceGraph(ABC): def __init__(self) -> None: - super().__init__() \ No newline at end of file + super().__init__() diff --git a/cldk/utils/exceptions/exceptions.py b/cldk/utils/exceptions/exceptions.py index 8646228..651c576 100644 --- a/cldk/utils/exceptions/exceptions.py +++ b/cldk/utils/exceptions/exceptions.py @@ -1,3 +1,24 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Exceptions module +""" + + class CldkInitializationException(Exception): """Custom exception for errors during CLDK initialization.""" diff --git a/cldk/utils/treesitter/__init__.py b/cldk/utils/treesitter/__init__.py index 35f5333..7644d5b 100644 --- a/cldk/utils/treesitter/__init__.py +++ b/cldk/utils/treesitter/__init__.py @@ -15,5 +15,5 @@ ################################################################################ """ -Tree Sitter package +Treesitter package """ From e4831061845e551fe956ae656dee552301e0ed76 Mon Sep 17 00:00:00 2001 From: John Rofrano Date: Fri, 11 Oct 2024 20:10:38 +0000 Subject: [PATCH 4/5] Added IBM Copyright to Core package source Signed-off-by: John Rofrano --- cldk/__init__.py | 20 ++++++++++++++++++++ cldk/core.py | 43 +++++++++++++++++++++++++++++++------------ 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/cldk/__init__.py b/cldk/__init__.py index 4829ad0..f2972e9 100644 --- a/cldk/__init__.py +++ b/cldk/__init__.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Core package +""" + from .core import CLDK __all__ = ["CLDK"] diff --git a/cldk/core.py b/cldk/core.py index 91445c9..f29a117 100644 --- a/cldk/core.py +++ b/cldk/core.py @@ -1,3 +1,23 @@ +################################################################################ +# Copyright IBM Corporation 2024 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ + +""" +Core module +""" + from pathlib import Path import logging @@ -31,16 +51,16 @@ def __init__(self, language: str): self.language: str = language def analysis( - self, - project_path: str | Path | None = None, - source_code: str | None = None, - eager: bool = False, - analysis_backend: str | None = "codeanalyzer", - analysis_level: str = AnalysisLevel.symbol_table, - target_files: List[str] | None = None, - analysis_backend_path: str | None = None, - analysis_json_path: str | Path = None, - use_graalvm_binary: bool = False, + self, + project_path: str | Path | None = None, + source_code: str | None = None, + eager: bool = False, + analysis_backend: str | None = "codeanalyzer", + analysis_level: str = AnalysisLevel.symbol_table, + target_files: List[str] | None = None, + analysis_backend_path: str | None = None, + analysis_json_path: str | Path = None, + use_graalvm_binary: bool = False, ) -> JavaAnalysis: """ Initialize the preprocessor based on the specified language and analysis_backend. @@ -94,8 +114,7 @@ def analysis( raise CldkInitializationException("Either project_path or source_code must be provided.") if project_path is not None and source_code is not None: - raise CldkInitializationException( - "Both project_path and source_code are provided. Please provide " "only one.") + raise CldkInitializationException("Both project_path and source_code are provided. Please provide " "only one.") if self.language == "java": return JavaAnalysis( From ca4690996ef2aa38446308012ce6ba5731775468 Mon Sep 17 00:00:00 2001 From: John Rofrano Date: Fri, 11 Oct 2024 20:26:50 +0000 Subject: [PATCH 5/5] Fixed misnamed Python files Signed-off-by: John Rofrano --- cldk/core.py | 2 +- cldk/utils/sanitization/java/__init__.py | 4 ++++ .../java/{TreesitterSanitizer.py => treesitter_sanitizer.py} | 2 +- .../java/{TreesitterUtils.py => treesitter_utils.py} | 0 4 files changed, 6 insertions(+), 2 deletions(-) rename cldk/utils/sanitization/java/{TreesitterSanitizer.py => treesitter_sanitizer.py} (100%) rename cldk/utils/sanitization/java/{TreesitterUtils.py => treesitter_utils.py} (100%) diff --git a/cldk/core.py b/cldk/core.py index f29a117..6bcb8e6 100644 --- a/cldk/core.py +++ b/cldk/core.py @@ -27,7 +27,7 @@ from cldk.analysis.java import JavaAnalysis from cldk.analysis.java.treesitter import JavaSitter from cldk.utils.exceptions import CldkInitializationException -from cldk.utils.sanitization.java.TreesitterSanitizer import TreesitterSanitizer +from cldk.utils.sanitization.java import TreesitterSanitizer logger = logging.getLogger(__name__) diff --git a/cldk/utils/sanitization/java/__init__.py b/cldk/utils/sanitization/java/__init__.py index b8cf380..d031f79 100644 --- a/cldk/utils/sanitization/java/__init__.py +++ b/cldk/utils/sanitization/java/__init__.py @@ -17,3 +17,7 @@ """ Java package """ + +from .treesitter_sanitizer import TreesitterSanitizer + +__all__ = ["TreesitterSanitizer"] diff --git a/cldk/utils/sanitization/java/TreesitterSanitizer.py b/cldk/utils/sanitization/java/treesitter_sanitizer.py similarity index 100% rename from cldk/utils/sanitization/java/TreesitterSanitizer.py rename to cldk/utils/sanitization/java/treesitter_sanitizer.py index 43596d3..dfca9af 100644 --- a/cldk/utils/sanitization/java/TreesitterSanitizer.py +++ b/cldk/utils/sanitization/java/treesitter_sanitizer.py @@ -18,12 +18,12 @@ Treesitter Sanitizer module """ +import logging from copy import deepcopy from typing import Dict, List, Set from cldk.analysis.java.treesitter import JavaSitter from cldk.models.treesitter import Captures -import logging log = logging.getLogger(__name__) diff --git a/cldk/utils/sanitization/java/TreesitterUtils.py b/cldk/utils/sanitization/java/treesitter_utils.py similarity index 100% rename from cldk/utils/sanitization/java/TreesitterUtils.py rename to cldk/utils/sanitization/java/treesitter_utils.py