Repository navigation
Compute tree positions without the SourcePositions methods JDK 27 deprecates - #2257
Merged
Merged
Conversation
…recates JDK 27 deprecates SourcePositions.getStartPosition(CompilationUnitTree, Tree) and getEndPosition(CompilationUnitTree, Tree) for removal, so the framework's calls to them carried @SuppressWarnings("removal") with a TODO to encapsulate them. Add TreeUtils.getStartPosition(Tree) and TreeUtils.getEndPosition(CompilationUnitTree, Tree), which compute what javac's implementation of those methods computes: JCTree.getStartPosition(), and the end position from the tree, or, before JDK-8372948, from the compilation unit's end-position table. Use them in SourceChecker, BaseTypeVisitor and LspTypeInformationPresenter. A jtreg test pins the source range that -Adetailedmsgtext reports, which no test checked. SuggestedFixData keeps its SourcePositions parameter and its suppressions: its API takes the SourcePositions to use from the caller. Fixes #1637. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ameter of SuggestedFixData BaseTypeVisitor#positions and LspTypeInformationReporter#sourcePositions are unused. SuggestedFixData#replaceTree and #deleteTree, which have not been in a release, locate the tree with TreeUtils instead of a SourcePositions argument. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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.
Fixes #1637.
JDK 27 deprecates
SourcePositions.getStartPosition(CompilationUnitTree, Tree)andgetEndPosition(CompilationUnitTree, Tree)for removal. The framework's calls to them carried@SuppressWarnings("removal")with a "TODO: encapsulate methods".This PR adds
TreeUtils.getStartPosition(Tree)andTreeUtils.getEndPosition(CompilationUnitTree, Tree). They compute what javac'sJavacTreesimplementation of those methods does:JCTree.getStartPosition()(that is,TreeInfo.getStartPos).JCTree.getEndPosition()on JDKs with JDK-8372948. On earlier JDKs it isJCTree.getEndPosition(root.endPositions). A method handle chooses between the two once, the same wayTreePathUtil.getEndPositionin the Annotation File Utilities does. The AFU does not depend on javacutil, so I did not share the code.The helpers replace the suppressed calls in
SourceChecker(-Adetailedmsgtext),BaseTypeVisitor(three sites), andLspTypeInformationPresenter. No test checked the range that-Adetailedmsgtextprints, so a jtreg reference-output test,checker/jtreg/detailedmsgtext/DetailedMsgTextPositions.java, now pins it.The unused
protectedfieldsBaseTypeVisitor.positionsandLspTypeInformationReporter.sourcePositionsare removed.SuggestedFixData.replaceTreeanddeleteTreeno longer take aSourcePositionsargument and useTreeUtilsinstead; neither method has been in a release.There is no JDK 27 locally, so the JDK 27/28 CI jobs are what check the new code path.
Locally (JDK 25):
assembleForJavac,:framework:test,:javacutil:test,:framework:jtregTests,:checker:jtregTests,:checker:jtregJdk11Tests,spotlessCheck,checkInterningandcheckNullnessfor javacutil and framework.