author | aph |
Mon, 04 Nov 2019 13:13:34 -0500 | |
changeset 58917 | 33f9271b3167 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
14720
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
1 |
|
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
2 |
/* |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
3 |
* @test /nodynamiccopyright/ |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
4 |
* @bug 7144981 |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
5 |
* @summary javac should ignore ignorable characters in input |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
14720
diff
changeset
|
6 |
* @modules jdk.compiler |
14720
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
7 |
* @run main IgnoreIgnorableCharactersInInput |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
8 |
*/ |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
9 |
|
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
10 |
import com.sun.source.util.JavacTask; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
11 |
import java.io.File; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
12 |
import java.net.URI; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
13 |
import java.util.Arrays; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
14 |
import java.util.Set; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
15 |
import java.util.TreeSet; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
16 |
import javax.tools.JavaCompiler; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
17 |
import javax.tools.JavaFileObject; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
18 |
import javax.tools.SimpleJavaFileObject; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
19 |
import javax.tools.ToolProvider; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
20 |
|
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
21 |
public class IgnoreIgnorableCharactersInInput { |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
22 |
|
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
23 |
public static void main(String... args) throws Exception { |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
24 |
new IgnoreIgnorableCharactersInInput().run(); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
25 |
} |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
26 |
|
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
27 |
void run() throws Exception { |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
28 |
JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
29 |
File classesDir = new File(System.getProperty("user.dir"), "classes"); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
30 |
classesDir.mkdirs(); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
31 |
JavaSource[] sources = new JavaSource[]{ |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
32 |
new JavaSource("TestOneIgnorableChar", "AA\\u0000BB"), |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
33 |
new JavaSource("TestMultipleIgnorableChar", "AA\\u0000\\u0000\\u0000BB")}; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
34 |
JavacTask ct = (JavacTask)comp.getTask(null, null, null, |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
35 |
Arrays.asList("-d", classesDir.getPath()), |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
36 |
null, Arrays.asList(sources)); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
37 |
try { |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
38 |
if (!ct.call()) { |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
39 |
throw new AssertionError("Error thrown when compiling test cases"); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
40 |
} |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
41 |
} catch (Throwable ex) { |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
42 |
throw new AssertionError("Error thrown when compiling test cases"); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
43 |
} |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
44 |
check(classesDir, |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
45 |
"TestOneIgnorableChar.class", |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
46 |
"TestOneIgnorableChar$AABB.class", |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
47 |
"TestMultipleIgnorableChar.class", |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
48 |
"TestMultipleIgnorableChar$AABB.class"); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
49 |
if (errors > 0) |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
50 |
throw new AssertionError("There are some errors in the test check the error output"); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
51 |
} |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
52 |
|
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
53 |
/** |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
54 |
* Check that a directory contains the expected files. |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
55 |
*/ |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
56 |
void check(File dir, String... paths) { |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
57 |
Set<String> found = new TreeSet<String>(Arrays.asList(dir.list())); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
58 |
Set<String> expect = new TreeSet<String>(Arrays.asList(paths)); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
59 |
if (found.equals(expect)) |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
60 |
return; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
61 |
for (String f: found) { |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
62 |
if (!expect.contains(f)) |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
63 |
error("Unexpected file found: " + f); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
64 |
} |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
65 |
for (String e: expect) { |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
66 |
if (!found.contains(e)) |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
67 |
error("Expected file not found: " + e); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
68 |
} |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
69 |
} |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
70 |
|
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
71 |
int errors; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
72 |
|
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
73 |
void error(String msg) { |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
74 |
System.err.println(msg); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
75 |
errors++; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
76 |
} |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
77 |
|
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
78 |
class JavaSource extends SimpleJavaFileObject { |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
79 |
|
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
80 |
String internalSource = |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
81 |
"public class #O {public class #I {} }"; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
82 |
public JavaSource(String outerClassName, String innerClassName) { |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
83 |
super(URI.create(outerClassName + ".java"), JavaFileObject.Kind.SOURCE); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
84 |
internalSource = |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
85 |
internalSource.replace("#O", outerClassName).replace("#I", innerClassName); |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
86 |
} |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
87 |
|
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
88 |
@Override |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
89 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
90 |
return internalSource; |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
91 |
} |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
92 |
} |
c24c61d0d9a6
7144981: javac should ignore ignorable characters in input
vromero
parents:
diff
changeset
|
93 |
} |