|
27 | 27 | import java.util.EnumSet; |
28 | 28 | import java.util.HashMap; |
29 | 29 | import java.util.HashSet; |
| 30 | +import java.util.List; |
30 | 31 | import java.util.Map; |
31 | 32 | import java.util.Set; |
32 | 33 | import java.util.concurrent.atomic.AtomicBoolean; |
|
53 | 54 | import org.netbeans.modules.classfile.ClassFile; |
54 | 55 | import org.netbeans.modules.java.source.indexing.CompileWorker.ParsingOutput; |
55 | 56 | import org.netbeans.modules.java.source.indexing.JavaCustomIndexer.CompileTuple; |
| 57 | +import org.netbeans.modules.parsing.impl.indexing.errors.TaskCache; |
56 | 58 | import org.netbeans.modules.parsing.spi.indexing.Context; |
| 59 | +import org.netbeans.modules.parsing.spi.indexing.ErrorsCache; |
| 60 | +import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.ErrorKind; |
| 61 | +import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.Range; |
57 | 62 | import org.netbeans.spi.java.classpath.support.ClassPathSupport; |
58 | 63 | import org.openide.filesystems.FileObject; |
59 | 64 | import org.openide.filesystems.FileUtil; |
60 | 65 | import org.openide.filesystems.URLMapper; |
| 66 | +import org.openide.util.Pair; |
61 | 67 |
|
62 | 68 | /** |
63 | 69 | * |
@@ -2431,6 +2437,54 @@ public void testRecord2() throws Exception { |
2431 | 2437 | assertEquals(expected, file2Fixed); |
2432 | 2438 | } |
2433 | 2439 |
|
| 2440 | + public void testBrokenWarningEndPos() throws Exception { //NETBEANS-7981 |
| 2441 | + setCompilerOptions(Arrays.asList("-Xlint:deprecation")); |
| 2442 | + |
| 2443 | + String code = """ |
| 2444 | + package test; |
| 2445 | + public class Test { |
| 2446 | + void t() { |
| 2447 | + new D() {}; |
| 2448 | + } |
| 2449 | + } |
| 2450 | + class D { |
| 2451 | + @Deprecated |
| 2452 | + D() {} |
| 2453 | + } |
| 2454 | + """; |
| 2455 | + ParsingOutput result = runIndexing(Arrays.asList(compileTuple("test/Test.java", |
| 2456 | + code)), |
| 2457 | + Arrays.asList()); |
| 2458 | + |
| 2459 | + assertFalse(result.lowMemory); |
| 2460 | + assertTrue(result.success); |
| 2461 | + |
| 2462 | + Set<String> createdFiles = new HashSet<String>(); |
| 2463 | + |
| 2464 | + for (File created : result.createdFiles) { |
| 2465 | + createdFiles.add(getWorkDir().toURI().relativize(created.toURI()).getPath()); |
| 2466 | + } |
| 2467 | + |
| 2468 | + assertEquals(new HashSet<String>(Arrays.asList("cache/s1/java/15/classes/test/Test.sig", |
| 2469 | + "cache/s1/java/15/classes/test/Test$1.sig", |
| 2470 | + "cache/s1/java/15/classes/test/D.sig")), |
| 2471 | + createdFiles); |
| 2472 | + record Data(ErrorKind kind, Pair<Pair<Integer, Integer>, Pair<Integer, Integer>> range) {} |
| 2473 | + List<Data> errors = TaskCache.getDefault().getErrors(getRoot().getFileObject("test/Test.java"), new ErrorsCache.ReverseConvertor<Data>() { |
| 2474 | + @Override |
| 2475 | + public Data get(ErrorKind kind, Range range, String message) { |
| 2476 | + return new Data(kind, Pair.of(Pair.of(range.getStart().getLine(), |
| 2477 | + range.getStart().getColumn()), |
| 2478 | + range.getEnd() != null ? Pair.of(range.getEnd().getLine(), |
| 2479 | + range.getEnd().getColumn()) |
| 2480 | + : null)); |
| 2481 | + } |
| 2482 | + }); |
| 2483 | + assertEquals(List.of(new Data(ErrorKind.WARNING, Pair.of(Pair.of(4, 9), Pair.of(4, 19))), |
| 2484 | + new Data(ErrorKind.WARNING, Pair.of(Pair.of(4, 17), null))), |
| 2485 | + errors); |
| 2486 | + } |
| 2487 | + |
2434 | 2488 | public static void noop() {} |
2435 | 2489 |
|
2436 | 2490 | @Override |
|
0 commit comments