Java: Rename several AST predicates.#21267
Merged
aschackmull merged 7 commits intogithub:mainfrom Feb 5, 2026
Merged
Conversation
949de90 to
2d02908
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR systematically renames several Java AST predicates to achieve greater consistency across CodeQL languages in preparation for CFG (Control Flow Graph) work. The changes are purely mechanical renames with deprecated aliases maintained for backward compatibility.
Changes:
- Renamed predicates across core AST classes:
UnaryExpr.getExpr→getOperand,ConditionalExpr.getTrueExpr/getFalseExpr→getThen/getElse,ReturnStmt.getResult→getExpr, and loop statementgetStmt→getBody - Updated all usages of renamed predicates across test files, queries, and library code
- Added deprecation markers to old predicate names for backward compatibility
Reviewed changes
Copilot reviewed 79 out of 79 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| java/ql/lib/semmle/code/java/Statement.qll | Core changes: Added getBody() to loop statements with deprecated getStmt(), added getExpr() to ReturnStmt with deprecated getResult(), refactored LoopStmt hierarchy |
| java/ql/lib/semmle/code/java/Expr.qll | Core changes: Added getOperand() to UnaryExpr with deprecated getExpr(), added getThen()/getElse() to ConditionalExpr with deprecated getTrueExpr()/getFalseExpr() |
| java/ql/lib/semmle/code/java/controlflow/Guards.qll | Simplified NotExpr and ConditionalExpr to type aliases since methods now exist on base classes |
| java/ql/lib/change-notes/2026-02-04-renames.md | Documents all predicate renames |
| java/ql/lib/semmle/code/java/*.qll | Updated all usages of renamed predicates in library files |
| java/ql/src/**/.ql,.qll | Updated all usages in query and library files |
| java/ql/test*/**/*.ql | Updated all test query usages |
| java/ql/examples/**/*.ql | Updated example query usages |
hvitved
reviewed
Feb 5, 2026
| /** A common super-class that represents unary operator expressions. */ | ||
| class UnaryExpr extends Expr, @unaryexpr { | ||
| /** | ||
| * DEPRECATED: Use getOperand() instead. |
| Expr getCondition() { result.isNthChildOf(this, 0) } | ||
|
|
||
| /** | ||
| * DEPRECATED: Use getThen() instead. |
| deprecated Expr getTrueExpr() { result.isNthChildOf(this, 1) } | ||
|
|
||
| /** | ||
| * DEPRECATED: Use getElse() instead. |
| /** A `return` statement. */ | ||
| class ReturnStmt extends Stmt, @returnstmt { | ||
| /** | ||
| * DEPRECATED: Use getExpr() instead. |
| } | ||
|
|
||
| /** | ||
| * DEPRECATED: Use getBody() instead. |
| Expr getExpr() { result.isNthChildOf(this, 1) } | ||
|
|
||
| /** | ||
| * DEPRECATED: Use getBody() instead. |
| override Expr getCondition() { result.getParent() = this } | ||
|
|
||
| /** | ||
| * DEPRECATED: Use getBody() instead. |
| override Expr getCondition() { result.getParent() = this } | ||
|
|
||
| /** | ||
| * DEPRECATED: Use getBody() instead. |
Contributor
|
Why delay deprecation of |
Contributor
Author
Because of submodules. |
owen-mc
approved these changes
Feb 5, 2026
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.
This is in preparation for the CFG work and an attempt to move towards greater consistency across languages.