|
52 | 52 |
|
53 | 53 | from tree_sitter import Tree |
54 | 54 |
|
55 | | -from cldk.analysis.commons.backend_config import CodeAnalyzerConfig, JavaBackend, cache_subdir |
| 55 | +from cldk.analysis.commons.backend_config import CodeAnalyzerConfig, JavaBackend, Neo4jConnectionConfig, cache_subdir |
56 | 56 | from cldk.analysis.commons.treesitter import TreesitterJava |
57 | 57 | from cldk.models.java import JCallable |
58 | 58 | from cldk.models.java import JApplication |
59 | 59 | from cldk.models.java.models import JCRUDOperation, JComment, JCompilationUnit, JMethodDetail, JType, JField |
60 | 60 | from cldk.analysis.java.codeanalyzer import JCodeanalyzer |
| 61 | +from cldk.analysis.java.neo4j import JNeo4jBackend |
61 | 62 | from cldk.analysis.java.backend import JavaAnalysisBackend |
62 | 63 |
|
63 | 64 |
|
@@ -149,22 +150,33 @@ def __init__( |
149 | 150 | self.eager_analysis = eager_analysis |
150 | 151 | self.target_files = target_files |
151 | 152 | self.backend_config: JavaBackend = backend if backend is not None else CodeAnalyzerConfig() |
152 | | - # Java has a single backend family; the config only carries the cache root. analysis.json |
153 | | - # is cached under <cache_dir>/java (None in source_code mode, where the analyzer streams |
154 | | - # results over a pipe). |
155 | | - cache_path = cache_subdir(self.backend_config.cache_dir, project_dir, "java") |
156 | | - if cache_path is not None: |
157 | | - cache_path.mkdir(parents=True, exist_ok=True) |
158 | 153 | self.treesitter_java: TreesitterJava = TreesitterJava() |
159 | | - # Initialize the analysis backend |
160 | | - self.backend: JavaAnalysisBackend = JCodeanalyzer( |
161 | | - project_dir=self.project_dir, |
162 | | - source_code=self.source_code, |
163 | | - eager_analysis=self.eager_analysis, |
164 | | - analysis_level=self.analysis_level, |
165 | | - analysis_json_path=cache_path, |
166 | | - target_files=self.target_files, |
167 | | - ) |
| 154 | + self.backend: JavaAnalysisBackend |
| 155 | + if isinstance(self.backend_config, Neo4jConnectionConfig): |
| 156 | + # Read-only: the graph is populated out of band; the SDK only polls it. |
| 157 | + cfg = self.backend_config |
| 158 | + application_name = cfg.application_name or (Path(project_dir).name if project_dir else None) |
| 159 | + self.backend = JNeo4jBackend( |
| 160 | + neo4j_uri=cfg.uri, |
| 161 | + neo4j_username=cfg.username, |
| 162 | + neo4j_password=cfg.password, |
| 163 | + neo4j_database=cfg.database, |
| 164 | + application_name=application_name, |
| 165 | + ) |
| 166 | + else: |
| 167 | + # The config only carries the cache root. analysis.json is cached under <cache_dir>/java |
| 168 | + # (None in source_code mode, where the analyzer streams results over a pipe). |
| 169 | + cache_path = cache_subdir(self.backend_config.cache_dir, project_dir, "java") |
| 170 | + if cache_path is not None: |
| 171 | + cache_path.mkdir(parents=True, exist_ok=True) |
| 172 | + self.backend = JCodeanalyzer( |
| 173 | + project_dir=self.project_dir, |
| 174 | + source_code=self.source_code, |
| 175 | + eager_analysis=self.eager_analysis, |
| 176 | + analysis_level=self.analysis_level, |
| 177 | + analysis_json_path=cache_path, |
| 178 | + target_files=self.target_files, |
| 179 | + ) |
168 | 180 |
|
169 | 181 | def get_imports(self) -> List[str]: |
170 | 182 | """Return all import statements in the source code. |
|
0 commit comments