Skip to content

Java: Rename several AST predicates.#21267

Merged
aschackmull merged 7 commits intogithub:mainfrom
aschackmull:java/rename-misc
Feb 5, 2026
Merged

Java: Rename several AST predicates.#21267
aschackmull merged 7 commits intogithub:mainfrom
aschackmull:java/rename-misc

Conversation

@aschackmull
Copy link
Contributor

This is in preparation for the CFG work and an attempt to move towards greater consistency across languages.

@aschackmull aschackmull marked this pull request as ready for review February 5, 2026 08:00
@aschackmull aschackmull requested review from a team as code owners February 5, 2026 08:00
Copilot AI review requested due to automatic review settings February 5, 2026 08:00
Copy link
Contributor

Copilot AI left a 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.getExprgetOperand, ConditionalExpr.getTrueExpr/getFalseExprgetThen/getElse, ReturnStmt.getResultgetExpr, and loop statement getStmtgetBody
  • 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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@owen-mc
Copy link
Contributor

owen-mc commented Feb 5, 2026

Why delay deprecation of ReturnStmt.getResult()?

@aschackmull
Copy link
Contributor Author

Why delay deprecation of ReturnStmt.getResult()?

Because of submodules.

@aschackmull aschackmull merged commit 29e0174 into github:main Feb 5, 2026
20 checks passed
@aschackmull aschackmull deleted the java/rename-misc branch February 5, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants