Skip to content

Merge main to slim branch #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 9, 2024
Merged
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ scratch*

# log file
*.json

# Lock file
*.lock
!devcontainer.json


# Python compiled files and env
Expand Down
35 changes: 8 additions & 27 deletions cldk/models/java/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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
_CALLABLES_LOOKUP_TABLE = dict()


class JField(BaseModel):
Expand Down Expand Up @@ -340,18 +340,10 @@ 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

Expand All @@ -373,14 +365,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
4 changes: 1 addition & 3 deletions cldk/models/python/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class PyMethod(BaseModel):
class_signature: str
start_line: int
end_line: int
# incoming_calls: Optional[List["PyMethod"]] = None
# outgoing_calls: Optional[List["PyMethod"]] = None


class PyClass(BaseModel):
Expand All @@ -54,7 +52,7 @@ class PyModule(BaseModel):
functions: List[PyMethod]
classes: List[PyClass]
imports: List[PyImport]
#expressions: str
# expressions: str


class PyBuildAttributes(BaseModel):
Expand Down
Loading