forked from magento/magento2-phpstorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginIndex.java
78 lines (67 loc) · 2.32 KB
/
PluginIndex.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2plugin.indexes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiManager;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.psi.xml.XmlFile;
import com.intellij.util.indexing.FileBasedIndex;
import com.magento.idea.magento2plugin.magento.files.ModuleDiXml;
import com.magento.idea.magento2plugin.util.xml.XmlPsiTreeUtil;
import java.util.ArrayList;
import java.util.Collection;
public final class PluginIndex {
private static PluginIndex INSTANCE; //NOPMD
private Project project;
private PluginIndex() {
}
/**
* Getter fo index instance.
*
* @param project Project
* @return PluginIndex
*/
public static PluginIndex getInstance(final Project project) {
if (null == INSTANCE) { //NOPMD
INSTANCE = new PluginIndex();
}
INSTANCE.project = project;
return INSTANCE;
}
/**
* Getter fo plugin elements.
*
* @param name String
* @param scope GlobalSearchScope
* @return Collection
*/
public Collection<PsiElement> getPluginElements(
final String name,
final GlobalSearchScope scope
) {
final Collection<PsiElement> result = new ArrayList<>();
final Collection<VirtualFile> virtualFiles =
FileBasedIndex.getInstance().getContainingFiles(
com.magento.idea.magento2plugin.stubs.indexes.PluginIndex.KEY,
name,
scope
);
for (final VirtualFile virtualFile : virtualFiles) {
final XmlFile xmlFile = (XmlFile) PsiManager.getInstance(project).findFile(virtualFile);
final Collection<XmlAttributeValue> valueElements = XmlPsiTreeUtil
.findAttributeValueElements(
xmlFile,
ModuleDiXml.TYPE_ATTR,
ModuleDiXml.NAME_ATTR,
name
);
result.addAll(valueElements);
}
return result;
}
}