Skip to content

Commit

Permalink
Merge pull request #75 from rofrano/fix-testcases
Browse files Browse the repository at this point in the history
Created test cases to bring JCodeAnalyzer, JavaAnalysis, and JavaSitter to 90% test coverage
  • Loading branch information
rahlk authored Jan 27, 2025
2 parents 8522093 + c04da6d commit 3b44af7
Show file tree
Hide file tree
Showing 13 changed files with 118,444 additions and 105,584 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
*.tar.gz
*.rar

# Don't ignore test fixture zip files
!tests/resources/java/application/daytrader8-1.2.zip

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

Expand Down
2 changes: 1 addition & 1 deletion cldk/analysis/java/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
Java package
"""

from .java import JavaAnalysis
from .java_analysis import JavaAnalysis

__all__ = ["JavaAnalysis"]
2 changes: 1 addition & 1 deletion cldk/analysis/java/codeanalyzer/codeanalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def _init_codeanalyzer(self, analysis_level=1) -> JApplication:
data = json.load(f)
return JApplication(**data)

def _codeanalyzer_single_file(self):
def _codeanalyzer_single_file(self) -> JApplication:
"""Invokes codeanalyzer in a single file mode.
Returns:
Expand Down
78 changes: 42 additions & 36 deletions cldk/analysis/java/java.py → cldk/analysis/java/java_analysis.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cldk/analysis/java/treesitter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
Treesitter package
"""

from cldk.analysis.java.treesitter.javasitter import JavaSitter
from cldk.analysis.java.treesitter.java_sitter import JavaSitter

__all__ = ["JavaSitter"]
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@
"""
JavaSitter module
"""
import logging
from itertools import groupby
from typing import List, Set, Dict
from tree_sitter import Language, Node, Parser, Query, Tree
import tree_sitter_java as tsjava
from tree_sitter import Language, Node, Parser, Query

from cldk.models.treesitter import Captures

import logging

logger = logging.getLogger(__name__)


# pylint: disable=too-many-public-methods
class JavaSitter:
"""
Treesitter for Java usecases.
Expand Down Expand Up @@ -75,7 +73,7 @@ def syntax_error(node):
for child in node.children:
if syntax_error(child):
return True
except RecursionError as err:
except RecursionError:
return True

return False
Expand Down Expand Up @@ -108,6 +106,7 @@ def get_all_imports(self, source_code: str) -> Set[str]:
import_declerations: Captures = self.frame_query_and_capture_output(query="(import_declaration (scoped_identifier) @name)", code_to_process=source_code)
return {capture.node.text.decode() for capture in import_declerations}

# TODO: This typo needs to be fixed (i.e., package not pacakge)
def get_pacakge_name(self, source_code: str) -> str:
"""Get the package name from the source code.
Expand Down Expand Up @@ -228,7 +227,7 @@ def safe_ascend(self, node: Node, ascend_count: int) -> Node:
def get_call_targets(self, method_body: str, declared_methods: dict) -> Set[str]:
"""Generate a list of call targets from the method body.
Uses simple name resolution for finding the call targets. Nothing sophiscticed here. Just a simple search
Uses simple name resolution for finding the call targets. Nothing sophisticated here. Just a simple search
over the AST.
Parameters
Expand Down
35 changes: 0 additions & 35 deletions tests/analysis/java/test_java.py

This file was deleted.

Loading

0 comments on commit 3b44af7

Please sign in to comment.