langtools/test/tools/javac/lambda/T8031967.java
author jlahoda
Fri, 30 May 2014 12:54:16 +0200
changeset 24649 1760d92bc6d2
child 30730 d3ce7619db2c
permissions -rw-r--r--
8031967: For some sources compiler compiles for ever Summary: Avoid creating DeferredTypes for method calls with method calls as receivers if the site can be determined reliably Reviewed-by: mcimadamore, vromero Contributed-by: maurizio.cimadamore@oracle.com, jan.lahoda@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
     1
/*
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
     4
 *
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
     8
 *
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    14
 *
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    18
 *
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    21
 * questions.
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    22
 */
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    23
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    24
/*
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    25
 * @test
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    26
 * @bug 8031967
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    27
 * @summary Ensure javac can handle very deeply nested chain of method invocations occurring as
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    28
 *          a parameter to other method invocations.
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    29
 * @run main T8031967
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    30
 */
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    31
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    32
import java.io.IOException;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    33
import java.net.URI;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    34
import java.util.Arrays;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    35
import java.util.List;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    36
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    37
import javax.tools.DiagnosticListener;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    38
import javax.tools.JavaCompiler;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    39
import javax.tools.JavaFileObject;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    40
import javax.tools.SimpleJavaFileObject;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    41
import javax.tools.ToolProvider;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    42
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    43
import com.sun.source.util.JavacTask;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    44
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    45
public class T8031967 {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    46
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    47
    public static void main(String... args) throws IOException {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    48
        new T8031967().run();
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    49
    }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    50
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    51
    final int depth = 50;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    52
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    53
    private void run() throws IOException {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    54
        runTestCase(true);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    55
        runTestCase(false);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    56
    }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    57
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    58
    private void runTestCase(boolean withErrors) throws IOException {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    59
        StringBuilder code = new StringBuilder();
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    60
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    61
        code.append("public class Test {\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    62
                    "    private void test() {\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    63
                    "        GroupLayout l = new GroupLayout();\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    64
                    "        l.setHorizontalGroup(\n");
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    65
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    66
        gen(code, depth);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    67
        code.append("        );\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    68
                    "    }\n");
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    69
        if (!withErrors) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    70
            code.append("    class GroupLayout {\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    71
                        "        ParallelGroup createParallelGroup() {return null;}\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    72
                        "        ParallelGroup createParallelGroup(int i) {return null;}\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    73
                        "        ParallelGroup createParallelGroup(int i, int j) {return null;}\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    74
                        "        void setHorizontalGroup(Group g) { }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    75
                        "    }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    76
                        "    \n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    77
                        "    class Group {\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    78
                        "        Group addGroup(Group g) { return this; }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    79
                        "        Group addGroup(int i, Group g) { return this; }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    80
                        "        Group addGap(int i) { return this; }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    81
                        "        Group addGap(long l) { return this; }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    82
                        "        Group addGap(int i, int j) { return this; }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    83
                        "        Group addComponent(Object c) { return this; }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    84
                        "        Group addComponent(int i, Object c) { return this; }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    85
                        "    }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    86
                        "    class ParallelGroup extends Group {\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    87
                        "        Group addGroup(Group g) { return this; }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    88
                        "        Group addGroup(int i, Group g) { return this; }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    89
                        "        Group addGap(int i) { return this; }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    90
                        "        Group addGap(int i, int j) { return this; }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    91
                        "        Group addComponent(Object c) { return this; }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    92
                        "        Group addComponent(int i, Object c) { return this; }\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    93
                        "    }\n");
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    94
        }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    95
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    96
        code.append("}\n");
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    97
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    98
        JavaSource source = new JavaSource(code.toString());
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
    99
        List<JavaSource> sourceList = Arrays.asList(source);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   100
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   101
        DiagnosticListener<JavaFileObject> noErrors = (diagnostic) -> {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   102
            throw new IllegalStateException("Should not produce errors: " + diagnostic);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   103
        };
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   104
        JavacTask task = (JavacTask) compiler.getTask(null, null, withErrors ? null : noErrors,
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   105
                null, null, sourceList);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   106
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   107
        task.analyze();
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   108
    }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   109
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   110
    private void gen(StringBuilder code, int depth) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   111
        code.append("l.createParallelGroup()\n");
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   112
        if (depth > 0) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   113
            code.append(".addGroup(\n");
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   114
            gen(code, depth - 1);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   115
            code.append(")");
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   116
        }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   117
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   118
        code.append(".addGap(1)\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   119
                    ".addComponent(new Object())\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   120
                    ".addGap(1)\n" +
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   121
                    ".addComponent(new Object())");
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   122
    }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   123
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   124
    class JavaSource extends SimpleJavaFileObject {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   125
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   126
        final String code;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   127
        public JavaSource(String code) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   128
            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   129
            this.code = code;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   130
        }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   131
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   132
        @Override
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   133
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   134
            return code;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   135
        }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   136
    }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents:
diff changeset
   137
}