23
23
import org .jetbrains .annotations .NotNull ;
24
24
import java .net .MalformedURLException ;
25
25
import java .net .URL ;
26
- import java .util .ArrayList ;
27
- import java .util .Collection ;
28
- import java .util .HashMap ;
29
- import java .util .List ;
26
+ import java .util .*;
27
+
30
28
import com .intellij .openapi .vfs .VfsUtil ;
31
29
import org .jetbrains .annotations .Nullable ;
32
30
@@ -93,9 +91,12 @@ public void visitFile(PsiFile file) {
93
91
}
94
92
targetObserversHash .put (observerKey , observerXmlTag );
95
93
96
- HashMap <String , String > modulesWithSameObserverName = fetchModuleNamesWhereSameObserverNameUsed (eventNameAttributeValue , observerName , eventIndex , file );
97
- for (String moduleName : modulesWithSameObserverName .keySet ()) {
98
- String problemKey = observerKey .concat ("_" ).concat (moduleName );
94
+ List <HashMap <String , String >> modulesWithSameObserverName = fetchModuleNamesWhereSameObserverNameUsed (eventNameAttributeValue , observerName , eventIndex , file );
95
+ for (HashMap <String , String > moduleEntry : modulesWithSameObserverName ) {
96
+ Map .Entry <String , String > module = moduleEntry .entrySet ().iterator ().next ();
97
+ String moduleName = module .getKey ();
98
+ String scope = module .getValue ();
99
+ String problemKey = observerKey .concat ("_" ).concat (moduleName ).concat ("_" ).concat (scope );
99
100
if (!eventProblems .containsKey (problemKey )){
100
101
problemsHolder .registerProblem (
101
102
observerNameAttribute .getValueElement (),
@@ -104,7 +105,7 @@ public void visitFile(PsiFile file) {
104
105
observerName ,
105
106
eventNameAttributeValue ,
106
107
moduleName ,
107
- modulesWithSameObserverName . get ( moduleName )
108
+ scope
108
109
),
109
110
errorSeverity
110
111
);
@@ -115,11 +116,10 @@ public void visitFile(PsiFile file) {
115
116
}
116
117
}
117
118
118
- private HashMap <String , String > fetchModuleNamesWhereSameObserverNameUsed (String eventNameAttributeValue , String observerName , EventIndex eventIndex , PsiFile file ) {
119
- HashMap <String , String > modulesName = new HashMap < String , String >();
119
+ private List < HashMap <String , String > > fetchModuleNamesWhereSameObserverNameUsed (String eventNameAttributeValue , String observerName , EventIndex eventIndex , PsiFile file ) {
120
+ List < HashMap <String , String >> modulesName = new ArrayList < >();
120
121
String currentFileDirectory = file .getContainingDirectory ().toString ();
121
122
String currentFileFullPath = currentFileDirectory .concat ("/" ).concat (file .getName ());
122
- String scope = MagentoPackages .AREA_BASE ;
123
123
124
124
Collection <PsiElement > indexedEvents = eventIndex .getEventElements (eventNameAttributeValue , GlobalSearchScope .getScopeRestrictedByFileTypes (
125
125
GlobalSearchScope .allScope (file .getProject ()),
@@ -143,11 +143,7 @@ private HashMap<String, String> fetchModuleNamesWhereSameObserverNameUsed(String
143
143
continue ;
144
144
}
145
145
146
- if (indexedFileDirectory .contains (MagentoPackages .AREA_ADMINHTML )) {
147
- scope = MagentoPackages .AREA_ADMINHTML ;
148
- } else if (indexedFileDirectory .contains (MagentoPackages .AREA_FRONTEND )) {
149
- scope = MagentoPackages .AREA_FRONTEND ;
150
- }
146
+ String scope = getAreaFromFileDirectory (indexedAttributeParent );
151
147
152
148
List <XmlTag > indexObserversTags = fetchObserverTagsFromEventTag ((XmlTag ) indexedEvent .getParent ().getParent ());
153
149
for (XmlTag indexObserversTag : indexObserversTags ) {
@@ -183,7 +179,7 @@ private List<XmlTag> fetchObserverTagsFromEventTag(XmlTag eventXmlTag) {
183
179
return result ;
184
180
}
185
181
186
- private void addModuleNameWhereSameObserverUsed (HashMap <String , String > modulesName , PsiFile indexedFile , String scope ) {
182
+ private void addModuleNameWhereSameObserverUsed (List < HashMap <String , String > > modulesName , PsiFile indexedFile , String scope ) {
187
183
XmlTag moduleDeclarationTag = getModuleDeclarationTagByConfigFile (indexedFile );
188
184
if (moduleDeclarationTag == null ) return ;
189
185
@@ -195,7 +191,10 @@ private void addModuleNameWhereSameObserverUsed(HashMap<String, String> modulesN
195
191
return ;
196
192
}
197
193
198
- modulesName .put (moduleNameAttribute .getValue (), scope );
194
+ HashMap <String , String > moduleEntry = new HashMap <>();
195
+
196
+ moduleEntry .put (moduleNameAttribute .getValue (), scope );
197
+ modulesName .add (moduleEntry );
199
198
}
200
199
201
200
@ Nullable
@@ -247,6 +246,35 @@ private XmlTag[] getFileXmlTags(PsiFile file) {
247
246
XmlTag xmlRootTag = PsiTreeUtil .getChildOfType (xmlDocument , XmlTag .class );
248
247
return PsiTreeUtil .getChildrenOfType (xmlRootTag , XmlTag .class );
249
248
}
249
+
250
+ private String getAreaFromFileDirectory (@ NotNull PsiFile file ) {
251
+ if (file .getParent () == null ) {
252
+ return "" ;
253
+ }
254
+
255
+ String areaFromFileDirectory = file .getParent ().getName ();
256
+
257
+ if (areaFromFileDirectory .equals ("etc" )) {
258
+ return MagentoPackages .AREA_BASE ;
259
+ }
260
+
261
+ List <String > possibleAreas = new ArrayList <>(Arrays .asList (
262
+ MagentoPackages .AREA_ADMINHTML ,
263
+ MagentoPackages .AREA_FRONTEND ,
264
+ MagentoPackages .AREA_CRON ,
265
+ MagentoPackages .AREA_API_REST ,
266
+ MagentoPackages .AREA_API_SOAP ,
267
+ MagentoPackages .AREA_GRAPHQL
268
+ ));
269
+
270
+ for (String area : possibleAreas ) {
271
+ if (area .equals (areaFromFileDirectory )) {
272
+ return area ;
273
+ }
274
+ }
275
+
276
+ return "" ;
277
+ }
250
278
};
251
279
}
252
280
}
0 commit comments