On Tue, 25 May 2021 09:37:58 GMT, Patrick Concannon <pconcan...@openjdk.org> 
wrote:

> Hi,
> 
> Could someone please review my code for updating the code in the `java.io`, 
> `java.math`, and `java.text` packages to make use of the switch expressions?
> 
> Kind regards,
> Patrick

src/java.base/share/classes/java/io/StreamTokenizer.java line 795:

> 793:                  * case statements
> 794:                  */
> 795:                 if (ttype < 256 && ((ctype[ttype] & CT_QUOTE) != 0)) {

Maybe (since its easier to grok the yield rather than the assignment of ret in 
branches):

    String ret = switch (ttype) {
            case TT_EOF     -> "EOF";
            case TT_EOL     -> "EOL";
            case TT_WORD    -> sval;
            case TT_NUMBER  -> "n=" + nval;
            case TT_NOTHING -> "NOTHING";
            default         -> {
                /*
                 * ttype is the first character of either a quoted string or
                 * is an ordinary character. ttype can definitely not be less
                 * than 0, since those are reserved values used in the previous
                 * case statements
                 */
                if (ttype < 256 && ((ctype[ttype] & CT_QUOTE) != 0)) {
                    yield sval;
                }
                char s[] = new char[3];
                s[0] = s[2] = ''';
                s[1] = (char) ttype;
                yield new String(s);
            }
        };
        return "Token[" + ret + "], line " + LINENO;

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

PR: https://git.openjdk.java.net/jdk/pull/4182

Reply via email to