Skip to content

Track Java->Java dependencies on inlined constants (#145)#1721

Open
jozanek wants to merge 1 commit into
sbt:developfrom
jozanek:fix/issue-145-java-constant-deps
Open

Track Java->Java dependencies on inlined constants (#145)#1721
jozanek wants to merge 1 commit into
sbt:developfrom
jozanek:fix/issue-145-java-constant-deps

Conversation

@jozanek

@jozanek jozanek commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #145.

Scope (resolves the issue's "TBD: is there some mention in the classfile?")

Checked with javap: ordinary constant uses (field initializers, method bodies, import static in expressions) keep the owning class as a CONSTANT_Class entry and are already tracked. The owner is erased entirely only when the constant is used as an annotation value (@Anno(B.MAX)) or a switch-case label (case B.MAX:). And it only causes staleness across a compilation boundary — within a module compileAllJava recompiles all Java together, and pipelining recompiles all Java each cycle. So the real gap: a Java class depending on a separately-compiled Java class only through a constant in an annotation value or switch-case label.

Approach

Recover the edges from javac's attributed AST, which keeps the resolved symbol the bytecode dropped. LocalJavaCompiler registers a TaskListener; at ANALYZE a TreePathScanner records, for each compile-time-constant reference, an edge from the enclosing class to (a) the declaring class and (b) the type named at the reference site — the member-select qualifier (Sub.K) or a contributing static import incl. wildcards. (b) matters for inherited constants, so a later change to the named subtype also recompiles the dependent. The map is returned from runWithConstantDeps (no shared mutable state) and fed into the existing JavaAnalyze member-ref path, so in-project owners become class deps and classpath owners become binary deps.

com.sun.source.* is exported by jdk.compiler — no --add-exports/--add-opens needed.

Limitation

Only in-process (local) javac is hooked; forked / custom JavaCompiler clients don't get this tracking.

@jozanek jozanek marked this pull request as ready for review June 18, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dependencies on java constants from java code not recognized

1 participant