|
23 | 23 |
|
24 | 24 | /*
|
25 | 25 | * @test
|
26 |
| - * @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584 8246774 8256411 8256149 8259050 8266436 8267221 8271928 8275097 8293897 8295401 8304671 |
| 26 | + * @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584 8246774 8256411 8256149 8259050 8266436 8267221 8271928 8275097 8293897 8295401 8304671 8310326 |
27 | 27 | * @summary tests error and diagnostics positions
|
28 | 28 | * @author Jan Lahoda
|
29 | 29 | * @modules jdk.compiler/com.sun.tools.javac.api
|
@@ -2395,6 +2395,31 @@ public Void visitCase(CaseTree node, Void p) {
|
2395 | 2395 | codes);
|
2396 | 2396 | }
|
2397 | 2397 |
|
| 2398 | + @Test //JDK-8310326 |
| 2399 | + void testUnnamedClassPositions() throws IOException { |
| 2400 | + String code = """ |
| 2401 | + void main() { |
| 2402 | + } |
| 2403 | + """; |
| 2404 | + DiagnosticCollector<JavaFileObject> coll = |
| 2405 | + new DiagnosticCollector<>(); |
| 2406 | + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, coll, List.of("--enable-preview", "--source", System.getProperty("java.specification.version")), |
| 2407 | + null, Arrays.asList(new MyFileObject(code))); |
| 2408 | + Trees trees = Trees.instance(ct); |
| 2409 | + SourcePositions sp = trees.getSourcePositions(); |
| 2410 | + CompilationUnitTree cut = ct.parse().iterator().next(); |
| 2411 | + new TreeScanner<Void, Void>() { |
| 2412 | + @Override |
| 2413 | + public Void visitClass(ClassTree node, Void p) { |
| 2414 | + assertEquals("Wrong start position", 0, sp.getStartPosition(cut, node)); |
| 2415 | + assertEquals("Wrong end position", -1, sp.getEndPosition(cut, node)); |
| 2416 | + assertEquals("Wrong modifiers start position", -1, sp.getStartPosition(cut, node.getModifiers())); |
| 2417 | + assertEquals("Wrong modifiers end position", -1, sp.getEndPosition(cut, node.getModifiers())); |
| 2418 | + return super.visitClass(node, p); |
| 2419 | + } |
| 2420 | + }.scan(cut, null); |
| 2421 | + } |
| 2422 | + |
2398 | 2423 | void run(String[] args) throws Exception {
|
2399 | 2424 | int passed = 0, failed = 0;
|
2400 | 2425 | final Pattern p = (args != null && args.length > 0)
|
|
0 commit comments