langtools/test/tools/javac/TestIndyStringConcat.java
author hseigel
Wed, 02 Mar 2016 23:48:41 +0000
changeset 36397 c487ced7231c
parent 36041 bfcede0994e5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35424
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     1
/*
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     4
 *
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     7
 * published by the Free Software Foundation.
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
     8
 *
96661d1df628 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
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
96661d1df628 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
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    13
 * accompanied this code).
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    14
 *
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    18
 *
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    21
 * questions.
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    22
 */
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    23
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    24
/*
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    25
 * @test
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    26
 * @summary Test that StringConcat is working for JDK >= 9
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    27
 * @compile -source 6 -target 6 TestIndyStringConcat.java
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    28
 * @run main TestIndyStringConcat false
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    29
 * @clean TestIndyStringConcat*
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    30
 * @compile -source 7 -target 7 TestIndyStringConcat.java
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    31
 * @run main TestIndyStringConcat false
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    32
 * @clean TestIndyStringConcat*
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    33
 * @compile -source 8 -target 8 TestIndyStringConcat.java
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    34
 * @run main TestIndyStringConcat false
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    35
 * @clean TestIndyStringConcat*
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    36
 * @compile -XDstringConcat=inline -source 9 -target 9 TestIndyStringConcat.java
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    37
 * @run main TestIndyStringConcat false
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    38
 * @clean TestIndyStringConcat*
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    39
 * @compile -XDstringConcat=indy -source 9 -target 9 TestIndyStringConcat.java
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    40
 * @run main TestIndyStringConcat true
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    41
 * @clean TestIndyStringConcat*
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    42
 * @compile -XDstringConcat=indyWithConstants -source 9 -target 9 TestIndyStringConcat.java
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    43
 * @run main TestIndyStringConcat true
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    44
 */
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    45
public class TestIndyStringConcat {
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    46
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    47
    private static class MyObject {
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    48
        public String toString() {
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    49
            throw new RuntimeException("Boyyaa");
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    50
        }
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    51
    }
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    52
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    53
    class Inner { }
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    54
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    55
    public static void main(String[] args) {
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    56
        boolean useIndyConcat = Boolean.valueOf(args[0]);
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    57
        try {
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    58
            String s = "Foo" + new MyObject();
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    59
        } catch (RuntimeException ex) {
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    60
            boolean indifiedStringConcat = false;
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    61
            ex.printStackTrace();
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    62
            for (StackTraceElement e : ex.getStackTrace()) {
36041
bfcede0994e5 8149835: StringConcatFactory should emit classes with the same package as the host class
shade
parents: 35424
diff changeset
    63
                if (e.getClassName().contains("$$StringConcat") &&
35424
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    64
                        e.getMethodName().equals("concat")) {
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    65
                    indifiedStringConcat = true;
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    66
                    break;
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    67
                }
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    68
            }
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    69
            if (indifiedStringConcat != useIndyConcat) {
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    70
                throw new AssertionError();
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    71
            }
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    72
        }
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    73
    }
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents:
diff changeset
    74
}