Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
feat: bring JVM (Java + Kotlin) indexing to parity (#280)
Raghav Chamadiya5175bc2ae86f
diff --git a/docs/LANGUAGE_SUPPORT.md b/docs/LANGUAGE_SUPPORT.mdindex 4dd4c5eb1..f11b41d52 100644--- a/docs/LANGUAGE_SUPPORT.md+++ b/docs/LANGUAGE_SUPPORT.md@@ -38,13 +38,14 @@ call resolution, named bindings, heritage extraction, and docstrings.| **Python** | `.py` `.pyi` | `main.py` `app.py` `__main__.py` `manage.py` `wsgi.py` `asgi.py` | `import x` / `from x import y` || **TypeScript** | `.ts` `.tsx` | `index.ts` `main.ts` `app.ts` `server.ts` | `import { x } from 'y'` / `export { x } from 'y'` & `export * from 'y'` re-export barrels / `require()` with tsconfig path aliases, npm/yarn/pnpm `workspaces`, and optional `.vue`/`.svelte`/`.astro` SFC probing || **JavaScript** | `.js` `.jsx` `.mjs` `.cjs` | `index.js` `main.js` `app.js` `server.js` | `import` / `require()` |-| **Java** | `.java` | `Main.java` `Application.java` | `import pkg.Class` |+| **Java** | `.java` | `Main.java` `Application.java` | `import pkg.Class` / `import pkg.*` / `import static pkg.Class.*` with Maven `pom.xml` reactor + Gradle `settings.gradle(.kts)` source-sets + `gradle/libs.versions.toml` discovery, JPMS `module-info.java` / `package-info.java` recognition, fan-out to every file in the imported package (siblings share importers), same-package implicit identifier resolution |+| **Kotlin** | `.kt` `.kts` | `Main.kt` `Application.kt` | `import com.example.Foo` / `import com.example.*` sharing the JVM workspace index with Java (cross-language resolution, `.kt` under `src/main/java` recognised) || **Go** | `.go` | `main.go` `cmd/main.go` | `import "path"` with multi-module `go.mod` discovery (longest-prefix match); a package import fans out to **all** `.go` files in the package directory || **Rust** | `.rs` | `main.rs` `lib.rs` | `use crate::` / `use super::` / `use self::` with `Cargo.toml` || **C++** | `.cpp` `.cc` `.cxx` `.h` `.hpp` `.hxx` | `main.cpp` `main.cc` | `#include` with `compile_commands.json` resolution || **C#** | `.cs` | `Program.cs` `Startup.cs` | `using Acme.Domain` / `global using` / `using static` / `using Alias = X.Y.Z` with `.csproj` / `.sln` / `Directory.Build.props` resolution |-All eight languages support:+All nine languages support:- Tree-sitter AST parsing with dedicated `.scm` query files- Three-tier call resolution (same-file, cross-file, global stem match)- Named binding extraction (mapping imported names to source symbols)@@ -58,6 +59,7 @@ All eight languages support:- For JavaScript only: esbuild/rollup bundle outputs (`*.bundle.js`), minified artifacts (`*.min.js`), LiveReload generated browser-global scripts (`livereload/gen/*`, `livereload.js`) and WASM JS glue (`*wasm_exec.js`) are never flagged as dead (build products / browser-loaded, never module-imported)- For TypeScript / JavaScript only: a workspace-granular index (`TsWorkspaceIndex`) built as a warmup phase that surfaces every file reachable through a `package.json` `exports` map (including `"./locales/*"`-style wildcards) as an entry point so downstream npm consumers don't read as unreachable; type-reference resolution emits `type_use` edges for parameter / field / return / generic-constraint / type-alias-RHS / heritage clauses (unwrapping `Promise<T>`, `T[]`, `Pick<T,K>`, union/intersection, conditional/mapped types) so interfaces consumed only as types are not flagged dead; same-file rescue exempts symbols whose only consumer is another declaration in the same module; convention never-flag globs for `*.test.*` / `*.spec.*` / `*.stories.*` / `*.bench.*` / `__tests__/**` / `__mocks__/**` / Next.js app-router files (`page.tsx`, `layout.tsx`, `route.ts`, `middleware.ts`, `instrumentation.ts`, route segment configs) / SvelteKit `+page` / `+layout` / `+server` / Remix `entry.client` / `entry.server` / `next-env.d.ts` / `*.gen.ts` / `generated/**`; experimental sub-package rescue marks every source file in directories named `bench` / `benchmarks` / `treeshake` / `examples` / `demos` / `samples` / `playground` / `scratch` / `scripts` as a live entry (these dirs invoke their files via runtime CLI arguments no static scan can follow); npm-script entry detection — parses every `package.json` `scripts.*` command for paths (`tsx X.ts` / `bun run X.mts` / `rollup -c X.js`), quoted glob arguments (prettier / eslint scopes), and bare directory tokens; MDX `import` scan + `vitest.config` `include` glob scan as belt-and-suspenders for entry surfaces the static parser can't see; framework edges for Next.js App Router (`app/**/{page,layout,route,middleware,…}`), Hono / Fastify / Koa / Elysia router DSLs (`.get('/x', handler)`), Remix / SvelteKit / Astro filesystem-convention routes, and tRPC procedure registries (`.query(handler)` / `.mutation(handler)`); JSX-namespace types declared inside a `namespace JSX` file are exempt from `unused_export` (consumed by tsc via `jsxImportSource`, never imported as values)- For XAML only: `<ResourceDictionary Source="..."/>` and `MergedDictionaries` entries resolve across `pack://application:,,,/`, `ms-appx:///`, repo-rooted and relative URIs, emitting xaml→xaml `dynamic_uses` edges+- For JVM (Java + Kotlin together) only: a unified `JvmWorkspaceIndex` warmup parsing Maven `pom.xml` reactors and Gradle `settings.gradle(.kts)` + source-sets + `gradle/libs.versions.toml` version catalogs; one walk groups every `.java` and `.kt` file by package directory so `import com.foo.Bar` fans out to every defining file in the package (siblings share importers), `import com.foo.*` / `import static com.foo.Bar.*` expand to all matching files, same-package implicit identifier access is honoured, and Kotlin↔Java cross-language resolution links callers across both source-roots (including `.kt` files hosted under `src/main/java`); type-reference resolution emits `type_use` edges for parameter / field / return / generic / `new T()` types (unwrapping arrays, generics, nullables), plus Kotlin `companion object` / `object` singleton / method-reference (`Foo::bar`) / `sealed … permits` resolution; source-generator-equivalent synthesis emits the symbols Lombok (`@Data` / `@Value` / `@Builder` / `@RequiredArgsConstructor` / `@Slf4j` / `@UtilityClass` / friends), Java `record`, Kotlin `data class` / `enum class` / `object`, and MapStruct / AutoValue / Immutables would produce at compile time — so a Lombok-only Spring service no longer reads its injected fields as unused; framework edges cover Spring (stereotypes with meta-annotation resolution; `@RequestMapping` family routing; Spring Data `JpaRepository` / `Crud` / `Mongo` / `R2dbc` / `Elasticsearch` / `Neo4j` / `Couchbase` / `Cassandra` interfaces and their derived-query methods as entry points; `@Bean` factories; single-constructor + `@Autowired` / `@Inject` / `@Resource` DI; Lombok-RAC/AAC constructor inference), Jakarta (JAX-RS `@Path`, CDI scopes, Servlet 3+ `@WebServlet`/`@WebFilter`/`@WebListener`, JPA `@Entity` + `@OneToMany`/`@ManyToOne`/`@ManyToMany`/`@OneToOne` association edges; both `javax.*` and `jakarta.*`), Quarkus (entry stereotypes + SmallRye `@Incoming("topic")` ↔ `@Outgoing("topic")` cross-linking), Micronaut (DI / routing, gated on Micronaut imports to disambiguate Spring's collisions), and Android (`AndroidManifest.xml` `android:name` references emit edges to the named class); JVM dynamic hints capture `Class.forName`, Mockito / mockk, MapStruct `Mappers.getMapper`, `SpringApplication.run` and Kotlin `runApplication<>`, Jackson / Gson `readValue` / `fromJson` / `treeToValue`; package-aware dead-code reachability rescues sibling-rescued packages, stereotype-annotated classes, `main(String[])` carriers, and FQNs listed in `META-INF/services/*` / `META-INF/spring.factories` (Boot 2) / `META-INF/spring/...AutoConfiguration.imports` (Boot 3) / JPMS `provides … with …` — all resolved during the workspace warmup; JVM never-flag patterns cover `module-info.java`, `package-info.java`, every conventional test source-set (`src/test/**`, `src/integrationTest/**`, `src/intTest/**`, `src/it/**`, `src/jmh/**`, generic `src/*Test/**`), generated source roots (`build/generated/**`, KAPT/KSP, `target/generated-sources/**`, GraalVM `aotSources`), generated suffix conventions (`Dagger*`, `AutoValue_*`, JPA `*_.java` metamodel, `*Grpc.java`, protoc `*OuterClass.java`), JUnit / TestNG / Spock / ArchUnit test-naming + annotation-marked entry points (`@Test` / `@PostConstruct` / `@EventListener` / `@Scheduled` / `@JmsListener` / `@KafkaListener` / `@RabbitListener` / `@SqsListener` / `@Incoming` / `@Outgoing` / `@Mojo` / `@Bean` / …), and JVM contract methods (`equals` / `hashCode` / `toString` / `compareTo` / `clone` / serialization `readObject` / `writeObject` / `serialVersionUID` / Lombok `canEqual` / Kotlin `componentN` / `copy` / enum `values` / `valueOf`)### Good@@ -69,7 +71,6 @@ resolvers for each language.| Language | Extensions | Entry Points | Import Style ||----------|-----------|-------------|-------------|| **C** | `.c` | `main.c` | `#include` with `compile_commands.json` (shares C++ grammar) |-| **Kotlin** | `.kt` `.kts` | `Main.kt` `Application.kt` | `import com.example.Foo` with Gradle `settings.gradle(.kts)` subprojects + `sourceSets` overrides || **Ruby** | `.rb` | `main.rb` `app.rb` `config.ru` | `require 'mod'` / `require_relative './mod'` plus Rails / Zeitwerk autoloading (gated on `config/application.rb`) || **Swift** | `.swift` | `main.swift` `App.swift` | `import Foundation` with SPM `Package.swift` `targets:` → directory mapping || **Scala** | `.scala` | `Main.scala` `App.scala` | `import pkg.{A, B => C}` with SBT `build.sbt` / Mill `build.sc` multi-project parsing |diff --git a/tests/fixtures/jvm_sample/app/build.gradle.kts b/tests/fixtures/jvm_sample/app/build.gradle.ktsnew file mode 100644index 000000000..4c552b14d--- /dev/null+++ b/tests/fixtures/jvm_sample/app/build.gradle.kts@@ -0,0 +1,13 @@+plugins {+ id("org.springframework.boot") version "3.2.0"+ id("io.spring.dependency-management") version "1.1.4"+ java+ kotlin("jvm") version "1.9.20"+}++dependencies {+ implementation(libs.bundles.spring.web)+ compileOnly(libs.lombok)+ annotationProcessor(libs.lombok)+ implementation(project(":lib"))+}diff --git a/tests/fixtures/jvm_sample/app/src/main/java/com/sample/app/SampleApplication.java b/tests/fixtures/jvm_sample/app/src/main/java/com/sample/app/SampleApplication.javanew file mode 100644index 000000000..597391afb--- /dev/null+++ b/tests/fixtures/jvm_sample/app/src/main/java/com/sample/app/SampleApplication.java@@ -0,0 +1,11 @@+package com.sample.app;++import org.springframework.boot.SpringApplication;+import org.springframework.boot.autoconfigure.SpringBootApplication;++@SpringBootApplication+public class SampleApplication {+ public static void main(String[] args) {+ SpringApplication.run(SampleApplication.class, args);+ }+}diff --git a/tests/fixtures/jvm_sample/app/src/main/java/com/sample/app/model/User.java b/tests/fixtures/jvm_sample/app/src/main/java/com/sample/app/model/User.javanew file mode 100644index 000000000..70d1959cb--- /dev/null+++ b/tests/fixtures/jvm_sample/app/src/main/java/com/sample/app/model/User.java@@ -0,0 +1,19 @@+package com.sample.app.model;++import jakarta.persistence.Entity;+import jakarta.persistence.Id;+import lombok.Data;++@Entity+@Data+public class User {++ @Id+ private Long id;+ private String email;+ private String status;++ public static User empty() {+ return new User();+ }+}diff --git a/tests/fixtures/jvm_sample/app/src/main/java/com/sample/app/svc/UserRepository.java b/tests/fixtures/jvm_sample/app/src/main/java/com/sample/app/svc/UserRepository.javanew file mode 100644index 000000000..d38dfbcb2--- /dev/null+++ b/tests/fixtures/jvm_sample/app/src/main/java/com/sample/app/svc/UserRepository.java@@ -0,0 +1,11 @@+package com.sample.app.svc;++import com.sample.app.model.User;+import org.springframework.data.jpa.repository.JpaRepository;++import java.util.List;++public interface UserRepository extends JpaRepository<User, Long> {++ List<User> findByEmailAndStatus(String email, String status);+}diff --git a/tests/fixtures/jvm_sample/app/src/main/java/com/sample/app/web/UserController.java b/tests/fixtures/jvm_sample/app/src/main/java/com/sample/app/web/UserController.javanew file mode 100644index 000000000..32d4a3f14--- /dev/null+++ b/tests/fixtures/jvm_sample/app/src/main/java/com/sample/app/web/UserController.java@@ -0,0 +1,22 @@+package com.sample.app.web;++import com.sample.app.model.User;+import com.sample.app.svc.UserService;+import lombok.RequiredArgsConstructor;+import org.springframework.web.bind.annotation.GetMapping;+import org.springframework.web.bind.annotation.PathVariable;+import org.springframework.web.bind.annotation.RequestMapping;+import org.springframework.web.bind.annotation.RestController;++@RestController+@RequestMapping("/users")+@RequiredArgsConstructor+public class UserController {++ private final UserService userService;++ @GetMapping("/{id}")+ public User getUser(@PathVariable Long id) {+ return userService.findById(id);+ }+}diff --git a/tests/fixtures/jvm_sample/app/src/main/kotlin/com/sample/app/svc/UserService.kt b/tests/fixtures/jvm_sample/app/src/main/kotlin/com/sample/app/svc/UserService.ktnew file mode 100644index 000000000..2f732e473--- /dev/null+++ b/tests/fixtures/jvm_sample/app/src/main/kotlin/com/sample/app/svc/UserService.kt@@ -0,0 +1,20 @@+package com.sample.app.svc++import com.sample.app.model.User+import org.springframework.stereotype.Service++data class UserDto(val id: Long, val email: String, val status: String)++@Service+class UserService(private val repository: UserRepository) {++ fun findById(id: Long): User {+ return repository.findByEmailAndStatus("[email protected]", "ACTIVE")+ .firstOrNull()+ ?: User.empty()+ }++ companion object {+ fun defaultStatus(): String = "ACTIVE"+ }+}diff --git a/tests/fixtures/jvm_sample/app/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/tests/fixtures/jvm_sample/app/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.importsnew file mode 100644index 000000000..8b41071d6--- /dev/null+++ b/tests/fixtures/jvm_sample/app/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports@@ -0,0 +1 @@+com.sample.lib.MyPlugindiff --git a/tests/fixtures/jvm_sample/gradle/libs.versions.toml b/tests/fixtures/jvm_sample/gradle/libs.versions.tomlnew file mode 100644index 000000000..37cc718d8--- /dev/null+++ b/tests/fixtures/jvm_sample/gradle/libs.versions.toml@@ -0,0 +1,15 @@+[versions]+spring-boot = "3.2.0"+lombok = "1.18.30"+mapstruct = "1.5.5.Final"+junit = "5.10.0"++[libraries]+spring-boot-starter-web = { module = "org.springframework.boot:spring-boot-starter-web", version.ref = "spring-boot" }+spring-boot-starter-data-jpa = { module = "org.springframework.boot:spring-boot-starter-data-jpa", version.ref = "spring-boot" }+lombok = { module = "org.projectlombok:lombok", version.ref = "lombok" }+mapstruct = { module = "org.mapstruct:mapstruct", version.ref = "mapstruct" }+junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }++[bundles]+spring-web = ["spring-boot-starter-web", "spring-boot-starter-data-jpa"]diff --git a/tests/fixtures/jvm_sample/lib-it/build.gradle.kts b/tests/fixtures/jvm_sample/lib-it/build.gradle.ktsnew file mode 100644index 000000000..9d7194811--- /dev/null+++ b/tests/fixtures/jvm_sample/lib-it/build.gradle.kts@@ -0,0 +1,9 @@+plugins {+ java+}++sourceSets {+ create("integrationTest") {+ java.srcDirs("src/integrationTest/java")+ }+}diff --git a/tests/fixtures/jvm_sample/lib-it/src/integrationTest/java/com/sample/lib/it/PluginIT.java b/tests/fixtures/jvm_sample/lib-it/src/integrationTest/java/com/sample/lib/it/PluginIT.javanew file mode 100644index 000000000..21d6d4550--- /dev/null+++ b/tests/fixtures/jvm_sample/lib-it/src/integrationTest/java/com/sample/lib/it/PluginIT.java@@ -0,0 +1,15 @@+package com.sample.lib.it;++import com.sample.lib.MyPlugin;+import org.junit.jupiter.api.Test;++import static org.junit.jupiter.api.Assertions.assertEquals;++public class PluginIT {++ @Test+ public void loadsPlugin() {+ MyPlugin plugin = new MyPlugin();+ assertEquals("hello, my-plugin", plugin.name());+ }+}diff --git a/tests/fixtures/jvm_sample/lib/build.gradle.kts b/tests/fixtures/jvm_sample/lib/build.gradle.ktsnew file mode 100644index 000000000..3b371f30b--- /dev/null+++ b/tests/fixtures/jvm_sample/lib/build.gradle.kts@@ -0,0 +1,3 @@+plugins {+ java+}diff --git a/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/api/Plugin.java b/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/api/Plugin.javanew file mode 100644index 000000000..46c17391e--- /dev/null+++ b/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/api/Plugin.java@@ -0,0 +1,5 @@+package com.sample.api;++public interface Plugin {+ String name();+}diff --git a/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/MyPlugin.java b/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/MyPlugin.javanew file mode 100644index 000000000..0cd3cc09a--- /dev/null+++ b/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/MyPlugin.java@@ -0,0 +1,14 @@+package com.sample.lib;++import com.sample.api.Plugin;+import com.sample.lib.internal.Helper;++public class MyPlugin implements Plugin {++ private final Helper helper = new Helper();++ @Override+ public String name() {+ return helper.greet("my-plugin");+ }+}diff --git a/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/dead/ObviouslyDead.java b/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/dead/ObviouslyDead.javanew file mode 100644index 000000000..b5833c57a--- /dev/null+++ b/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/dead/ObviouslyDead.java@@ -0,0 +1,13 @@+package com.sample.lib.dead;++/**+ * Planted dead code: no importer, no framework annotation, no main, no+ * META-INF entry, no JPMS provides. The analyzer MUST flag this file+ * unreachable and the public method as an unused export.+ */+public class ObviouslyDead {++ public String deadGreeting() {+ return "i am dead";+ }+}diff --git a/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/internal/Helper.java b/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/internal/Helper.javanew file mode 100644index 000000000..29dd47ba0--- /dev/null+++ b/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/internal/Helper.java@@ -0,0 +1,7 @@+package com.sample.lib.internal;++public class Helper {+ public String greet(String name) {+ return "hello, " + name;+ }+}diff --git a/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/internal/HelperUser.java b/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/internal/HelperUser.javanew file mode 100644index 000000000..f069dd327--- /dev/null+++ b/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/internal/HelperUser.java@@ -0,0 +1,17 @@+package com.sample.lib.internal;++/**+ * Same-package sibling that references Helper with NO import line. The+ * JVM resolves the unqualified identifier `Helper` from the current+ * package; the indexer must honour the same rule (Phase 1 same-package+ * implicit access) so this file is reachable via the package fan-out+ * from MyPlugin's import of com.sample.lib.internal.Helper.+ */+public class HelperUser {++ private final Helper helper = new Helper();++ public String announce() {+ return helper.greet("internal");+ }+}diff --git a/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/package-info.java b/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/package-info.javanew file mode 100644index 000000000..704767bb6--- /dev/null+++ b/tests/fixtures/jvm_sample/lib/src/main/java/com/sample/lib/package-info.java@@ -0,0 +1,4 @@+/**+ * Sample library package.+ */+package com.sample.lib;diff --git a/tests/fixtures/jvm_sample/lib/src/main/java/module-info.java b/tests/fixtures/jvm_sample/lib/src/main/java/module-info.javanew file mode 100644index 000000000..b261004fd--- /dev/null+++ b/tests/fixtures/jvm_sample/lib/src/main/java/module-info.java@@ -0,0 +1,8 @@+module com.sample.lib {+ requires java.base;++ exports com.sample.api;+ exports com.sample.lib;++ provides com.sample.api.Plugin with com.sample.lib.MyPlugin;+}diff --git a/tests/fixtures/jvm_sample/lib/src/main/resources/META-INF/services/com.sample.api.Plugin b/tests/fixtures/jvm_sample/lib/src/main/resources/META-INF/services/com.sample.api.Pluginnew file mode 100644index 000000000..8b41071d6--- /dev/null+++ b/tests/fixtures/jvm_sample/lib/src/main/resources/META-INF/services/com.sample.api.Plugin@@ -0,0 +1 @@+com.sample.lib.MyPlugindiff --git a/tests/fixtures/jvm_sample/settings.gradle.kts b/tests/fixtures/jvm_sample/settings.gradle.ktsnew file mode 100644index 000000000..1eee7e648--- /dev/null+++ b/tests/fixtures/jvm_sample/settings.gradle.kts@@ -0,0 +1,3 @@+rootProject.name = "jvm-sample"++include(":app", ":lib", ":lib-it")diff --git a/tests/integration/test_jvm_dead_code.py b/tests/integration/test_jvm_dead_code.pynew file mode 100644index 000000000..98ec14dc4--- /dev/null+++ b/tests/integration/test_jvm_dead_code.py@@ -0,0 +1,141 @@+"""End-to-end JVM dead-code regression test for the jvm_sample fixture.++Runs the full FileTraverser -> ASTParser -> GraphBuilder -> DeadCodeAnalyzer+pipeline against tests/fixtures/jvm_sample and proves the JVM-parity work+(Phases 1-4) holds together end-to-end across a multi-module Gradle layout+mixing Java + Kotlin + Spring Boot + Lombok + JPA + Spring Data ++META-INF/services + JPMS provides...with + a non-main integrationTest+source set:++- the one planted genuinely-dead class is flagged,+- module-info.java / package-info.java are never flagged,+- every framework- or convention-loaded class is reached,+- same-package implicit access keeps internal siblings reachable,+- the integrationTest source set is reachable.++This is the regression guard that keeps the JVM analyzer honest: if a future+change over-suppresses (the live assertions hold but the dead assertions+fail) or regresses to false positives (the dead assertions hold but a live+assertion fails), this test breaks.+"""++from __future__ import annotations++from pathlib import Path++import pytest++from repowise.core.analysis.dead_code import DeadCodeAnalyzer, DeadCodeKind+from repowise.core.ingestion import ASTParser, FileTraverser, GraphBuilder++JVM_SAMPLE = Path(__file__).parent.parent / "fixtures" / "jvm_sample"++[email protected](scope="module")+def jvm_report():+ traverser = FileTraverser(JVM_SAMPLE)+ parser = ASTParser()+ builder = GraphBuilder(repo_path=JVM_SAMPLE)++ for fi in traverser.traverse():+ source = Path(fi.abs_path).read_bytes()+ builder.add_file(parser.parse_file(fi, source))++ graph = builder.build()++ # Mirror the production pipeline: framework + dynamic edges after build.+ builder.add_framework_edges([])+ try:+ from repowise.core.ingestion.dynamic_hints import HintRegistry++ registry = HintRegistry()+ builder.add_dynamic_edges(registry.extract_all(JVM_SAMPLE))+ except Exception:+ pass++ analyzer = DeadCodeAnalyzer(graph, git_meta_map={})+ report = analyzer.analyze({"min_confidence": 0.0})+ return report+++def _names(report, kind) -> set[str]:+ return {f.symbol_name for f in report.findings if f.kind == kind}+++def _paths(report, kind) -> set[str]:+ return {f.file_path for f in report.findings if f.kind == kind}+++class TestJvmSampleHonesty:+ def test_planted_dead_file_is_unreachable(self, jvm_report) -> None:+ unreachable = _paths(jvm_report, DeadCodeKind.UNREACHABLE_FILE)+ assert any("dead/ObviouslyDead.java" in p for p in unreachable), (+ "ObviouslyDead.java should be flagged unreachable — it has no "+ "importer, no framework annotation, no main, no META-INF entry"+ )++ def test_planted_dead_export_is_flagged(self, jvm_report) -> None:+ exports = _names(jvm_report, DeadCodeKind.UNUSED_EXPORT)+ assert "deadGreeting" in exports or "ObviouslyDead" in exports+++class TestJvmSampleNoFalsePositives:+ def test_module_info_and_package_info_never_flagged(self, jvm_report) -> None:+ unreachable = _paths(jvm_report, DeadCodeKind.UNREACHABLE_FILE)+ for never_flag in ("module-info.java", "package-info.java"):+ assert not any(p.endswith(never_flag) for p in unreachable), (+ f"{never_flag} should never be flagged unreachable"+ )++ def test_spring_boot_entry_point_reachable(self, jvm_report) -> None:+ unreachable = _paths(jvm_report, DeadCodeKind.UNREACHABLE_FILE)+ assert not any("SampleApplication.java" in p for p in unreachable)++ def test_spring_stereotype_files_reachable(self, jvm_report) -> None:+ unreachable = _paths(jvm_report, DeadCodeKind.UNREACHABLE_FILE)+ for live in (+ "web/UserController.java",+ "svc/UserService.kt",+ "svc/UserRepository.java",+ "model/User.java",+ ):+ assert not any(live in p for p in unreachable), (+ f"{live} wrongly unreachable — Spring stereotype / "+ "JpaRepository should rescue it"+ )++ def test_jpa_repository_methods_not_dead_exports(self, jvm_report) -> None:+ exports = _names(jvm_report, DeadCodeKind.UNUSED_EXPORT)+ # Derived-query methods on a Spring Data repository are entry+ # points — Spring synthesizes implementations at runtime.+ assert "findByEmailAndStatus" not in exports++ def test_service_loader_and_jpms_provides_rescue_my_plugin(self, jvm_report) -> None:+ unreachable = _paths(jvm_report, DeadCodeKind.UNREACHABLE_FILE)+ assert not any("lib/MyPlugin.java" in p for p in unreachable), (+ "MyPlugin should be reachable via META-INF/services and "+ "JPMS provides...with"+ )++ def test_same_package_sibling_reachable(self, jvm_report) -> None:+ unreachable = _paths(jvm_report, DeadCodeKind.UNREACHABLE_FILE)+ # HelperUser has no explicit importer; it should be reachable via+ # the package fan-out from MyPlugin's import of Helper.+ assert not any("internal/HelperUser.java" in p for p in unreachable)+ assert not any("internal/Helper.java" in p for p in unreachable)++ def test_integration_test_source_set_reachable(self, jvm_report) -> None:+ unreachable = _paths(jvm_report, DeadCodeKind.UNREACHABLE_FILE)+ exports = _names(jvm_report, DeadCodeKind.UNUSED_EXPORT)+ assert not any("PluginIT.java" in p for p in unreachable), (+ "integrationTest source-set files must be never-flagged"+ )+ assert "loadsPlugin" not in exports++ def test_kotlin_cross_language_reachable(self, jvm_report) -> None:+ # UserService.kt calls User.empty() (Java) and is called from+ # UserController.java — cross-language resolution should keep+ # both sides reachable (covered above) and the Kotlin file's+ # exported class shouldn't be flagged unused.+ exports = _names(jvm_report, DeadCodeKind.UNUSED_EXPORT)+ assert "UserService" not in exports