|
31 | 31 | import javax.lang.model.element.ElementKind; |
32 | 32 | import javax.lang.model.element.TypeElement; |
33 | 33 | import javax.swing.event.ChangeListener; |
| 34 | +import javax.tools.JavaFileObject; |
| 35 | +import javax.tools.ToolProvider; |
34 | 36 | import org.netbeans.api.java.classpath.ClassPath; |
35 | 37 | import org.netbeans.api.java.classpath.GlobalPathRegistry; |
36 | 38 | import org.netbeans.api.java.platform.JavaPlatformManager; |
@@ -92,6 +94,7 @@ public static NbTestSuite suite() { |
92 | 94 | suite.addTest(new ClassIndexTest("testPackageUsages")); //NOI18N |
93 | 95 | suite.addTest(new ClassIndexTest("testNullRootPassedToClassIndexEvent")); //NOI18N |
94 | 96 | suite.addTest(new ClassIndexTest("testFindSymbols")); //NOI18N |
| 97 | + suite.addTest(new ClassIndexTest("testQueryIndexRefreshQueryAgain")); //NOI18N |
95 | 98 | return suite; |
96 | 99 | } |
97 | 100 |
|
@@ -576,6 +579,55 @@ public void testFindSymbols() throws Exception { |
576 | 579 | assertEquals(new HashSet<String>(Arrays.asList("test.foo:[foo]", "test.Test:[foo]")), actualResult); |
577 | 580 | } |
578 | 581 |
|
| 582 | + public void testQueryIndexRefreshQueryAgain() throws Exception { |
| 583 | + final FileObject wd = FileUtil.toFileObject(getWorkDir()); |
| 584 | + final FileObject root = FileUtil.createFolder(wd,"src"); //NOI18N |
| 585 | + final FileObject classes = FileUtil.createFolder(wd,"classes"); //NOI18N |
| 586 | + sourcePath = ClassPathSupport.createClassPath(root); |
| 587 | + final FileObject t1 = createJavaFile( |
| 588 | + root, |
| 589 | + "org.me.test", //NOI18N |
| 590 | + "T1", //NOI18N |
| 591 | + "package org.me.test;\n"+ //NOI18N |
| 592 | + "public class T1 extends java.util.ArrayList {}"); //NOI18N |
| 593 | + //compile binary dependency: |
| 594 | + JavaFileObject libraryJFO = |
| 595 | + FileObjects.memoryFileObject("lib", |
| 596 | + "TestLib.java", |
| 597 | + """ |
| 598 | + package lib; |
| 599 | + public class TestLib {} |
| 600 | + """); |
| 601 | + ToolProvider.getSystemJavaCompiler() |
| 602 | + .getTask(null, |
| 603 | + null, |
| 604 | + null, |
| 605 | + List.of("-d", |
| 606 | + FileUtil.toFile(classes).getAbsolutePath()), |
| 607 | + null, |
| 608 | + List.of(libraryJFO)) |
| 609 | + .call(); |
| 610 | + |
| 611 | + compilePath = ClassPathSupport.createClassPath(classes); |
| 612 | + bootPath = JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries(); |
| 613 | + |
| 614 | + final ClassIndex ci = ClasspathInfo.create(bootPath, compilePath, sourcePath).getClassIndex(); |
| 615 | + Set<ElementHandle<TypeElement>> result; |
| 616 | + result = ci.getDeclaredTypes("TestLib", NameKind.PREFIX, Set.of(ClassIndex.SearchScope.DEPENDENCIES)); |
| 617 | + assertElementHandles(new String[] {}, result); |
| 618 | + |
| 619 | + GlobalPathRegistry.getDefault().register(ClassPath.BOOT, new ClassPath[] {bootPath}); |
| 620 | + GlobalPathRegistry.getDefault().register(ClassPath.COMPILE, new ClassPath[] {compilePath}); |
| 621 | + GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {sourcePath}); |
| 622 | + |
| 623 | + IndexingManager.getDefault().refreshAllIndices(true, true, root); |
| 624 | + SourceUtils.waitScanFinished(); |
| 625 | + |
| 626 | + result = ci.getDeclaredTypes("TestLib", NameKind.PREFIX, Set.of(ClassIndex.SearchScope.DEPENDENCIES)); |
| 627 | + assertNotNull(result); |
| 628 | + assertElementHandles(new String[] {"lib.TestLib"}, result); |
| 629 | + } |
| 630 | + |
579 | 631 | private FileObject createJavaFile ( |
580 | 632 | final FileObject root, |
581 | 633 | final String pkg, |
|
0 commit comments