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