Support package annotation subpackage opt-outs - #1996
Open
aosen-xiong wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an applyToSubpackages element (default true) to several package-applicable annotations so users can opt out of having an enclosing package’s annotation implicitly apply to subpackages, while preserving existing behavior by default. This updates the framework’s package-walk logic to respect the opt-out and adds tests and documentation to lock in the semantics.
Changes:
- Extend
@AnnotatedFor,@HasQualifierParameter, and@ReportUsewithapplyToSubpackages(defaulttrue) and update package-chain lookup to gate propagation to enclosing packages on that element. - Add regression tests covering both opt-in (default behavior) and opt-out behavior, including transitive subpackages.
- Document the new behavior in the manual and changelog, including compatibility behavior when an older
checker-qualis on the classpath.
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java | Adds reflective access to new elements; gates @HasQualifierParameter package propagation; exposes doesAnnotatedForApplyToSubpackages. |
| framework/src/main/java/org/checkerframework/common/basetype/BaseTypeChecker.java | Updates @AnnotatedFor package propagation logic to respect opt-out via a dedicated “reaches subpackages” cache. |
| framework/src/main/java/org/checkerframework/common/util/report/ReportVisitor.java | Updates @ReportUse lookup to respect applyToSubpackages for enclosing packages (but always apply to the annotated package itself). |
| checker-qual/src/main/java/org/checkerframework/framework/qual/AnnotatedFor.java | Adds applyToSubpackages element and documents package/subpackage semantics. |
| checker-qual/src/main/java/org/checkerframework/framework/qual/HasQualifierParameter.java | Adds applyToSubpackages element and updates Javadoc to describe opt-out behavior. |
| checker-qual/src/main/java/org/checkerframework/common/util/report/qual/ReportUse.java | Converts marker annotation to include applyToSubpackages element and documents semantics. |
| framework/tests/report/reportuseoptin/package-info.java | Package-level @ReportUse opt-in coverage test (default behavior). |
| framework/tests/report/reportuseoptin/InInnerPackage.java | ReportUse opt-in: direct subpackage should be reported. |
| framework/tests/report/reportuseoptin/InNestedSubpackage.java | ReportUse opt-in: transitive subpackage should be reported. |
| framework/tests/report/reportuseoptin/Uses.java | ReportUse opt-in: verifies uses in nested packages trigger diagnostics. |
| framework/tests/report/reportuseoptout/package-info.java | Package-level @ReportUse(applyToSubpackages=false) opt-out coverage test. |
| framework/tests/report/reportuseoptout/InPackage.java | ReportUse opt-out: annotated package still reported. |
| framework/tests/report/reportuseoptout/InNestedSubpackage.java | ReportUse opt-out: transitive subpackage excluded. |
| framework/tests/report/reportuseoptout/Uses.java | ReportUse opt-out: verifies subpackages are excluded while package remains covered. |
| framework/tests/conservative-defaults/annotatedfor/subpkgoptin/package-info.java | @AnnotatedFor opt-in package propagation test setup. |
| framework/tests/conservative-defaults/annotatedfor/subpkgoptin/InPackage.java | @AnnotatedFor opt-in: package itself in scope (errors expected). |
| framework/tests/conservative-defaults/annotatedfor/subpkgoptin/InSubpackage.java | @AnnotatedFor opt-in: direct subpackage in scope (errors expected). |
| framework/tests/conservative-defaults/annotatedfor/subpkgoptin/InNestedSubpackage.java | @AnnotatedFor opt-in: transitive subpackage in scope (errors expected). |
| framework/tests/conservative-defaults/annotatedfor/subpkgoptout/package-info.java | @AnnotatedFor(applyToSubpackages=false) opt-out test setup. |
| framework/tests/conservative-defaults/annotatedfor/subpkgoptout/InPackage.java | @AnnotatedFor opt-out: annotated package still in scope (errors expected). |
| framework/tests/conservative-defaults/annotatedfor/subpkgoptout/InSubpackage.java | @AnnotatedFor opt-out: direct subpackage excluded (no errors expected). |
| framework/tests/conservative-defaults/annotatedfor/subpkgoptout/InNestedSubpackage.java | @AnnotatedFor opt-out: transitive subpackage excluded (no errors expected). |
| checker/tests/tainting/hqpoptin/package-info.java | @HasQualifierParameter opt-in test setup for package propagation. |
| checker/tests/tainting/hqpoptin/InSubpackage.java | @HasQualifierParameter opt-in: subpackage inherits qualifier parameter (poly use allowed). |
| checker/tests/tainting/hqpoptin/InNestedSubpackage.java | @HasQualifierParameter opt-in: transitive subpackage inherits qualifier parameter. |
| checker/tests/tainting/hqpoptout/package-info.java | @HasQualifierParameter(applyToSubpackages=false) opt-out test setup. |
| checker/tests/tainting/hqpoptout/InPackage.java | @HasQualifierParameter opt-out: annotated package still has qualifier parameter. |
| checker/tests/tainting/hqpoptout/InSubpackage.java | @HasQualifierParameter opt-out: subpackage excluded (poly use rejected). |
| checker/tests/tainting/hqpoptout/InNestedSubpackage.java | @HasQualifierParameter opt-out: transitive subpackage excluded (poly use rejected). |
| docs/manual/annotating-libraries.tex | Documents package-level @AnnotatedFor and the new opt-out element. |
| docs/manual/generics.tex | Documents package-level @HasQualifierParameter opt-out behavior. |
| docs/manual/advanced-features.tex | Documents @DefaultQualifier(applyToSubpackages=false) as the existing analogous mechanism. |
| docs/CHANGELOG.md | Records user-visible behavior and the new API/method for package propagation gating. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Closes #1990.
Merge with eisop/jdk#138.
Adds
applyToSubpackagesto@AnnotatedFor,@HasQualifierParameter, and@ReportUse. The element defaults totrueto preserve existing behavior.Package lookup applies an annotation from an enclosing package only when
applyToSubpackagesistrue. An annotation always applies to the package where it is written.Tests are organized into opt-in and opt-out directories for each annotation:
trueand check that the annotation reaches direct and transitively nested subpackages.applyToSubpackages=falseand check that the annotated package remains covered while direct and transitively nested subpackages are excluded.Each package annotation and its package/subpackage classes are compiled in the same per-directory test invocation. This is particularly necessary for
@AnnotatedFor, which has source retention.