Record documentation-comment reference packages in TypesInUse#8078
Merged
Conversation
knutwannheden
force-pushed
the
fancy-bison
branch
from
June 19, 2026 09:47
26ac9f2 to
99b38d7
Compare
TypesInUseTypesInUse
`TypesInUse` deliberately excludes fully qualified documentation-comment
references (Javadoc `{@link ...}`, and the equivalent in other languages
that share the `JavaType` attribution) from its import-retention set
(#5738), since such references need no import. `ChangePackage` therefore
carried its own LST walk to rediscover exactly those references for its
precondition — duplicating the "is this a fully qualified doc reference"
predicate, which is how the regression fixed in #7284 originally crept in.
Capture the packages of those references in a separate transient
`docReferencePackages` bucket during the single `FindTypesInUse` walk, and
have `ChangePackage` query it via `hasDocReferenceInPackage`. Only the
package is retained, since that is all package-renaming recipes ask. The
import-retention set is unchanged, so `RemoveUnusedImports`/`UsesType`/the
FQN trie behave exactly as before. The bucket is not serialized
(`TypesInUse.of` leaves it empty) and is queried only through
`hasDocReferenceInPackage`; the raw set is not exposed.
knutwannheden
force-pushed
the
fancy-bison
branch
from
June 19, 2026 11:10
99b38d7 to
f04e4dd
Compare
TypesInUseTypesInUse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
TypesInUsedeliberately excludes fully qualified documentation-comment references (Javadoc{@link com.foo.Bar}, and the equivalent constructs in the other languages that share theJavaTypeattribution — C#<see cref="..."/>, etc.) from its import-retention set, because such a reference needs no import and must not count toward import retention (#5738). The consequence is thatChangePackagecould not rely onTypesInUseto discover those references, so it grew its own dedicated full-compilation-unit walk to rediscover them for its precondition. That duplicated the "is this a fully qualified doc reference" predicate in two places with opposite intent —FindTypesInUseto exclude,ChangePackageto recover — which is precisely the kind of drift that produced the regression fixed in #7284. It also meant an extra per-file, per-recipe-instance traversal alongside the oneTypesInUsealready performs and caches.This records the packages of those excluded references once, as a byproduct of the single
FindTypesInUsewalk, and letsChangePackageconsume them — removing the duplicated predicate and the redundant traversal. Only the package is retained, since that is all a package-renaming recipe asks of a doc reference; this also keeps the in-memory shape aligned with the package-keyed form a future serialized precondition would use.Examples
ChangePackage's precondition doc-reference branch collapses from its own dedicated full-tree visitor to a single lookup against the already-cachedTypesInUse:Summary
docReferencePackagesbucket toTypesInUse, populated duringFindTypesInUsewith the packages of fully qualified documentation-comment references — the references that are (still) excluded from the import-retentiontypesInUseset.RemoveUnusedImports,UsesType, and the FQN trie behave exactly as before. The new bucket is consulted only by callers that explicitly want it.TypesInUse.hasDocReferenceInPackage(packageName, recursive), mirroring the per-type package check package-renaming recipes apply totypesInUse. The raw set is not exposed — the query method is the only entry point.ChangePackage's precondition to call it and delete its bespoke documentation-comment walk, so the fully-qualified-doc-reference predicate now lives in exactly one place.TypesInUse.build(...)and left empty byTypesInUse.of(...), since a serialized type index carries no doc references. No serialization-format change.Test plan
TypesInUseTest.recordsFullyQualifiedJavadocReferencesSeparately— uses a Java{@link}fixture to verify the reference is excluded fromgetTypesInUse()yet its package is discoverable viahasDocReferenceInPackage, covering exact / recursive / non-matching package queries.ChangePackageTest(including the#2537fully-qualified-Javadoc cases) stays green — behavior preserved.RemoveUnusedImportsTeststays green — the import-retention set is unchanged (Remove fully qualified JavaDoc references fromTypesInUseforRemoveUnusedImports#5738 behavior intact).ChangePackageTeststays green — the shared recipe behaves the same on the extendedJmodel.