Skip to content

Remove an unprinted annotation from the AST, not from the pretty-printer - #8183

Merged
mernst merged 1 commit into
masterfrom
ajava-remove-annotations-from-ast
Sep 17, 2026
Merged

mernst merged 1 commit into
masterfrom
ajava-remove-annotations-from-ast

Conversation

@mernst

@mernst mernst commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Part 2 of 6, splitting #8177 into reviewable pieces. This one is independent of #8182 and can merge in parallel with it; parts 3-6 build on it.

To avoid cluttering an ajava file, whole-program inference does not print the invisible qualifiers. It suppressed them by overriding the pretty-printer's three visit(...AnnotationExpr) methods to return without printing. By the time the pretty-printer visits an annotation it has already printed the whitespace that separates the annotation from what follows it, so each suppressed annotation leaves a stray space or blank line: java.util. Date, static double, String [] [].

Instead, remove the annotations that should not be printed from a clone of the compilation unit, and print that. The pretty-printer then outputs no separator for them. The clone is needed because the removal is a side effect and the AST is printed once per checker that was run.

No test output changes. The test checkers declare no invisible qualifier, so nothing is removed in the test suite. The refactoring is worthwhile on its own for the stray whitespace it fixes for a checker that does declare one, and it is a prerequisite for #8184: omitting irrelevant annotations in the pretty-printer would leave the same stray whitespace on every annotation omitted.

🤖 Generated with Claude Code

To avoid cluttering an ajava file, whole-program inference does not print the
invisible qualifiers.  It suppressed them by overriding the pretty-printer's
three `visit(...AnnotationExpr)` methods to return without printing.  By the
time the pretty-printer visits an annotation, it has already printed the
whitespace that separates the annotation from what follows it, so each
suppressed annotation leaves a stray space or blank line:  `java.util. Date`,
`static   double`, `String  []  []`.  That partly defeats the purpose of not
printing the annotation, which is to reduce clutter.

Instead, remove the annotations that should not be printed from a clone of the
compilation unit, and print that.  The pretty-printer then outputs no
separator for them.  The clone is necessary because the removal is a side
effect, and the AST is printed once per checker that was run.

No test output changes:  the test checkers declare no invisible qualifier, so
nothing is removed in the test suite.  This refactoring is worthwhile on its
own for the stray whitespace it fixes for a checker that does declare one, and
it is a prerequisite for omitting irrelevant annotations, which would
otherwise leave the same stray whitespace on every annotation it omits.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: aaa5ff67-d9d3-4bb5-9cc5-18f77004f6cb

📥 Commits

Reviewing files that changed from the base of the PR and between e405420 and 5b90bc6.

📒 Files selected for processing (1)
  • framework/src/main/java/org/checkerframework/common/wholeprograminference/WholeProgramInferenceJavaParserStorage.java

Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

writeAjavaFile now clones the compilation unit before output. A new removeUnprintedAnnotations method removes invisible qualifier annotations from NodeWithAnnotations nodes and parameter varargs annotations. The method uses getInvisibleQualifierNames(atypeFactory). The previous pretty-printer visitor overrides and related imports were removed.

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 5b90b

The output change removes invisible annotations from the cloned AST without leaving a verified annotation path unfiltered, so no merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ajava-remove-annotations-from-ast

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mernst
mernst merged commit 6cc7873 into master Sep 17, 2026
57 checks passed
@mernst
mernst deleted the ajava-remove-annotations-from-ast branch September 17, 2026 01:53
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.

1 participant