test/tools/javac/7142086/T7142086.java

Wed, 13 Aug 2014 14:50:00 -0700

author
katleman
date
Wed, 13 Aug 2014 14:50:00 -0700
changeset 2549
0b6cc4ea670f
parent 0
959103a6100f
permissions
-rw-r--r--

Added tag jdk8u40-b01 for changeset bf89a471779d

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 */
aoqi@0 23
aoqi@0 24 /*
aoqi@0 25 * @test
aoqi@0 26 * @bug 7142086
aoqi@0 27 * @summary performance problem in Check.checkOverrideClashes(...)
aoqi@0 28 * @run main/timeout=10 T7142086
aoqi@0 29 */
aoqi@0 30
aoqi@0 31 import com.sun.source.util.JavacTask;
aoqi@0 32 import java.net.URI;
aoqi@0 33 import java.util.List;
aoqi@0 34 import java.util.ArrayList;
aoqi@0 35 import java.util.Locale;
aoqi@0 36 import javax.tools.Diagnostic;
aoqi@0 37 import javax.tools.JavaCompiler;
aoqi@0 38 import javax.tools.JavaFileObject;
aoqi@0 39 import javax.tools.SimpleJavaFileObject;
aoqi@0 40 import javax.tools.StandardJavaFileManager;
aoqi@0 41 import javax.tools.ToolProvider;
aoqi@0 42
aoqi@0 43 public class T7142086 {
aoqi@0 44
aoqi@0 45 final static int N_METHODS = 1000;
aoqi@0 46
aoqi@0 47 static class TestClass extends SimpleJavaFileObject {
aoqi@0 48
aoqi@0 49 String methTemplate = "abstract void m(A#N p);";
aoqi@0 50 String classTemplate = "abstract class Test { #M }";
aoqi@0 51
aoqi@0 52 String source;
aoqi@0 53
aoqi@0 54 public TestClass() {
aoqi@0 55 super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
aoqi@0 56 StringBuilder buf = new StringBuilder();
aoqi@0 57 for (int i = 0 ; i < N_METHODS ; i++) {
aoqi@0 58 buf.append(methTemplate.replace("#N", String.valueOf(i)));
aoqi@0 59 buf.append("\n");
aoqi@0 60 }
aoqi@0 61 source = classTemplate.replace("#M", buf.toString());
aoqi@0 62 }
aoqi@0 63
aoqi@0 64 @Override
aoqi@0 65 public CharSequence getCharContent(boolean ignoreEncodingErrors) {
aoqi@0 66 return source;
aoqi@0 67 }
aoqi@0 68 }
aoqi@0 69
aoqi@0 70 static class AnSource extends SimpleJavaFileObject {
aoqi@0 71
aoqi@0 72 String classTemplate = "abstract class A#N { }";
aoqi@0 73
aoqi@0 74 String source;
aoqi@0 75
aoqi@0 76 public AnSource(int n) {
aoqi@0 77 super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
aoqi@0 78 source = classTemplate.replace("#N", String.valueOf(n));
aoqi@0 79 }
aoqi@0 80
aoqi@0 81 @Override
aoqi@0 82 public CharSequence getCharContent(boolean ignoreEncodingErrors) {
aoqi@0 83 return source;
aoqi@0 84 }
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 public static void main(String... args) throws Exception {
aoqi@0 88 ArrayList<JavaFileObject> sources = new ArrayList<>();
aoqi@0 89 for (int i = 0 ; i < N_METHODS ; i++) {
aoqi@0 90 sources.add(new AnSource(i));
aoqi@0 91 }
aoqi@0 92 sources.add(new TestClass());
aoqi@0 93 new T7142086().run(sources);
aoqi@0 94 }
aoqi@0 95
aoqi@0 96 void run(List<JavaFileObject> sources) throws Exception {
aoqi@0 97 DiagnosticChecker dc = new DiagnosticChecker();
aoqi@0 98 JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
aoqi@0 99 StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
aoqi@0 100 JavacTask ct = (JavacTask)comp.getTask(null, fm, dc,
aoqi@0 101 null, null, sources);
aoqi@0 102 ct.analyze();
aoqi@0 103 }
aoqi@0 104
aoqi@0 105 static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
aoqi@0 106
aoqi@0 107 boolean errorFound;
aoqi@0 108
aoqi@0 109 public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
aoqi@0 110 if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
aoqi@0 111 throw new AssertionError("unexpected diagnostic: " + diagnostic.getMessage(Locale.getDefault()));
aoqi@0 112 }
aoqi@0 113 }
aoqi@0 114 }
aoqi@0 115 }

mercurial