Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,8 @@ private void createQueriesForRoots (final ClassPath cp, final boolean sources, f
if (ci != null) {
ci.addClassIndexImplListener(spiListener);
queries.add (ci);
} else {
spiListener.attachClassIndexManagerListener();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;
import javax.swing.event.ChangeListener;
import javax.tools.JavaFileObject;
import javax.tools.ToolProvider;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.java.classpath.GlobalPathRegistry;
import org.netbeans.api.java.platform.JavaPlatformManager;
Expand Down Expand Up @@ -92,6 +94,7 @@ public static NbTestSuite suite() {
suite.addTest(new ClassIndexTest("testPackageUsages")); //NOI18N
suite.addTest(new ClassIndexTest("testNullRootPassedToClassIndexEvent")); //NOI18N
suite.addTest(new ClassIndexTest("testFindSymbols")); //NOI18N
suite.addTest(new ClassIndexTest("testQueryIndexRefreshQueryAgain")); //NOI18N
return suite;
}

Expand Down Expand Up @@ -576,6 +579,55 @@ public void testFindSymbols() throws Exception {
assertEquals(new HashSet<String>(Arrays.asList("test.foo:[foo]", "test.Test:[foo]")), actualResult);
}

public void testQueryIndexRefreshQueryAgain() throws Exception {
final FileObject wd = FileUtil.toFileObject(getWorkDir());
final FileObject root = FileUtil.createFolder(wd,"src"); //NOI18N
final FileObject classes = FileUtil.createFolder(wd,"classes"); //NOI18N
sourcePath = ClassPathSupport.createClassPath(root);
final FileObject t1 = createJavaFile(
root,
"org.me.test", //NOI18N
"T1", //NOI18N
"package org.me.test;\n"+ //NOI18N
"public class T1 extends java.util.ArrayList {}"); //NOI18N
//compile binary dependency:
JavaFileObject libraryJFO =
FileObjects.memoryFileObject("lib",
"TestLib.java",
"""
package lib;
public class TestLib {}
""");
ToolProvider.getSystemJavaCompiler()
.getTask(null,
null,
null,
List.of("-d",
FileUtil.toFile(classes).getAbsolutePath()),
null,
List.of(libraryJFO))
.call();

compilePath = ClassPathSupport.createClassPath(classes);
bootPath = JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries();

final ClassIndex ci = ClasspathInfo.create(bootPath, compilePath, sourcePath).getClassIndex();
Set<ElementHandle<TypeElement>> result;
result = ci.getDeclaredTypes("TestLib", NameKind.PREFIX, Set.of(ClassIndex.SearchScope.DEPENDENCIES));
assertElementHandles(new String[] {}, result);

GlobalPathRegistry.getDefault().register(ClassPath.BOOT, new ClassPath[] {bootPath});
GlobalPathRegistry.getDefault().register(ClassPath.COMPILE, new ClassPath[] {compilePath});
GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {sourcePath});

IndexingManager.getDefault().refreshAllIndices(true, true, root);
SourceUtils.waitScanFinished();

result = ci.getDeclaredTypes("TestLib", NameKind.PREFIX, Set.of(ClassIndex.SearchScope.DEPENDENCIES));
assertNotNull(result);
assertElementHandles(new String[] {"lib.TestLib"}, result);
}

private FileObject createJavaFile (
final FileObject root,
final String pkg,
Expand Down
Loading