test/jdk/java/lang/String/concat/ImplicitStringConcat.java
author jlaskey
Fri, 18 May 2018 08:43:49 -0300
changeset 50175 589ed2770141
parent 49422 b64cd942ac7a
permissions -rw-r--r--
8200436: String::isBlank Reviewed-by: sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35388
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     1
/*
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     4
 *
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     8
 *
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    13
 * accompanied this code).
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    14
 *
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    18
 *
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    21
 * questions.
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    22
 */
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    23
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    24
/**
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    25
 * @test
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    26
 * @summary test implicit String concatenations
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    27
 *
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    28
 * @compile ImplicitStringConcat.java
35639
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    29
 * @run main/othervm -Xverify:all ImplicitStringConcat
35388
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    30
 *
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    31
 * @compile -XDstringConcat=inline ImplicitStringConcat.java
35639
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    32
 * @run main/othervm -Xverify:all ImplicitStringConcat
35388
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    33
 *
49422
b64cd942ac7a 8200241: [TESTBUG] java/lang/String/concat/ tests should not force source/target = 9 anymore
shade
parents: 47216
diff changeset
    34
 * @compile -XDstringConcat=indy ImplicitStringConcat.java
35388
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    35
 *
35639
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    36
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB                                                              ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    37
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED                                                        ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    38
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED                                                        ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    39
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT                                                  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    40
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT                                                  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    41
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT                                              ImplicitStringConcat
35388
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    42
 *
35639
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    43
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB                  -Djava.lang.invoke.stringConcat.debug=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    44
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED            -Djava.lang.invoke.stringConcat.debug=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    45
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED            -Djava.lang.invoke.stringConcat.debug=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    46
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT      -Djava.lang.invoke.stringConcat.debug=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    47
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT      -Djava.lang.invoke.stringConcat.debug=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    48
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT  -Djava.lang.invoke.stringConcat.debug=true  ImplicitStringConcat
35388
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    49
 *
35639
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    50
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB                                                              -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    51
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED                                                        -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    52
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED                                                        -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    53
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT                                                  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    54
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT                                                  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    55
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT                                              -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
35388
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    56
35639
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    57
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB                  -Djava.lang.invoke.stringConcat.debug=true  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    58
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED            -Djava.lang.invoke.stringConcat.debug=true  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    59
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED            -Djava.lang.invoke.stringConcat.debug=true  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    60
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT      -Djava.lang.invoke.stringConcat.debug=true  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    61
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT      -Djava.lang.invoke.stringConcat.debug=true  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    62
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT  -Djava.lang.invoke.stringConcat.debug=true  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
35388
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    63
 *
49422
b64cd942ac7a 8200241: [TESTBUG] java/lang/String/concat/ tests should not force source/target = 9 anymore
shade
parents: 47216
diff changeset
    64
 * @compile -XDstringConcat=indyWithConstants ImplicitStringConcat.java
35388
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    65
 *
35639
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    66
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB                                                              ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    67
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED                                                        ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    68
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED                                                        ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    69
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT                                                  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    70
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT                                                  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    71
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT                                              ImplicitStringConcat
35388
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    72
 *
35639
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    73
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB                  -Djava.lang.invoke.stringConcat.debug=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    74
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED            -Djava.lang.invoke.stringConcat.debug=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    75
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED            -Djava.lang.invoke.stringConcat.debug=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    76
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT      -Djava.lang.invoke.stringConcat.debug=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    77
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT      -Djava.lang.invoke.stringConcat.debug=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    78
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT  -Djava.lang.invoke.stringConcat.debug=true  ImplicitStringConcat
35388
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    79
 *
35639
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    80
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB                                                              -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    81
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED                                                        -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    82
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED                                                        -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    83
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT                                                  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    84
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT                                                  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    85
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT                                              -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
35388
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    86
 *
35639
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    87
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB                  -Djava.lang.invoke.stringConcat.debug=true  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    88
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED            -Djava.lang.invoke.stringConcat.debug=true  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    89
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED            -Djava.lang.invoke.stringConcat.debug=true  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    90
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT      -Djava.lang.invoke.stringConcat.debug=true  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    91
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT      -Djava.lang.invoke.stringConcat.debug=true  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
f34e7e8b4eac 8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested
shade
parents: 35388
diff changeset
    92
 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT  -Djava.lang.invoke.stringConcat.debug=true  -Djava.lang.invoke.stringConcat.cache=true  ImplicitStringConcat
35388
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    93
*/
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    94
import java.lang.StringBuilder;
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    95
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    96
public class ImplicitStringConcat {
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    97
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    98
    static boolean b = true;
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    99
    static byte by = 42;
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   100
    static short sh = 42;
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   101
    static char ch = 'a';
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   102
    static int i = 42;
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   103
    static float fl = 42.0f;
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   104
    static long l = 42;
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   105
    static double d = 42.0d;
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   106
    static String s = "foo";
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   107
    static String sNull = null;
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   108
    static Object o = "bar";
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   109
    static Object oNull = null;
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   110
    static CharSequence cs = "bar";
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   111
    static char[] chars = new char[] {'a'};
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   112
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   113
    static MyClass myCl = new MyClass();
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   114
    static MyClassNull myClNull = new MyClassNull();
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   115
    static Object  myCl2 = new MyClass();
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   116
    static Object[] myArr = new Object[] { myCl };
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   117
    static final Object[] s_myArr = new Object[] { myCl };
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   118
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   119
    static StringBuffer sb = new StringBuffer("a");
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   120
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   121
    public static void main(String[] args) throws Exception {
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   122
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   123
        test("footrue", s + b);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   124
        test("foo42",   s + by);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   125
        test("foo42",   s + sh);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   126
        test("fooa",    s + ch);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   127
        test("foo42",   s + i);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   128
        test("foo42",   s + l);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   129
        test("foo42.0", s + fl);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   130
        test("foo42.0", s + d);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   131
        test("foofoo",  s + s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   132
        test("foonull", s + sNull);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   133
        test("foobar",  s + o);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   134
        test("foonull", s + oNull);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   135
        test("foobar",  s + cs);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   136
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   137
        {
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   138
            StringBuilder sb = new StringBuilder();
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   139
            sb.append("foo");
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   140
            sb.append(myArr.toString());
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   141
            test(sb.toString(), s + myArr);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   142
        }
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   143
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   144
        {
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   145
            StringBuilder sb = new StringBuilder();
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   146
            sb.append("foo");
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   147
            sb.append(s_myArr.toString());
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   148
            test(sb.toString(), s + s_myArr);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   149
        }
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   150
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   151
        {
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   152
            StringBuilder sb = new StringBuilder();
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   153
            sb.append("foo[C@");
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   154
            sb.append(Integer.toHexString(System.identityHashCode(chars)));
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   155
            test(sb.toString(), s + chars);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   156
        }
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   157
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   158
        test("fooa",    s + ImplicitStringConcat.sb);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   159
        test("foonull", s + null);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   160
        test("fooMyClass", s + myCl);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   161
        test("foonull",    s + myClNull);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   162
        test("fooMyClass", s + myCl2);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   163
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   164
        s = "foo";  s += b;     test("footrue", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   165
        s = "foo";  s += by;    test("foo42", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   166
        s = "foo";  s += sh;    test("foo42", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   167
        s = "foo";  s += ch;    test("fooa", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   168
        s = "foo";  s += i;     test("foo42", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   169
        s = "foo";  s += l;     test("foo42", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   170
        s = "foo";  s += fl;    test("foo42.0", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   171
        s = "foo";  s += d;     test("foo42.0", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   172
        s = "foo";  s += s;     test("foofoo", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   173
        s = "foo";  s += sNull; test("foonull", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   174
        s = "foo";  s += o;     test("foobar", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   175
        s = "foo";  s += oNull; test("foonull", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   176
        s = "foo";  s += cs;    test("foobar", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   177
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   178
        {
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   179
            StringBuilder sb = new StringBuilder();
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   180
            sb.append("foo[C@");
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   181
            sb.append(Integer.toHexString(System.identityHashCode(chars)));
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   182
            s = "foo";
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   183
            s += chars;
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   184
            test(sb.toString(), s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   185
        }
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   186
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   187
        s = "foo";  s += ImplicitStringConcat.sb;    test("fooa", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   188
        s = "foo";  s += null;  test("foonull", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   189
        s = "foo";  s += myCl;  test("fooMyClass", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   190
        s = "foo";  s += myCl2; test("fooMyClass", s);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   191
    }
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   192
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   193
    public static void test(String expected, String actual) {
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   194
       // Fingers crossed: String concat should work.
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   195
       if (!expected.equals(actual)) {
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   196
           StringBuilder sb = new StringBuilder();
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   197
           sb.append("Expected = ");
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   198
           sb.append(expected);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   199
           sb.append(", actual = ");
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   200
           sb.append(actual);
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   201
           throw new IllegalStateException(sb.toString());
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   202
       }
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   203
    }
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   204
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   205
    static class MyClass {
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   206
        public String toString() {
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   207
            return "MyClass";
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   208
        }
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   209
    }
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   210
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   211
    static class MyClassNull {
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   212
        public String toString() {
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   213
            return null;
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   214
        }
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   215
    }
a33a232cf7b7 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
   216
}