From 3c6e3e2c0bc2d2308fe5bf8d4f7f7170b5bacad6 Mon Sep 17 00:00:00 2001 From: Rahul Krishna Date: Mon, 7 Oct 2024 10:16:07 -0400 Subject: [PATCH 1/2] =?UTF-8?q?Set=20version=20to=20=C3=BCber=20json.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rahul Krishna --- cldk/models/java/models.py | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/cldk/models/java/models.py b/cldk/models/java/models.py index 7bc51274..93530cbe 100644 --- a/cldk/models/java/models.py +++ b/cldk/models/java/models.py @@ -1,9 +1,10 @@ -import json import re -from typing import Dict, List, Optional -from pydantic import BaseModel, field_validator, model_validator +import json +from ipdb import set_trace from contextvars import ContextVar +from typing import Dict, List, Optional from .constants_namespace import ConstantsNamespace +from pydantic import BaseModel, field_validator, model_validator constants = ConstantsNamespace() context_concrete_class = ContextVar("context_concrete_class") # context var to store class concreteness @@ -340,18 +341,11 @@ class JGraphEdges(BaseModel): @field_validator("source", "target", mode="before") @classmethod def validate_source(cls, value) -> JMethodDetail: - if isinstance(value, str): - callable_dict = json.loads(value) - j_callable = JCallable(**json.loads(callable_dict["callable"])) # parse the value which is a quoted string - class_name = callable_dict["class_interface_declarations"] - method_decl = j_callable.declaration - elif isinstance(value, dict): - file_path, type_declaration, callable_declaration = value["file_path"], value["type_declaration"], value["callable_declaration"] - j_callable = _CALLABLES_LOOKUP_TABLE.get((file_path, type_declaration, callable_declaration), None) - if j_callable is None: - raise ValueError(f"Callable not found in lookup table: {file_path}, {type_declaration}, {callable_declaration}") - class_name = type_declaration - method_decl = j_callable.declaration + callable_dict = json.loads(value) + j_callable = JCallable(**json.loads(callable_dict["callable"])) # parse the value which is a quoted string + class_name = callable_dict["class_interface_declarations"] + method_decl = j_callable.declaration + mc = JMethodDetail(method_declaration=method_decl, klass=class_name, method=j_callable) return mc @@ -373,14 +367,3 @@ class JApplication(BaseModel): symbol_table: Dict[str, JCompilationUnit] system_dependency_graph: List[JGraphEdges] = None - - @field_validator("symbol_table", mode="after") - @classmethod - def validate_source(cls, symbol_table): - from ipdb import set_trace - - # Populate the lookup table for callables - for file_path, j_compulation_unit in symbol_table.items(): - for type_declaration, jtype in j_compulation_unit.type_declarations.items(): - for callable_declaration, j_callable in jtype.callable_declarations.items(): - _CALLABLES_LOOKUP_TABLE[(file_path, type_declaration, callable_declaration)] = j_callable From c9e965d3e44c74bc68e4f6bca5f32dbdee9cfb31 Mon Sep 17 00:00:00 2001 From: Rahul Krishna Date: Mon, 7 Oct 2024 10:24:22 -0400 Subject: [PATCH 2/2] =?UTF-8?q?Set=20version=20to=20=C3=BCber=20json.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rahul Krishna --- cldk/models/java/models.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cldk/models/java/models.py b/cldk/models/java/models.py index 79d22dfa..ab6cd39f 100644 --- a/cldk/models/java/models.py +++ b/cldk/models/java/models.py @@ -8,7 +8,6 @@ constants = ConstantsNamespace() context_concrete_class = ContextVar("context_concrete_class") # context var to store class concreteness -_CALLABLES_LOOKUP_TABLE = dict() class JField(BaseModel): @@ -345,7 +344,6 @@ def validate_source(cls, value) -> JMethodDetail: j_callable = JCallable(**json.loads(callable_dict["callable"])) # parse the value which is a quoted string class_name = callable_dict["class_interface_declarations"] method_decl = j_callable.declaration - mc = JMethodDetail(method_declaration=method_decl, klass=class_name, method=j_callable) return mc @@ -366,4 +364,4 @@ class JApplication(BaseModel): """ symbol_table: Dict[str, JCompilationUnit] - system_dependency_graph: List[JGraphEdges] = None \ No newline at end of file + system_dependency_graph: List[JGraphEdges] = None