[code-reflection] RFR: 8374550: API for casting Value to Op.Result and Block.Parameter

Paul Sandoz psandoz at openjdk.org
Mon Jan 5 21:19:26 UTC 2026


On Mon, 5 Jan 2026 20:58:14 GMT, Ruby Chen <duke at openjdk.org> wrote:

> This PR adds two methods, `Value::result()` and `Value::parameter()`, which cast a given Value as a Op.Result or Block.Parameter. If the cast fails, the two methods throw an IllegalStateException.

Looks good. Please add some +ve and -ve tests e.g., reflect on some simple code, stream over the values, and assert accordingly e.g., using say

    static Stream<Value> values(CodeElement<?, ?> r) {
        return r.elements().mapMulti((e, c) -> {
            switch (e) {
                case Block block -> block.parameters().forEach(c);
                case Op op -> c.accept(op.result());
                case Body _ -> { }
            }
        });
    }

src/jdk.incubator.code/share/classes/jdk/incubator/code/Value.java line 83:

> 81:     public Op.Result result() {
> 82:         if (this instanceof Op.Result r) return r;
> 83:         else throw new IllegalStateException("Value is not an instance of operation result");

Can you use braces to be consistent with code style. No need for the else block you can just directly have the throw statement at the end.

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

PR Review: https://git.openjdk.org/babylon/pull/816#pullrequestreview-3628430656
PR Review Comment: https://git.openjdk.org/babylon/pull/816#discussion_r2662810173


More information about the babylon-dev mailing list