RFR: 8304283: Modernize the switch statements in jdk.internal.foreign

Jorn Vernee jvernee at openjdk.org
Wed Mar 15 19:57:24 UTC 2023


On Wed, 15 Mar 2023 18:10:29 GMT, Per Minborg <pminborg at openjdk.org> wrote:

> This PR proposes changing old-type switch statements to newer forms of switch.

src/java.base/share/classes/jdk/internal/foreign/abi/CallingSequenceBuilder.java line 219:

> 217:             case Binding.Cast unused-> true;
> 218:         };
> 219:     }

I'd go a bit further here and visually organize the cases as well. Also, using a static import for `Binding.*`:

Suggestion:

    static boolean isUnbox(Binding binding) {
        return switch (binding) {
            case VMStore       unused -> true;
            case BufferLoad    unused -> true;
            case Copy          unused -> true;
            case UnboxAddress  unused -> true;
            case Dup           unused -> true;
            case Cast          unused -> true;
            
            case VMLoad       unused -> false;
            case BufferStore  unused -> false;
            case Allocate     unused -> false;
            case BoxAddress   unused -> false;
        };
    }


It's a bit unfortunate that we need variable names as well.

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

PR: https://git.openjdk.org/jdk/pull/13047


More information about the core-libs-dev mailing list