fix "IDEA-221944 Deadlock on opening second project" and support preloading for proje...
[idea/community.git] / java / java-indexing-impl / src / com / intellij / openapi / roots / impl / ProjectPackageIndexImpl.java
1 // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.openapi.roots.impl;
3
4 import com.intellij.openapi.project.Project;
5 import com.intellij.openapi.roots.PackageIndex;
6 import com.intellij.openapi.vfs.VirtualFile;
7 import com.intellij.util.Query;
8 import org.jetbrains.annotations.NotNull;
9
10 final class ProjectPackageIndexImpl extends PackageIndex {
11   private final DirectoryIndex myDirectoryIndex;
12
13   ProjectPackageIndexImpl(@NotNull Project project) {
14     myDirectoryIndex = DirectoryIndex.getInstance(project);
15   }
16
17   @NotNull
18   @Override
19   public VirtualFile[] getDirectoriesByPackageName(@NotNull String packageName, boolean includeLibrarySources) {
20     return getDirsByPackageName(packageName, includeLibrarySources).toArray(VirtualFile.EMPTY_ARRAY);
21   }
22
23   @NotNull
24   @Override
25   public Query<VirtualFile> getDirsByPackageName(@NotNull String packageName, boolean includeLibrarySources) {
26     return myDirectoryIndex.getDirectoriesByPackageName(packageName, includeLibrarySources);
27   }
28 }