Skip to content

Fixing java and python issues #6

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 5 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

# Mac file
.DS_Store

# Log file
*.log

# Gradle files
.gradle

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

scratch*
*.flake8
.vscode
.idea/
*.iml

# environment file
.env

# log file
*.json

# Lock file
*.lock


# Python compiled files and env
__pycache__/
*.py[cod]
.python-version
.venv/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,4 @@ if __name__ == "__main__":
# (11) Print the instruction and LLM output
print(f"Instruction:\n{instruction}")
print(f"LLM Output:\n{llm_output}")
```
```
60 changes: 20 additions & 40 deletions cldk/analysis/java/codeanalyzer/codeanalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ def __init__(
self.use_graalvm_binary = use_graalvm_binary
self.eager_analysis = eager_analysis
self.analysis_level = analysis_level
self.application = self._init_codeanalyzer(analysis_level=1 if analysis_level == 'symbol_table' else 2)
# Attributes related the Java code analysis...
self.call_graph: DiGraph | None = None
self.application = None
if analysis_level == 'symbol_table':
self.call_graph: DiGraph | None = None
else:
self.call_graph: DiGraph = self._generate_call_graph(using_symbol_table=False)


@staticmethod
def _download_or_update_code_analyzer(filepath: Path) -> str:
Expand Down Expand Up @@ -164,7 +168,7 @@ def _get_codeanalyzer_exec(self) -> List[str]:
codeanalyzer_exec = shlex.split(codeanalyzer_bin_path.__str__())
else:
if self.analysis_backend_path:
analysis_backend_path = Path(analysis_backend_path)
analysis_backend_path = Path(self.analysis_backend_path)
logger.info(f"Using codeanalyzer.jar from {analysis_backend_path}")
codeanalyzer_exec = shlex.split(f"java -jar {analysis_backend_path / 'codeanalyzer.jar'}")
else:
Expand Down Expand Up @@ -715,43 +719,19 @@ def get_class_call_graph(self, qualified_class_name: str, method_name: str | Non
"""
# If the method name is not provided, we'll get the call graph for the entire class.

# TODO: Implement class call graph generation @rahlk

_class: JType = self.get_class(qualified_class_name)

edge_list = []
for method_signature, callable in _class.callable_declarations.items():
for callsite in callable.callsites:
edge_list.append(((callable.signature, qualified_class_name),))

class_call_graph = nx.DiGraph()

edge_list = [
(
(jge.source.method.signature, jge.source.klass),
(jge.target.method.signature, jge.target.klass),
{
"type": jge.type,
"weight": jge.weight,
"calling_lines": tsu.get_calling_lines(jge.source.method.code, jge.target.method.signature),
},
)
for jge in sdg
if jge.type == "CONTROL_DEP" or jge.type == "CALL_DEP"
]

for jge in sdg:
class_call_graph.add_node(
(jge.source.method.signature, jge.source.klass),
method_detail=jge.source,
)
class_call_graph.add_node(
(jge.target.method.signature, jge.target.klass),
method_detail=jge.target,
)
class_call_graph.add_edges_from(edge_list)

NotImplementedError("Class call graph generation is not implemented yet.")
if method_name is None:
filter_criteria = {node for node in self.call_graph.nodes if node[1] == qualified_class_name}
else:
filter_criteria = {node for node in self.call_graph.nodes if
tuple(node) == (method_name, qualified_class_name)}

graph_edges: List[Tuple[JMethodDetail, JMethodDetail]] = list()
for edge in self.call_graph.edges(nbunch=filter_criteria):
source: JMethodDetail = self.call_graph.nodes[edge[0]]["method_detail"]
target: JMethodDetail = self.call_graph.nodes[edge[1]]["method_detail"]
graph_edges.append((source, target))

return graph_edges

def get_all_entry_point_methods(self) -> Dict[str, Dict[str, JCallable]]:
"""
Expand Down
Loading