aoqi@0: /* aoqi@0: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 8031967 aoqi@0: * @summary Ensure javac can handle very deeply nested chain of method invocations occurring as aoqi@0: * a parameter to other method invocations. aoqi@0: * @run main T8031967 aoqi@0: */ aoqi@0: aoqi@0: import java.io.IOException; aoqi@0: import java.net.URI; aoqi@0: import java.util.Arrays; aoqi@0: import java.util.List; aoqi@0: aoqi@0: import javax.tools.DiagnosticListener; aoqi@0: import javax.tools.JavaCompiler; aoqi@0: import javax.tools.JavaFileObject; aoqi@0: import javax.tools.SimpleJavaFileObject; aoqi@0: import javax.tools.ToolProvider; aoqi@0: aoqi@0: import com.sun.source.util.JavacTask; aoqi@0: aoqi@0: public class T8031967 { aoqi@0: aoqi@0: public static void main(String... args) throws IOException { aoqi@0: new T8031967().run(); aoqi@0: } aoqi@0: aoqi@0: final int depth = 50; aoqi@0: aoqi@0: private void run() throws IOException { aoqi@0: runTestCase(true); aoqi@0: runTestCase(false); aoqi@0: } aoqi@0: aoqi@0: private void runTestCase(boolean withErrors) throws IOException { aoqi@0: StringBuilder code = new StringBuilder(); aoqi@0: aoqi@0: code.append("public class Test {\n" + aoqi@0: " private void test() {\n" + aoqi@0: " GroupLayout l = new GroupLayout();\n" + aoqi@0: " l.setHorizontalGroup(\n"); aoqi@0: aoqi@0: gen(code, depth); aoqi@0: code.append(" );\n" + aoqi@0: " }\n"); aoqi@0: if (!withErrors) { aoqi@0: code.append(" class GroupLayout {\n" + aoqi@0: " ParallelGroup createParallelGroup() {return null;}\n" + aoqi@0: " ParallelGroup createParallelGroup(int i) {return null;}\n" + aoqi@0: " ParallelGroup createParallelGroup(int i, int j) {return null;}\n" + aoqi@0: " void setHorizontalGroup(Group g) { }\n" + aoqi@0: " }\n" + aoqi@0: " \n" + aoqi@0: " class Group {\n" + aoqi@0: " Group addGroup(Group g) { return this; }\n" + aoqi@0: " Group addGroup(int i, Group g) { return this; }\n" + aoqi@0: " Group addGap(int i) { return this; }\n" + aoqi@0: " Group addGap(long l) { return this; }\n" + aoqi@0: " Group addGap(int i, int j) { return this; }\n" + aoqi@0: " Group addComponent(Object c) { return this; }\n" + aoqi@0: " Group addComponent(int i, Object c) { return this; }\n" + aoqi@0: " }\n" + aoqi@0: " class ParallelGroup extends Group {\n" + aoqi@0: " Group addGroup(Group g) { return this; }\n" + aoqi@0: " Group addGroup(int i, Group g) { return this; }\n" + aoqi@0: " Group addGap(int i) { return this; }\n" + aoqi@0: " Group addGap(int i, int j) { return this; }\n" + aoqi@0: " Group addComponent(Object c) { return this; }\n" + aoqi@0: " Group addComponent(int i, Object c) { return this; }\n" + aoqi@0: " }\n"); aoqi@0: } aoqi@0: aoqi@0: code.append("}\n"); aoqi@0: aoqi@0: JavaSource source = new JavaSource(code.toString()); aoqi@0: List sourceList = Arrays.asList(source); aoqi@0: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); aoqi@0: DiagnosticListener noErrors = (diagnostic) -> { aoqi@0: throw new IllegalStateException("Should not produce errors: " + diagnostic); aoqi@0: }; aoqi@0: JavacTask task = (JavacTask) compiler.getTask(null, null, withErrors ? null : noErrors, aoqi@0: null, null, sourceList); aoqi@0: aoqi@0: task.analyze(); aoqi@0: } aoqi@0: aoqi@0: private void gen(StringBuilder code, int depth) { aoqi@0: code.append("l.createParallelGroup()\n"); aoqi@0: if (depth > 0) { aoqi@0: code.append(".addGroup(\n"); aoqi@0: gen(code, depth - 1); aoqi@0: code.append(")"); aoqi@0: } aoqi@0: aoqi@0: code.append(".addGap(1)\n" + aoqi@0: ".addComponent(new Object())\n" + aoqi@0: ".addGap(1)\n" + aoqi@0: ".addComponent(new Object())"); aoqi@0: } aoqi@0: aoqi@0: class JavaSource extends SimpleJavaFileObject { aoqi@0: aoqi@0: final String code; aoqi@0: public JavaSource(String code) { aoqi@0: super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); aoqi@0: this.code = code; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public CharSequence getCharContent(boolean ignoreEncodingErrors) { aoqi@0: return code; aoqi@0: } aoqi@0: } aoqi@0: }