2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.openapi
.roots
.impl
;
18 import com
.intellij
.openapi
.roots
.ModuleFileIndex
;
19 import com
.intellij
.openapi
.roots
.ModulePackageIndex
;
20 import com
.intellij
.openapi
.roots
.ModuleRootManager
;
21 import com
.intellij
.openapi
.util
.Condition
;
22 import com
.intellij
.openapi
.vfs
.VirtualFile
;
23 import com
.intellij
.util
.FilteredQuery
;
24 import com
.intellij
.util
.Query
;
25 import org
.jetbrains
.annotations
.NotNull
;
27 public class ModulePackageIndexImpl
extends ModulePackageIndex
{
28 private final ModuleFileIndex myModuleFileIndex
;
29 private final DirectoryIndex myDirectoryIndex
;
31 public ModulePackageIndexImpl(ModuleRootManager moduleRootManager
, DirectoryIndex directoryIndex
) {
32 myModuleFileIndex
= moduleRootManager
.getFileIndex();
33 myDirectoryIndex
= directoryIndex
;
36 private final Condition
<VirtualFile
> myDirCondition
= new Condition
<VirtualFile
>() {
37 public boolean value(final VirtualFile dir
) {
38 return dir
.isValid() && myModuleFileIndex
.getOrderEntryForFile(dir
) != null;
42 public Query
<VirtualFile
> getDirsByPackageName(@NotNull String packageName
, boolean includeLibrarySources
) {
43 return new FilteredQuery
<VirtualFile
>(myDirectoryIndex
.getDirectoriesByPackageName(packageName
, includeLibrarySources
), myDirCondition
);
46 public VirtualFile
[] getDirectoriesByPackageName(@NotNull String packageName
, boolean includeLibrarySources
) {
47 return getDirsByPackageName(packageName
, includeLibrarySources
).toArray(VirtualFile
.EMPTY_ARRAY
);