[code-reflection] RFR: CodeElement ancestor functionality [v2]

Paul Sandoz psandoz at openjdk.org
Tue Jul 8 16:19:26 UTC 2025


> Declare common ancestor methods on `CodeElement`. This enables more uniform traversal up the tree of code elements and querying of ancestors.
> 
> The expression `e.ancestorOp().ancestorOp()` will first traverse up the code model tree from `e` to the nearest ancestor operation and then traverse again to the subsequent nearest ancestor operation, both skipping intermediate block and body elements. The first traversal can start from any kind of code element.
> 
> The methods `ancestor{Op, Body, Block}` are currently implemented as default methods. While the implementations are simple it is easy to make mistakes handling unbound or root operations. They can be more directly implemented in a follow on PR.

Paul Sandoz has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains eight additional commits since the last revision:

 - Merge remote-tracking branch 'upstream/code-reflection' into ancestor
 - Cleanup.
 - Doc updates.
 - Adjust isAncestorOf. Add test.
 - Update examples.
 - Merge remote-tracking branch 'upstream/code-reflection' into ancestor
 - Uses. Add CodeElement.isAncestorOf.
 - Unify ancestor functionality on CodeElement.

-------------

Changes:
  - all: https://git.openjdk.org/babylon/pull/479/files
  - new: https://git.openjdk.org/babylon/pull/479/files/56e8c185..54107d94

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=babylon&pr=479&range=01
 - incr: https://webrevs.openjdk.org/?repo=babylon&pr=479&range=00-01

  Stats: 485 lines in 68 files changed: 100 ins; 94 del; 291 mod
  Patch: https://git.openjdk.org/babylon/pull/479.diff
  Fetch: git fetch https://git.openjdk.org/babylon.git pull/479/head:pull/479

PR: https://git.openjdk.org/babylon/pull/479


More information about the babylon-dev mailing list