|
93 | 93 | import org.netbeans.modules.parsing.spi.SchedulerTask; |
94 | 94 | import org.netbeans.modules.parsing.spi.SourceModificationEvent; |
95 | 95 | import org.netbeans.modules.parsing.spi.TaskFactory; |
| 96 | +import org.netbeans.spi.java.queries.CompilerOptionsQueryImplementation; |
| 97 | +import org.openide.util.lookup.ProxyLookup; |
96 | 98 |
|
97 | 99 | /** |
98 | 100 | * |
@@ -627,6 +629,53 @@ public void run(CompilationController parameter) throws Exception { |
627 | 629 | }, true); |
628 | 630 | } |
629 | 631 |
|
| 632 | + public void testReleaseValidateCompilerOptionsBasedOnRelease() throws Exception { |
| 633 | + FileObject f = createFile("test/Test.java", |
| 634 | + """ |
| 635 | + package test; |
| 636 | + import javax.tools.Diagnostic; |
| 637 | + """); |
| 638 | + SourceUtilsTestUtil.setSourceLevel(f, "17"); |
| 639 | + SourceUtilsTestUtil.setCompilerOptions(f, List.of("--limit-modules=java.base")); |
| 640 | + JavaSource js = JavaSource.create(new ClasspathInfo.Builder(ClassPath.EMPTY).build(), f); |
| 641 | + |
| 642 | + js.runUserActionTask(new Task<CompilationController>() { |
| 643 | + public void run(CompilationController parameter) throws Exception { |
| 644 | + assertTrue(Phase.RESOLVED.compareTo(parameter.toPhase(Phase.RESOLVED)) <= 0); |
| 645 | + assertEquals(parameter.getDiagnostics().toString(), 1, parameter.getDiagnostics().size()); |
| 646 | + |
| 647 | + Set<String> codes = new HashSet<String>(); |
| 648 | + |
| 649 | + for (Diagnostic d : parameter.getDiagnostics()) { |
| 650 | + codes.add(d.getCode()); |
| 651 | + } |
| 652 | + |
| 653 | + assertEquals(new HashSet<String>(Arrays.asList("compiler.err.package.not.visible")), codes); |
| 654 | + } |
| 655 | + }, true); |
| 656 | + } |
| 657 | + |
| 658 | + public void testReleaseUnsupportedSourceLevel() throws Exception { |
| 659 | + FileObject f = createFile("test/Test.java", |
| 660 | + """ |
| 661 | + package test; |
| 662 | + public class Test { |
| 663 | + public static void main(String... args) { |
| 664 | + System.out.println(""); |
| 665 | + } |
| 666 | + } |
| 667 | + """); |
| 668 | + SourceUtilsTestUtil.setSourceLevel(f, "1.4"); |
| 669 | + JavaSource js = JavaSource.create(new ClasspathInfo.Builder(ClassPath.EMPTY).build(), f); |
| 670 | + |
| 671 | + js.runUserActionTask(new Task<CompilationController>() { |
| 672 | + public void run(CompilationController parameter) throws Exception { |
| 673 | + assertTrue(Phase.RESOLVED.compareTo(parameter.toPhase(Phase.RESOLVED)) <= 0); |
| 674 | + assertEquals(parameter.getDiagnostics().toString(), 0, parameter.getDiagnostics().size()); |
| 675 | + } |
| 676 | + }, true); |
| 677 | + } |
| 678 | + |
630 | 679 | private FileObject createFile(String path, String content) throws Exception { |
631 | 680 | FileObject file = FileUtil.createData(sourceRoot, path); |
632 | 681 | TestUtilities.copyStringToFile(file, content); |
|
0 commit comments