|
1 | 1 | package com.cedricziel.idea.typo3.index; |
2 | 2 |
|
3 | 3 | import com.intellij.openapi.project.Project; |
| 4 | +import com.intellij.psi.PsiElement; |
| 5 | +import com.intellij.psi.PsiManager; |
| 6 | +import com.intellij.psi.search.GlobalSearchScope; |
4 | 7 | import com.intellij.util.indexing.*; |
5 | 8 | import com.intellij.util.io.EnumeratorStringDescriptor; |
6 | 9 | import com.intellij.util.io.KeyDescriptor; |
7 | 10 | import gnu.trove.THashMap; |
8 | 11 | import org.jetbrains.annotations.NotNull; |
9 | 12 |
|
10 | | -import java.util.Collection; |
11 | | -import java.util.Map; |
| 13 | +import java.util.*; |
12 | 14 |
|
13 | 15 | public class ResourcePathIndex extends ScalarIndexExtension<String> { |
14 | 16 |
|
15 | 17 | public static final ID<String, Void> KEY = ID.create("com.cedricziel.idea.typo3.index.resource_path"); |
16 | 18 |
|
| 19 | + public static Collection<String> getAvailableExtensionResourceFiles(@NotNull Project project) { |
| 20 | + return FileBasedIndex.getInstance().getAllKeys(ResourcePathIndex.KEY, project); |
| 21 | + } |
| 22 | + |
| 23 | + public static boolean projectContainsResourceFile(@NotNull Project project, @NotNull String resourceId) { |
| 24 | + return FileBasedIndex.getInstance().getAllKeys(ResourcePathIndex.KEY, project).contains(resourceId); |
| 25 | + } |
| 26 | + |
| 27 | + public static boolean projectContainsResourceDirectory(@NotNull Project project, @NotNull String resourceId) { |
| 28 | + return false; |
| 29 | + } |
| 30 | + |
| 31 | + public static PsiElement[] findElementsForKey(@NotNull Project project, @NotNull String identifier) { |
| 32 | + Set<String> keys = new HashSet<>(); |
| 33 | + keys.add(identifier); |
| 34 | + Set<PsiElement> elements = new HashSet<>(); |
| 35 | + |
| 36 | + FileBasedIndex.getInstance().getFilesWithKey(ResourcePathIndex.KEY, keys, virtualFile -> { |
| 37 | + elements.add(PsiManager.getInstance(project).findFile(virtualFile)); |
| 38 | + |
| 39 | + return true; |
| 40 | + }, GlobalSearchScope.allScope(project)); |
| 41 | + |
| 42 | + return elements |
| 43 | + .stream() |
| 44 | + .filter(Objects::nonNull) |
| 45 | + .toArray(PsiElement[]::new); |
| 46 | + } |
| 47 | + |
17 | 48 | @NotNull |
18 | 49 | @Override |
19 | 50 | public ID<String, Void> getName() { |
@@ -59,23 +90,11 @@ public int getVersion() { |
59 | 90 | @NotNull |
60 | 91 | @Override |
61 | 92 | public FileBasedIndex.InputFilter getInputFilter() { |
62 | | - return file -> file.isInLocalFileSystem() && (file.getPath().contains("sysext") ||file.getPath().contains("typo3conf/ext")); |
| 93 | + return file -> file.isInLocalFileSystem() && (file.getPath().contains("sysext") || file.getPath().contains("typo3conf/ext")); |
63 | 94 | } |
64 | 95 |
|
65 | 96 | @Override |
66 | 97 | public boolean dependsOnFileContent() { |
67 | 98 | return false; |
68 | 99 | } |
69 | | - |
70 | | - public static Collection<String> getAvailableExtensionResourceFiles(@NotNull Project project) { |
71 | | - return FileBasedIndex.getInstance().getAllKeys(ResourcePathIndex.KEY, project); |
72 | | - } |
73 | | - |
74 | | - public static boolean projectContainsResourceFile(@NotNull Project project, @NotNull String resourceId) { |
75 | | - return FileBasedIndex.getInstance().getAllKeys(ResourcePathIndex.KEY, project).contains(resourceId); |
76 | | - } |
77 | | - |
78 | | - public static boolean projectContainsResourceDirectory(@NotNull Project project, @NotNull String resourceId) { |
79 | | - return false; |
80 | | - } |
81 | 100 | } |
0 commit comments