author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 27319 | 030080f03e4f |
permissions | -rw-r--r-- |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
4 |
* |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
8 |
* |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
13 |
* accompanied this code). |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
14 |
* |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
18 |
* |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
21 |
* questions. |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
22 |
*/ |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
23 |
|
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
24 |
/**@test |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
25 |
* @bug 8035890 |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
26 |
* @summary Verify that the parser correctly checks for source level 8 on the new places where |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
27 |
* annotations can appear in 8. |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
29 |
* jdk.compiler/com.sun.tools.javac.file |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
30 |
* @run main CheckErrorsForSource7 CheckErrorsForSource7.java |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
31 |
*/ |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
32 |
import java.io.File; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
33 |
import java.io.IOException; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
34 |
import java.lang.annotation.ElementType; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
35 |
import java.lang.annotation.Target; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
36 |
import java.net.URI; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
37 |
import java.net.URISyntaxException; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
38 |
import java.util.ArrayList; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
39 |
import java.util.Arrays; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
40 |
import java.util.Collections; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
41 |
import java.util.Comparator; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
42 |
import java.util.HashSet; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
43 |
import java.util.List; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
44 |
import java.util.Set; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
45 |
import javax.tools.Diagnostic; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
46 |
import javax.tools.DiagnosticCollector; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
47 |
import javax.tools.JavaFileObject; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
48 |
import javax.tools.SimpleJavaFileObject; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
49 |
import com.sun.source.tree.AnnotationTree; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
50 |
import com.sun.source.tree.CompilationUnitTree; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
51 |
import com.sun.source.tree.IdentifierTree; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
52 |
import com.sun.source.tree.Tree.Kind; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
53 |
import com.sun.source.util.JavacTask; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
54 |
import com.sun.source.util.TreePathScanner; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
55 |
import com.sun.source.util.Trees; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
56 |
import com.sun.tools.javac.api.JavacTool; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
57 |
import com.sun.tools.javac.file.JavacFileManager; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
58 |
|
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
59 |
/**For each place where an annotation can syntactically appear with -source 8, but not with |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
60 |
* -source 7, this test verifies that an error is correctly emitted from the parser for |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
61 |
* the annotation for -source 7. This test first gathers the occurrences of @TA from |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
62 |
* the CheckErrorsForSource7Data class below, and then repeatedly removes all these annotations |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
63 |
* except one and checks the parser reports an expected error. This is needed as as the parser |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
64 |
* typically produces only one 'insufficient source level' error for each new feature used. |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
65 |
*/ |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
66 |
public class CheckErrorsForSource7 { |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
67 |
public static void main(String... args) throws IOException, URISyntaxException { |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
68 |
new CheckErrorsForSource7().run(args); |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
69 |
} |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
70 |
|
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
71 |
private void run(String... args) throws IOException, URISyntaxException { |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
72 |
//the first and only parameter must be the name of the file to be analyzed: |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
73 |
if (args.length != 1) throw new IllegalStateException("Must provide source file!"); |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
74 |
File testSrc = new File(System.getProperty("test.src")); |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
75 |
File testFile = new File(testSrc, args[0]); |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
76 |
if (!testFile.canRead()) throw new IllegalStateException("Cannot read the test source"); |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
77 |
try (JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null)) { |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
78 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
79 |
//gather spans of the @TA annotations into typeAnnotationSpans: |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
80 |
JavacTask task = JavacTool.create().getTask(null, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
81 |
fm, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
82 |
null, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
83 |
Collections.<String>emptyList(), |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
84 |
null, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
85 |
fm.getJavaFileObjects(testFile)); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
86 |
final Trees trees = Trees.instance(task); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
87 |
final CompilationUnitTree cut = task.parse().iterator().next(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
88 |
final List<int[]> typeAnnotationSpans = new ArrayList<>(); |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
89 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
90 |
new TreePathScanner<Void, Void>() { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
91 |
@Override |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
92 |
public Void visitAnnotation(AnnotationTree node, Void p) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
93 |
if (node.getAnnotationType().getKind() == Kind.IDENTIFIER && |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
94 |
((IdentifierTree) node.getAnnotationType()).getName().contentEquals("TA")) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
95 |
int start = (int) trees.getSourcePositions().getStartPosition(cut, node); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
96 |
int end = (int) trees.getSourcePositions().getEndPosition(cut, node); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
97 |
typeAnnotationSpans.add(new int[] {start, end}); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
98 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
99 |
return null; |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
100 |
} |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
101 |
}.scan(cut, null); |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
102 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
103 |
//sort the spans in the reverse order, to simplify removing them from the source: |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
104 |
Collections.sort(typeAnnotationSpans, new Comparator<int[]>() { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
105 |
@Override |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
106 |
public int compare(int[] o1, int[] o2) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
107 |
return o2[0] - o1[0]; |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
108 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
109 |
}); |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
110 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
111 |
//verify the errors are produce correctly: |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
112 |
String originalSource = cut.getSourceFile().getCharContent(false).toString(); |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
113 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
114 |
for (int[] toKeep : typeAnnotationSpans) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
115 |
//prepare updated source code by removing all the annotations except the toKeep one: |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
116 |
String updated = originalSource; |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
117 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
118 |
for (int[] span : typeAnnotationSpans) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
119 |
if (span == toKeep) continue; |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
120 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
121 |
updated = updated.substring(0, span[0]) + updated.substring(span[1]); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
122 |
} |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
123 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
124 |
//parse and verify: |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
125 |
JavaFileObject updatedFile = new TestFO(cut.getSourceFile().toUri(), updated); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
126 |
DiagnosticCollector<JavaFileObject> errors = new DiagnosticCollector<>(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
127 |
JavacTask task2 = JavacTool.create().getTask(null, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
128 |
fm, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
129 |
errors, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
130 |
Arrays.asList("-source", "7"), |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
131 |
null, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
132 |
Arrays.asList(updatedFile)); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
133 |
task2.parse(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
134 |
|
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
135 |
boolean found = false; |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
136 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
137 |
for (Diagnostic<? extends JavaFileObject> d : errors.getDiagnostics()) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
138 |
if (d.getKind() == Diagnostic.Kind.ERROR && EXPECTED_ERRORS.contains(d.getCode())) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
139 |
if (found) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
140 |
throw new IllegalStateException("More than one expected error found."); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
141 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
142 |
found = true; |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
143 |
} |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
144 |
} |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
145 |
|
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
146 |
if (!found) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
23800
diff
changeset
|
147 |
throw new IllegalStateException("Did not produce proper errors for: " + updated); |
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
148 |
} |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
149 |
} |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
150 |
} |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
151 |
|
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
152 |
static final Set<String> EXPECTED_ERRORS = new HashSet<>(Arrays.asList( |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
153 |
"compiler.err.type.annotations.not.supported.in.source", |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
154 |
"compiler.err.annotations.after.type.params.not.supported.in.source" |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
155 |
)); |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
156 |
|
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
157 |
class TestFO extends SimpleJavaFileObject { |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
158 |
private final String content; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
159 |
public TestFO(URI uri, String content) { |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
160 |
super(uri, Kind.SOURCE); |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
161 |
this.content = content; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
162 |
} |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
163 |
|
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
164 |
@Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
165 |
return content; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
166 |
} |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
167 |
|
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
168 |
@Override public boolean isNameCompatible(String simpleName, Kind kind) { |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
169 |
return true; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
170 |
} |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
171 |
} |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
172 |
} |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
173 |
|
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
174 |
//data on which the source level check is verified: |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
175 |
class CheckErrorsForSource7Data { |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
176 |
@Target(ElementType.TYPE_USE) |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
177 |
@interface TA { } |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
178 |
|
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
179 |
Object n1 = new @TA ArrayList<@TA String>(); |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
180 |
Object n2 = new @TA Object() {}; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
181 |
Object [] @TA [] arr @TA[]; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
182 |
<T> @TA int @TA[] ret(Object obj) @TA[] throws @TA Exception { |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
183 |
this.<@TA String>ret(null); |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
184 |
Object c1 = new @TA String[1]; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
185 |
|
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
186 |
int val = obj instanceof @TA String ? ((@TA String) obj).length() : 0; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
187 |
List<@TA ?> l; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
188 |
return null; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
189 |
} |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
190 |
void vararg(String @TA ... args) { } |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
191 |
|
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
192 |
abstract class C<@TA T extends @TA Number & @TA Runnable> |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
193 |
extends @TA ArrayList<@TA String> |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
194 |
implements java.util. @TA Comparator<@TA T> { } |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
195 |
|
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
196 |
interface I extends java.util. @TA Comparator<@TA String> { } |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
197 |
|
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
diff
changeset
|
198 |
} |