update copyright
[fedora-idea.git] / xml / impl / src / com / intellij / xml / index / XmlTagNamesIndex.java
blobf26e3705671a19fc94ea4710c4dedec9e53dbc0f
1 /*
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.project.Project;
19 import com.intellij.openapi.vfs.VirtualFile;
20 import com.intellij.util.containers.HashMap;
21 import com.intellij.util.indexing.*;
22 import com.intellij.util.io.DataExternalizer;
23 import org.jetbrains.annotations.NotNull;
25 import java.io.ByteArrayInputStream;
26 import java.util.Collection;
27 import java.util.Collections;
28 import java.util.Map;
30 /**
31 * @author Dmitry Avdeev
33 public class XmlTagNamesIndex extends XmlIndex<Void> {
35 public static Collection<VirtualFile> getFilesByTagName(String tagName, final Project project) {
36 return FileBasedIndex.getInstance().getContainingFiles(NAME, tagName, createFilter(project));
39 public static Collection<String> getAllTagNames(Project project) {
40 return FileBasedIndex.getInstance().getAllKeys(NAME, project);
43 static void requestRebuild() {
44 FileBasedIndex.getInstance().requestRebuild(NAME);
47 private static final ID<String,Void> NAME = ID.create("XmlTagNames");
49 public ID<String, Void> getName() {
50 return NAME;
53 public DataIndexer<String, Void, FileContent> getIndexer() {
54 return new DataIndexer<String, Void, FileContent>() {
55 @NotNull
56 public Map<String, Void> map(final FileContent inputData) {
57 final Collection<String> tags = XsdTagNameBuilder.computeTagNames(new ByteArrayInputStream(inputData.getContent()));
58 if (tags != null && !tags.isEmpty()) {
59 final HashMap<String, Void> map = new HashMap<String, Void>(tags.size());
60 for (String tag : tags) {
61 map.put(tag, null);
63 return map;
64 } else {
65 return Collections.emptyMap();
71 public DataExternalizer<Void> getValueExternalizer() {
72 return ScalarIndexExtension.VOID_DATA_EXTERNALIZER;