/** * Java's dominant unit-test convention places a test class in the SAME * package as its subject, with no `import` statement connecting them at all * -- Java, like Go, grants unqualified access to every other type in the * same package (#925). Unlike Go, this is NOT bounded to a single directory: * a real Gradle/Maven multi-module build routinely puts the test class in a * *different* module's source root that happens to declare the identical * package. * * Measured against a real square/retrofit clone: ALL 101 of its test files * share a package with their subject but live in a different module's * `src//java/` tree entirely -- e.g. * `retrofit-adapters/guava/src/test/java/retrofit2/adapter/guava/ * GuavaCallAdapterFactoryTest.java` (package `retrofit2.adapter.guava`, zero * import for `GuavaCallAdapterFactory`) tests `retrofit-adapters/guava/ * src/main/java/retrofit2/adapter/guava/GuavaCallAdapterFactory.java` -- * same package, different directory. `chunk.metadata.imports` carries zero * signal for this, Java's own dominant unit-test shape, exactly the same * structural gap #902 named for Go. * * This module needs no `package` clause parsing to recover the signal. * Every real Java build tool (Maven, Gradle, and every IDE that reads * either) enforces the Standard Directory Layout: a source file always * lives at `.../src//java//ClassName.java`, where * `` is `main`, `test`, `androidTest`, or similar. Stripping that * fixed, well-known marker recovers the package-relative path * deterministically -- pure filepath-string reasoning, exactly like Go's * "same directory" is, just keyed on the path *after* the source-root * marker instead of the literal directory. A file that doesn't follow this * layout simply doesn't participate (see `javaPackageRelativePath`'s null * return) rather than falling back to a guess. * * Same two-tier discipline as Go's #902 (`go-same-directory-tests.ts`): * * - Tier 1, `pairJavaBasenameTest`: `Foo.java` <-> `FooTest.java`, same * package-relative directory, exact stem match. As trustworthy as a real * import match -- no hedging -- so callers fold this directly into their * existing test-association set (see `test-associations.ts` and * `get-files-context.ts`). * - Tier 2, `findJavaPackageLevelTests`: every test file sharing the * target's package-relative directory, used ONLY as a last resort when * tier 1 finds nothing for that specific file. Real, non-fabricated * same-package signal, but coarser -- callers must present it distinctly * (see `annotate-cmd.ts`'s honesty label), never with tier 1's * unqualified confidence. */ /** * Strip the `src//java/` prefix, returning the package-relative * path (directory + basename, extension already stripped by the caller's * own normalization -- mirrors `pairGoBasenameTest`'s `normalizedTarget` * contract). Returns null for a path that doesn't follow the convention; * callers must treat that as "does not participate", never as a fallback * to guess from. */ export declare function javaPackageRelativePath(normalizedPath: string): string | null; /** * A candidate Java test file, carrying both the form to add to a result set * (`file`) and its package-relative path (directory + basename) to compare * against -- mirrors `GoTestCandidate`'s `file`/`normalized` split. */ export interface JavaTestCandidate { /** The path to report back to the caller (e.g. `chunk.metadata.file`). */ file: string; /** Package-relative path (post `src//java/` strip, extension-stripped). */ packageRelative: string; } /** Package-relative directory -> every same-package-test-convention candidate in it. */ export type JavaTestDirIndex = ReadonlyMap; /** * Build a `JavaTestCandidate` from a (potential) test chunk's file, or * `null` when it doesn't follow the Standard Directory Layout (see * `javaPackageRelativePath`). Shared by every caller that builds a * `JavaTestDirIndex` from indexed chunks (`test-associations.ts`, * `get-files-context.ts`, `annotate-cmd.ts`) so the "does this path * participate" check can't drift between them. */ export declare function toJavaTestCandidate(file: string, normalize: (path: string) => string): JavaTestCandidate | null; /** * Build a package-relative-directory index from a list of candidate Java * test files. Callers build this once per scan (not per target file) and * reuse it -- mirrors `buildGoTestDirIndex`. */ export declare function buildJavaTestDirIndex(candidates: readonly JavaTestCandidate[]): JavaTestDirIndex; /** * Tier 1: the test file(s) sharing `normalizedTarget`'s package-relative * directory whose basename is exactly `Test` (Java's * `Foo.java` <-> `FooTest.java` convention). Returns the candidates' `file` * form, ready to add straight into a caller's test-association set. * * `normalizedTarget` must already be extension-stripped and workspace- * relative (same contract as `pairGoBasenameTest`). Returns `[]` for a * target that doesn't follow the Standard Directory Layout. * * No self-match guard is needed: the required candidate basename is * `normalizedTarget`'s own basename with a non-empty `Test` literal * appended, which can never equal `normalizedTarget`'s own basename again -- * mirrors `pairGoBasenameTest`'s reasoning exactly. */ export declare function pairJavaBasenameTest(normalizedTarget: string, dirIndex: JavaTestDirIndex): string[]; /** * Tier 2, fallback only: every same-package-test-convention test file * sharing `normalizedTarget`'s package-relative directory, regardless of * basename, EXCLUDING `normalizedTarget` itself. Without that exclusion, * calling this on a test file directly would list the file as covered by * itself. Callers must only consult this when tier 1 * (`pairJavaBasenameTest`) finds nothing for the same target, and must * present the result distinctly from a direct match -- mirrors * `findGoPackageLevelTests`'s discipline exactly. */ export declare function findJavaPackageLevelTests(normalizedTarget: string, dirIndex: JavaTestDirIndex): string[]; //# sourceMappingURL=java-same-package-tests.d.ts.map