-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Java: Rename several AST predicates. #21267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
949de90 to
2d02908
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
| /** A common super-class that represents unary operator expressions. */ | ||
| class UnaryExpr extends Expr, @unaryexpr { | ||
| /** | ||
| * DEPRECATED: Use getOperand() instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: backticks
| Expr getCondition() { result.isNthChildOf(this, 0) } | ||
|
|
||
| /** | ||
| * DEPRECATED: Use getThen() instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
| deprecated Expr getTrueExpr() { result.isNthChildOf(this, 1) } | ||
|
|
||
| /** | ||
| * DEPRECATED: Use getElse() instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
| /** A `return` statement. */ | ||
| class ReturnStmt extends Stmt, @returnstmt { | ||
| /** | ||
| * DEPRECATED: Use getExpr() instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
| } | ||
|
|
||
| /** | ||
| * DEPRECATED: Use getBody() instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
| Expr getExpr() { result.isNthChildOf(this, 1) } | ||
|
|
||
| /** | ||
| * DEPRECATED: Use getBody() instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
| override Expr getCondition() { result.getParent() = this } | ||
|
|
||
| /** | ||
| * DEPRECATED: Use getBody() instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
| override Expr getCondition() { result.getParent() = this } | ||
|
|
||
| /** | ||
| * DEPRECATED: Use getBody() instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
|
Why delay deprecation of |
Because of submodules. |
This is in preparation for the CFG work and an attempt to move towards greater consistency across languages.