@@ -150,9 +150,9 @@ public List<PluginData> getPluginsForClass(
150
150
}
151
151
152
152
public List <PluginMethodData > getPluginMethods (final List <PluginData > pluginDataList ) {
153
- List <PluginMethodData > result = new ArrayList <>();
153
+ final List <PluginMethodData > result = new ArrayList <>();
154
154
155
- for (PluginData pluginData : pluginDataList ) {
155
+ for (final PluginData pluginData : pluginDataList ) {
156
156
for (final PhpClass plugin : pluginData .getPhpClassCollection ()) {
157
157
//@todo add module sequence ID if sortOrder equal zero. It should be negative value.
158
158
result .addAll (getPluginMethods (plugin , pluginData .getSortOrder ()));
@@ -162,7 +162,7 @@ public List<PluginMethodData> getPluginMethods(final List<PluginData> pluginData
162
162
return result ;
163
163
}
164
164
165
- public List <PluginMethodData > getPluginMethods (final @ NotNull PhpClass pluginClass , int sortOrder ) {
165
+ public List <PluginMethodData > getPluginMethods (final @ NotNull PhpClass pluginClass , final int sortOrder ) {
166
166
final List <PluginMethodData > methodList = new ArrayList <>();
167
167
168
168
for (final Method method : pluginClass .getMethods ()) {
@@ -171,13 +171,18 @@ public List<PluginMethodData> getPluginMethods(final @NotNull PhpClass pluginCla
171
171
172
172
if (pluginMethodName .length () > MIN_PLUGIN_METHOD_NAME_LENGTH ) {
173
173
//@todo module sequence value should be set here instead of zero.
174
- methodList .add (new PluginMethodData (method , sortOrder , 0 ));
174
+ methodList .add (getPluginMethodDataObject (method , sortOrder , 0 ));
175
175
}
176
176
}
177
177
}
178
178
179
179
return methodList ;
180
180
}
181
+
182
+ @ NotNull
183
+ private PluginMethodData getPluginMethodDataObject (final Method method , final int sortOrder , final int moduleSequence ) {
184
+ return new PluginMethodData (method , sortOrder , moduleSequence );
185
+ }
181
186
}
182
187
183
188
private static class ClassPluginCollector implements Collector <PhpClass , PhpClass > {
@@ -192,10 +197,10 @@ public ClassPluginCollector(
192
197
193
198
@ Override
194
199
public List <PhpClass > collect (final @ NotNull PhpClass psiElement ) {
195
- List <PluginData > pluginDataList = pluginClassCache .getPluginsForClass (psiElement );
196
- List <PhpClass > phpClassList = new ArrayList <>();
200
+ final List <PluginData > pluginDataList = pluginClassCache .getPluginsForClass (psiElement );
201
+ final List <PhpClass > phpClassList = new ArrayList <>();
197
202
198
- for (PluginData pluginData : pluginDataList ) {
203
+ for (final PluginData pluginData : pluginDataList ) {
199
204
phpClassList .addAll (pluginData .getPhpClassCollection ());
200
205
}
201
206
@@ -207,6 +212,7 @@ private static class MethodPluginCollector implements Collector<Method, Method>
207
212
208
213
private final PluginLineMarkerProvider .PluginClassCache pluginClassCache ;
209
214
private final Map <String , Integer > pluginMethodsSortOrder ;
215
+ private static final String AFTER_PLUGIN_PREFIX = "after" ;
210
216
211
217
public MethodPluginCollector (
212
218
final PluginLineMarkerProvider .PluginClassCache pluginClassCache
@@ -215,7 +221,7 @@ public MethodPluginCollector(
215
221
pluginMethodsSortOrder = new HashMap <>();
216
222
pluginMethodsSortOrder .put ("before" , 1 );
217
223
pluginMethodsSortOrder .put ("around" , 2 );
218
- pluginMethodsSortOrder .put ("after" , 3 );
224
+ pluginMethodsSortOrder .put (AFTER_PLUGIN_PREFIX , 3 );
219
225
}
220
226
221
227
@ SuppressWarnings ("checkstyle:LineLength" )
@@ -238,13 +244,13 @@ public List<Method> collect(final @NotNull Method psiElement) {
238
244
return results ;
239
245
}
240
246
241
- @ SuppressWarnings ({"checkstyle:Indentation" , "checkstyle:OperatorWrap" , "checkstyle:LineLength" })
242
- private void sortMethods (final @ NotNull List <PluginMethodData > methodDataList , List <Method > results ) {
243
- List <Integer > bufferSortOrderList = new ArrayList <>();
247
+ @ SuppressWarnings ({"checkstyle:Indentation" , "checkstyle:OperatorWrap" , "checkstyle:LineLength" , "PMD.NPathComplexity" })
248
+ private void sortMethods (final @ NotNull List <PluginMethodData > methodDataList , final List <Method > results ) {
249
+ final List <Integer > bufferSortOrderList = new ArrayList <>();
244
250
int biggestSortOrder = 0 ;
245
251
246
- for (PluginMethodData pluginMethodData : methodDataList ) {
247
- String methodName = pluginMethodData .getMethodName ();
252
+ for (final PluginMethodData pluginMethodData : methodDataList ) {
253
+ final String methodName = pluginMethodData .getMethodName ();
248
254
249
255
if (methodName .startsWith ("around" )) {
250
256
bufferSortOrderList .add (pluginMethodData .getSortOrder ());
@@ -261,10 +267,10 @@ private void sortMethods(final @NotNull List<PluginMethodData> methodDataList, L
261
267
(PluginMethodData method1 , PluginMethodData method2 ) -> {
262
268
final String firstMethodName = method1 .getMethodName ();
263
269
final String secondMethodName = method2 .getMethodName ();
264
- final int firstIndexEnd = firstMethodName .startsWith ("after" ) ? 5 : 6 ;
265
- final int secondIndexEnd = secondMethodName .startsWith ("after" ) ? 5 : 6 ;
266
- String firstMethodPrefix = firstMethodName .substring (0 ,firstIndexEnd );
267
- String secondMethodPrefix = secondMethodName .substring (0 ,secondIndexEnd );
270
+ final int firstIndexEnd = firstMethodName .startsWith (AFTER_PLUGIN_PREFIX ) ? 5 : 6 ;
271
+ final int secondIndexEnd = secondMethodName .startsWith (AFTER_PLUGIN_PREFIX ) ? 5 : 6 ;
272
+ final String firstMethodPrefix = firstMethodName .substring (0 ,firstIndexEnd );
273
+ final String secondMethodPrefix = secondMethodName .substring (0 ,secondIndexEnd );
268
274
269
275
if (!pluginMethodsSortOrder .containsKey (firstMethodPrefix )
270
276
|| !pluginMethodsSortOrder .containsKey (secondMethodPrefix )) {
@@ -280,17 +286,17 @@ private void sortMethods(final @NotNull List<PluginMethodData> methodDataList, L
280
286
281
287
Integer firstBuffer = 0 ;
282
288
Integer secondBuffer = 0 ;
283
- Integer firstModuleSequence = (method1 .getModuleSequence () + biggestSortOrderValue ) * -1 ;
284
- Integer secondModuleSequence = (method2 .getModuleSequence () + biggestSortOrderValue ) * -1 ;
285
- Integer firstSortOrder = method1 .getSortOrder () ! = 0 ?
286
- method1 . getSortOrder () :
287
- firstModuleSequence ;
288
- Integer secondSortOrder = method2 .getSortOrder () ! = 0 ?
289
- method2 . getSortOrder () :
290
- secondModuleSequence ;
291
-
292
- if (!bufferSortOrderList .isEmpty () && firstMethodPrefix .equals ("after" )) {
293
- for (Integer bufferSortOrder : bufferSortOrderList ) {
289
+ final Integer firstModuleSequence = (method1 .getModuleSequence () + biggestSortOrderValue ) * -1 ;
290
+ final Integer secondModuleSequence = (method2 .getModuleSequence () + biggestSortOrderValue ) * -1 ;
291
+ final Integer firstSortOrder = method1 .getSortOrder () = = 0 ?
292
+ firstModuleSequence :
293
+ method1 . getSortOrder () ;
294
+ final Integer secondSortOrder = method2 .getSortOrder () = = 0 ?
295
+ secondModuleSequence :
296
+ method2 . getSortOrder () ;
297
+
298
+ if (!bufferSortOrderList .isEmpty () && firstMethodPrefix .equals (AFTER_PLUGIN_PREFIX )) {
299
+ for (final Integer bufferSortOrder : bufferSortOrderList ) {
294
300
if (bufferSortOrder < firstSortOrder && firstBuffer < bufferSortOrder + 1 ) {
295
301
firstBuffer = bufferSortOrder + 1 ;
296
302
}
@@ -316,7 +322,7 @@ private void sortMethods(final @NotNull List<PluginMethodData> methodDataList, L
316
322
}
317
323
);
318
324
319
- for (PluginMethodData pluginMethodData : methodDataList ) {
325
+ for (final PluginMethodData pluginMethodData : methodDataList ) {
320
326
results .add (pluginMethodData .getMethod ());
321
327
}
322
328
}
0 commit comments