mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
"indexing" module housekeeping
This commit is contained in:
-50
@@ -25,26 +25,17 @@ import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.fileTypes.LanguageFileType;
|
||||
import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType;
|
||||
import com.intellij.psi.CustomHighlighterTokenType;
|
||||
import com.intellij.psi.impl.cache.impl.IndexPatternUtil;
|
||||
import com.intellij.psi.impl.cache.impl.OccurrenceConsumer;
|
||||
import com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry;
|
||||
import com.intellij.psi.impl.cache.impl.todo.TodoIndexers;
|
||||
import com.intellij.psi.search.IndexPattern;
|
||||
import com.intellij.psi.search.UsageSearchContext;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.indexing.DataIndexer;
|
||||
import com.intellij.util.indexing.FileContent;
|
||||
import com.intellij.util.indexing.IdDataConsumer;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class IdTableBuilding {
|
||||
private IdTableBuilding() {
|
||||
@@ -74,41 +65,6 @@ public class IdTableBuilding {
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlainTextTodoIndexer implements DataIndexer<TodoIndexEntry, Integer, FileContent> {
|
||||
@Override
|
||||
@NotNull
|
||||
public Map<TodoIndexEntry, Integer> map(final FileContent inputData) {
|
||||
final CharSequence chars = inputData.getContentAsText();
|
||||
|
||||
|
||||
final IndexPattern[] indexPatterns = IndexPatternUtil.getIndexPatterns();
|
||||
if (indexPatterns.length > 0) {
|
||||
final OccurrenceConsumer occurrenceConsumer = new OccurrenceConsumer(null, true);
|
||||
for (IndexPattern indexPattern : indexPatterns) {
|
||||
Pattern pattern = indexPattern.getPattern();
|
||||
if (pattern != null) {
|
||||
Matcher matcher = pattern.matcher(chars);
|
||||
while (matcher.find()) {
|
||||
if (matcher.start() != matcher.end()) {
|
||||
occurrenceConsumer.incTodoOccurrence(indexPattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<TodoIndexEntry, Integer> map = new HashMap<TodoIndexEntry, Integer>();
|
||||
for (IndexPattern indexPattern : indexPatterns) {
|
||||
final int count = occurrenceConsumer.getOccurrenceCount(indexPattern);
|
||||
if (count > 0) {
|
||||
map.put(new TodoIndexEntry(indexPattern.getPatternString(), indexPattern.isCaseSensitive()), count);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final HashMap<FileType, FileTypeIdIndexer> ourIdIndexers = new HashMap<FileType, FileTypeIdIndexer>();
|
||||
|
||||
@Deprecated
|
||||
@@ -120,11 +76,6 @@ public class IdTableBuilding {
|
||||
return ourIdIndexers.containsKey(fileType) || IdIndexers.INSTANCE.forFileType(fileType) != null;
|
||||
}
|
||||
|
||||
public static boolean isTodoIndexerRegistered(FileType fileType) {
|
||||
return ourIdIndexers.containsKey(fileType) || TodoIndexers.INSTANCE.forFileType(fileType) != null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Nullable
|
||||
public static FileTypeIdIndexer getFileTypeIndexer(FileType fileType) {
|
||||
@@ -249,5 +200,4 @@ public class IdTableBuilding {
|
||||
processor.run(chars, charArray, index1, index);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+41
-1
@@ -50,6 +50,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Author: dmitrylomov
|
||||
@@ -114,6 +116,9 @@ public abstract class PlatformIdTableBuilding {
|
||||
ourTodoIndexers.put(fileType, indexer);
|
||||
}
|
||||
|
||||
public static boolean isTodoIndexerRegistered(FileType fileType) {
|
||||
return ourTodoIndexers.containsKey(fileType) || TodoIndexers.INSTANCE.forFileType(fileType) != null;
|
||||
}
|
||||
|
||||
private static class CompositeTodoIndexer implements DataIndexer<TodoIndexEntry, Integer, FileContent> {
|
||||
|
||||
@@ -201,9 +206,44 @@ public abstract class PlatformIdTableBuilding {
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlainTextTodoIndexer implements DataIndexer<TodoIndexEntry, Integer, FileContent> {
|
||||
@Override
|
||||
@NotNull
|
||||
public Map<TodoIndexEntry, Integer> map(final FileContent inputData) {
|
||||
final CharSequence chars = inputData.getContentAsText();
|
||||
|
||||
|
||||
final IndexPattern[] indexPatterns = IndexPatternUtil.getIndexPatterns();
|
||||
if (indexPatterns.length > 0) {
|
||||
final OccurrenceConsumer occurrenceConsumer = new OccurrenceConsumer(null, true);
|
||||
for (IndexPattern indexPattern : indexPatterns) {
|
||||
Pattern pattern = indexPattern.getPattern();
|
||||
if (pattern != null) {
|
||||
Matcher matcher = pattern.matcher(chars);
|
||||
while (matcher.find()) {
|
||||
if (matcher.start() != matcher.end()) {
|
||||
occurrenceConsumer.incTodoOccurrence(indexPattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<TodoIndexEntry, Integer> map = new HashMap<TodoIndexEntry, Integer>();
|
||||
for (IndexPattern indexPattern : indexPatterns) {
|
||||
final int count = occurrenceConsumer.getOccurrenceCount(indexPattern);
|
||||
if (count > 0) {
|
||||
map.put(new TodoIndexEntry(indexPattern.getPatternString(), indexPattern.isCaseSensitive()), count);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static {
|
||||
IdTableBuilding.registerIdIndexer(FileTypes.PLAIN_TEXT, new IdTableBuilding.PlainTextIndexer());
|
||||
registerTodoIndexer(FileTypes.PLAIN_TEXT, new IdTableBuilding.PlainTextTodoIndexer());
|
||||
registerTodoIndexer(FileTypes.PLAIN_TEXT, new PlainTextTodoIndexer());
|
||||
|
||||
IdTableBuilding.registerIdIndexer(StdFileTypes.IDEA_MODULE, null);
|
||||
IdTableBuilding.registerIdIndexer(StdFileTypes.IDEA_WORKSPACE, null);
|
||||
|
||||
+1
-2
@@ -25,7 +25,6 @@ import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType;
|
||||
import com.intellij.openapi.project.ProjectCoreUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.impl.cache.impl.id.IdTableBuilding;
|
||||
import com.intellij.psi.impl.cache.impl.id.PlatformIdTableBuilding;
|
||||
import com.intellij.psi.search.IndexPatternProvider;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
@@ -130,7 +129,7 @@ public class TodoIndex extends FileBasedIndexExtension<TodoIndexEntry, Integer>
|
||||
return commentTokens != null;
|
||||
}
|
||||
|
||||
return IdTableBuilding.isTodoIndexerRegistered(fileType) ||
|
||||
return PlatformIdTableBuilding.isTodoIndexerRegistered(fileType) ||
|
||||
fileType instanceof CustomSyntaxTableFileType;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -39,7 +39,7 @@ import com.intellij.psi.impl.cache.CacheManager;
|
||||
import com.intellij.psi.impl.cache.impl.id.IdIndex;
|
||||
import com.intellij.psi.impl.cache.impl.id.IdIndexEntry;
|
||||
import com.intellij.psi.search.*;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.CommonProcessors;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.SmartList;
|
||||
@@ -93,7 +93,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper {
|
||||
}
|
||||
});
|
||||
synchronized (results) {
|
||||
return PsiUtilBase.toPsiElementArray(results);
|
||||
return PsiUtilCore.toPsiElementArray(results);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user