Repository navigation
Conversation
A check that decides by the context of an expression reads the parent of its path, and when the expression is in redundant parentheses that parent is a ParenthesizedTree. ASTHelpers had stripParentheses for looking down into an expression and nothing for looking up out of the parentheses around it, so six places carried their own loop: TargetType.targetType, EqualsGetClass (makeAlwaysFalse and removeFromBinary), HashCodeInObjectsHash, RandomCast, and PatternMatchingInstanceof.isVariableAssignedFromCast. The change alters no finding. outermostParenthesized(TreePath) returns the path to the outermost ParenthesizedTree in the chain that wraps the leaf, or the path itself when the leaf is not wrapped. It returns a path rather than the parent leaf: the returned leaf is a direct child of the parent, so a caller can find an argument position with getArguments().indexOf. The six loops now call it. AssignmentExpression and BadInstanceof inspect only one level of parentheses and are left alone, because switching them changes their findings; google#6218 and google#5845 track that. PatternMatchingInstanceof.getUsage expands the usage by exactly one level on purpose. Fixes google#6226 Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
A check that decides by the context of an expression reads the parent of its path, and when the expression is in redundant parentheses that parent is a
ParenthesizedTree.ASTHelpershadstripParenthesesfor looking down into an expression and nothing for looking up out of the parentheses around it, so six places carried their own loop:TargetType.targetType,EqualsGetClass(makeAlwaysFalseandremoveFromBinary),HashCodeInObjectsHash,RandomCast, andPatternMatchingInstanceof.isVariableAssignedFromCast. The last one is not in the issue's list; it walked the parent path withdropWhile(PARENTHESIZED). The change alters no finding.outermostParenthesized(TreePath)returns the path to the outermostParenthesizedTreein the chain that wraps the leaf, or the path itself when the leaf is not wrapped. It returns a path rather than the parent leaf: the returned leaf is a direct child of the parent, so a caller can find an argument position withgetArguments().indexOf. The six loops now call it.AssignmentExpressionandBadInstanceofinspect only one level of parentheses and are left alone, because switching them changes their findings; #6218 and #5845 track that.PatternMatchingInstanceof.getUsageexpands the usage by exactly one level on purpose.Verification
ASTHelpersTestcoversx,(x), and((x))as a call argument (all three give the sameMethodInvocationTreeand the argument itself as the leaf), a leaf whose grandparent but not parent is parenthesized, and the root path. TheTargetTypetestdata gains a two-level parenthesized enhanced-for iterable. The tests of the changed checks already have parenthesized inputs at each changed site, and they pass.check_api/pom.xmlexcludesASTHelpersTestandTargetTypeTestfrom the Maven build, so I compiled and ran both by hand againstcore's test classpath: 70 tests pass. Each of three mutants of the helper fails a new test: a singleifinstead of the loop fails the call-argument test andTargetTypeTest, climbing to the lastParenthesizedTreeamong all ancestors fails the grandparent test, and dropping the null check fails the root-path test.Fixes #6226
🤖 Generated with Claude Code