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
.xml
.index
;
18 import com
.intellij
.openapi
.module
.Module
;
19 import com
.intellij
.openapi
.project
.Project
;
20 import com
.intellij
.openapi
.roots
.OrderEntry
;
21 import com
.intellij
.openapi
.roots
.ProjectFileIndex
;
22 import com
.intellij
.openapi
.roots
.ProjectRootManager
;
23 import com
.intellij
.openapi
.vfs
.VirtualFile
;
24 import com
.intellij
.openapi
.vfs
.VirtualFileFilter
;
25 import com
.intellij
.psi
.search
.GlobalSearchScope
;
26 import com
.intellij
.util
.indexing
.FileBasedIndex
;
27 import com
.intellij
.util
.indexing
.FileBasedIndexExtension
;
28 import com
.intellij
.util
.io
.EnumeratorStringDescriptor
;
29 import com
.intellij
.util
.io
.KeyDescriptor
;
30 import org
.jetbrains
.annotations
.NonNls
;
31 import org
.jetbrains
.annotations
.NotNull
;
33 import java
.util
.List
;
36 * @author Dmitry Avdeev
38 public abstract class XmlIndex
<V
> extends FileBasedIndexExtension
<String
, V
> {
40 protected static final EnumeratorStringDescriptor KEY_DESCRIPTOR
= new EnumeratorStringDescriptor();
42 private static final FileBasedIndex
.InputFilter INPUT_FILTER
= new FileBasedIndex
.InputFilter() {
43 public boolean acceptInput(final VirtualFile file
) {
44 @NonNls final String extension
= file
.getExtension();
45 return extension
!= null && extension
.equals("xsd");
49 protected static GlobalSearchScope
createFilter(final Project project
) {
50 final GlobalSearchScope projectScope
= GlobalSearchScope
.allScope(project
);
51 return new GlobalSearchScope(project
) {
52 public int compare(VirtualFile file1
, VirtualFile file2
) {
53 return projectScope
.compare(file1
, file2
);
56 public boolean isSearchInModuleContent(@NotNull Module aModule
) {
61 public boolean contains(VirtualFile file
) {
62 final VirtualFile parent
= file
.getParent();
63 assert parent
!= null;
64 return parent
.getName().equals("standardSchemas") || projectScope
.contains(file
);
68 public boolean isSearchInLibraries() {
75 protected static VirtualFileFilter
createFilter(@NotNull final Module module
) {
77 final ProjectFileIndex fileIndex
= ProjectRootManager
.getInstance(module
.getProject()).getFileIndex();
78 return new VirtualFileFilter() {
79 public boolean accept(final VirtualFile file
) {
80 Module moduleForFile
= fileIndex
.getModuleForFile(file
);
81 if (moduleForFile
!= null) { // in module content
82 return module
.equals(moduleForFile
);
84 if (fileIndex
.isInLibraryClasses(file
)) {
85 List
<OrderEntry
> orderEntries
= fileIndex
.getOrderEntriesForFile(file
);
86 if (orderEntries
.isEmpty()) {
89 for (OrderEntry orderEntry
: orderEntries
) {
90 Module ownerModule
= orderEntry
.getOwnerModule();
91 if (ownerModule
!= null) {
92 if (ownerModule
.equals(module
)) {
98 final VirtualFile parent
= file
.getParent();
99 assert parent
!= null;
100 return parent
.getName().equals("standardSchemas");
105 public KeyDescriptor
<String
> getKeyDescriptor() {
106 return KEY_DESCRIPTOR
;
109 public FileBasedIndex
.InputFilter
getInputFilter() {
113 public boolean dependsOnFileContent() {
117 public int getVersion() {