22 * Copyright © Magento, Inc. All rights reserved.
33 * See COPYING.txt for license details.
44 */
5+
56package com .magento .idea .magento2plugin .indexes ;
67
78import com .intellij .openapi .project .Project ;
1516import com .magento .idea .magento2plugin .stubs .indexes .EventNameIndex ;
1617import com .magento .idea .magento2plugin .stubs .indexes .EventObserverIndex ;
1718import com .magento .idea .magento2plugin .util .xml .XmlPsiTreeUtil ;
18-
1919import java .util .ArrayList ;
2020import java .util .Collection ;
2121
@@ -24,6 +24,9 @@ public class EventIndex {
2424 private static EventIndex INSTANCE ; //NOPMD
2525 private Project project ;
2626
27+ /**
28+ * Gets singleton instance.
29+ */
2730 public static EventIndex getInstance (final Project project ) {
2831 if (null == INSTANCE ) { //NOPMD
2932 INSTANCE = new EventIndex ();
@@ -33,7 +36,13 @@ public static EventIndex getInstance(final Project project) {
3336 return INSTANCE ;
3437 }
3538
36- public Collection <PsiElement > getEventElements (final String name , final GlobalSearchScope scope ) {
39+ /**
40+ * Gets event elements by event name.
41+ */
42+ public Collection <PsiElement > getEventElements (
43+ final String name ,
44+ final GlobalSearchScope scope
45+ ) {
3746 final Collection <PsiElement > result = new ArrayList <>();
3847
3948 final Collection <VirtualFile > virtualFiles =
@@ -48,22 +57,26 @@ public Collection<PsiElement> getEventElements(final String name, final GlobalSe
4857 return result ;
4958 }
5059
51- public Collection <PsiElement > getObserver (
60+ /**
61+ * Gets observers by event-observer name combination.
62+ */
63+ public Collection <PsiElement > getObservers (
5264 final String eventName ,
5365 final String observerName ,
5466 final GlobalSearchScope scope
5567 ) {
5668 final Collection <PsiElement > result = new ArrayList <>();
57- final Collection <VirtualFile > virtualFiles = FileBasedIndex .getInstance ().getContainingFiles (
58- EventObserverIndex .KEY , eventName , scope
59- );
69+ final Collection <VirtualFile > virtualFiles
70+ = FileBasedIndex .getInstance ().getContainingFiles (
71+ EventObserverIndex .KEY , eventName , scope
72+ );
6073
6174 for (final VirtualFile virtualFile : virtualFiles ) {
6275 final XmlFile eventsXmlFile
6376 = (XmlFile ) PsiManager .getInstance (project ).findFile (virtualFile );
6477 if (eventsXmlFile != null ) {
6578 result .addAll (
66- XmlPsiTreeUtil .findObserverTag (eventsXmlFile , eventName , observerName )
79+ XmlPsiTreeUtil .findObserverTags (eventsXmlFile , eventName , observerName )
6780 );
6881 }
6982 }
0 commit comments