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