Skip to content

Commit 7b9579a

Browse files
committed
406: test fix
1 parent 3dad734 commit 7b9579a

File tree

8 files changed

+112
-90
lines changed

8 files changed

+112
-90
lines changed

src/com/magento/idea/magento2plugin/actions/generation/PluginGenerateMethodHandlerBase.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ public boolean isValidFor(final Editor editor, final PsiFile file) {
8888
return false;
8989
}
9090
final GetTargetClassNamesByPluginClassName targetClassesService
91-
= GetTargetClassNamesByPluginClassName.getInstance(editor.getProject());
91+
= new GetTargetClassNamesByPluginClassName(editor.getProject());
9292
final String currentClass = phpClass.getFQN().substring(1);
93-
final ArrayList<String> targetClassNames = targetClassesService.execute(currentClass);
93+
final List<String> targetClassNames = targetClassesService.execute(currentClass);
9494
return !targetClassNames.isEmpty();
9595
}
9696

@@ -241,9 +241,9 @@ protected PhpNamedElementNode[] targetMethods(
241241
final TreeMap<String, PhpNamedElementNode> nodes = new TreeMap();
242242

243243
final GetTargetClassNamesByPluginClassName targetClassesService =
244-
GetTargetClassNamesByPluginClassName.getInstance(phpClass.getProject());
244+
new GetTargetClassNamesByPluginClassName(phpClass.getProject());
245245
final String currentClass = phpClass.getFQN().substring(1);
246-
final ArrayList<String> targetClassNames = targetClassesService.execute(currentClass);
246+
final List<String> targetClassNames = targetClassesService.execute(currentClass);
247247
for (final String targetClassName : targetClassNames) {
248248
final PhpClass targetClass = GetPhpClassByFQN.getInstance(
249249
phpClass.getProject()

src/com/magento/idea/magento2plugin/inspections/php/PluginInspection.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.magento.idea.magento2plugin.magento.packages.Package;
2828
import com.magento.idea.magento2plugin.util.GetPhpClassByFQN;
2929
import com.magento.idea.magento2plugin.util.magento.plugin.GetTargetClassNamesByPluginClassName;
30-
import java.util.ArrayList;
30+
import java.util.List;
3131
import org.jetbrains.annotations.NotNull;
3232

3333
@SuppressWarnings({"PMD.ExcessiveMethodLength", "PMD.NPathComplexity", "PMD.CognitiveComplexity"})
@@ -75,10 +75,8 @@ public void visitPhpMethod(final Method pluginMethod) {
7575
((PhpClass) parentClass).getNameIdentifier();
7676
final String currentClass = ((PhpClass) parentClass).getFQN().substring(1);
7777
final GetTargetClassNamesByPluginClassName targetClassesService =
78-
GetTargetClassNamesByPluginClassName.getInstance(
79-
problemsHolder.getProject()
80-
);
81-
final ArrayList<String> targetClassNames =
78+
new GetTargetClassNamesByPluginClassName(problemsHolder.getProject());
79+
final List<String> targetClassNames =
8280
targetClassesService.execute(currentClass);
8381

8482
for (final String targetClassName : targetClassNames) {

src/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java

+35-29
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ public List<PluginData> getPluginsForClass(
150150
}
151151

152152
public List<PluginMethodData> getPluginMethods(final List<PluginData> pluginDataList) {
153-
List<PluginMethodData> result = new ArrayList<>();
153+
final List<PluginMethodData> result = new ArrayList<>();
154154

155-
for (PluginData pluginData: pluginDataList) {
155+
for (final PluginData pluginData: pluginDataList) {
156156
for (final PhpClass plugin: pluginData.getPhpClassCollection()) {
157157
//@todo add module sequence ID if sortOrder equal zero. It should be negative value.
158158
result.addAll(getPluginMethods(plugin, pluginData.getSortOrder()));
@@ -162,7 +162,7 @@ public List<PluginMethodData> getPluginMethods(final List<PluginData> pluginData
162162
return result;
163163
}
164164

165-
public List<PluginMethodData> getPluginMethods(final @NotNull PhpClass pluginClass, int sortOrder) {
165+
public List<PluginMethodData> getPluginMethods(final @NotNull PhpClass pluginClass, final int sortOrder) {
166166
final List<PluginMethodData> methodList = new ArrayList<>();
167167

168168
for (final Method method : pluginClass.getMethods()) {
@@ -171,13 +171,18 @@ public List<PluginMethodData> getPluginMethods(final @NotNull PhpClass pluginCla
171171

172172
if (pluginMethodName.length() > MIN_PLUGIN_METHOD_NAME_LENGTH) {
173173
//@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));
175175
}
176176
}
177177
}
178178

179179
return methodList;
180180
}
181+
182+
@NotNull
183+
private PluginMethodData getPluginMethodDataObject(final Method method, final int sortOrder, final int moduleSequence) {
184+
return new PluginMethodData(method, sortOrder, moduleSequence);
185+
}
181186
}
182187

183188
private static class ClassPluginCollector implements Collector<PhpClass, PhpClass> {
@@ -192,10 +197,10 @@ public ClassPluginCollector(
192197

193198
@Override
194199
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<>();
197202

198-
for (PluginData pluginData: pluginDataList) {
203+
for (final PluginData pluginData: pluginDataList) {
199204
phpClassList.addAll(pluginData.getPhpClassCollection());
200205
}
201206

@@ -207,6 +212,7 @@ private static class MethodPluginCollector implements Collector<Method, Method>
207212

208213
private final PluginLineMarkerProvider.PluginClassCache pluginClassCache;
209214
private final Map<String, Integer> pluginMethodsSortOrder;
215+
private static final String AFTER_PLUGIN_PREFIX = "after";
210216

211217
public MethodPluginCollector(
212218
final PluginLineMarkerProvider.PluginClassCache pluginClassCache
@@ -215,7 +221,7 @@ public MethodPluginCollector(
215221
pluginMethodsSortOrder = new HashMap<>();
216222
pluginMethodsSortOrder.put("before", 1);
217223
pluginMethodsSortOrder.put("around", 2);
218-
pluginMethodsSortOrder.put("after", 3);
224+
pluginMethodsSortOrder.put(AFTER_PLUGIN_PREFIX, 3);
219225
}
220226

221227
@SuppressWarnings("checkstyle:LineLength")
@@ -238,13 +244,13 @@ public List<Method> collect(final @NotNull Method psiElement) {
238244
return results;
239245
}
240246

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<>();
244250
int biggestSortOrder = 0;
245251

246-
for (PluginMethodData pluginMethodData: methodDataList) {
247-
String methodName = pluginMethodData.getMethodName();
252+
for (final PluginMethodData pluginMethodData: methodDataList) {
253+
final String methodName = pluginMethodData.getMethodName();
248254

249255
if (methodName.startsWith("around")) {
250256
bufferSortOrderList.add(pluginMethodData.getSortOrder());
@@ -261,10 +267,10 @@ private void sortMethods(final @NotNull List<PluginMethodData> methodDataList, L
261267
(PluginMethodData method1, PluginMethodData method2) -> {
262268
final String firstMethodName = method1.getMethodName();
263269
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);
268274

269275
if (!pluginMethodsSortOrder.containsKey(firstMethodPrefix)
270276
|| !pluginMethodsSortOrder.containsKey(secondMethodPrefix)) {
@@ -280,17 +286,17 @@ private void sortMethods(final @NotNull List<PluginMethodData> methodDataList, L
280286

281287
Integer firstBuffer = 0;
282288
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) {
294300
if (bufferSortOrder < firstSortOrder && firstBuffer < bufferSortOrder + 1) {
295301
firstBuffer = bufferSortOrder + 1;
296302
}
@@ -316,7 +322,7 @@ private void sortMethods(final @NotNull List<PluginMethodData> methodDataList, L
316322
}
317323
);
318324

319-
for (PluginMethodData pluginMethodData: methodDataList) {
325+
for (final PluginMethodData pluginMethodData: methodDataList) {
320326
results.add(pluginMethodData.getMethod());
321327
}
322328
}

src/com/magento/idea/magento2plugin/linemarker/php/PluginTargetLineMarkerProvider.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ private List<PhpClass> getTargetClassesForPlugin(
9797
}
9898

9999
final GetTargetClassNamesByPluginClassName targetClassesService =
100-
GetTargetClassNamesByPluginClassName.getInstance(phpClass.getProject());
101-
final ArrayList<String> targetClassNames = targetClassesService.execute(classFQN);
100+
new GetTargetClassNamesByPluginClassName(phpClass.getProject());
101+
final List<String> targetClassNames = targetClassesService.execute(classFQN);
102102

103103
final List<PhpClass> results = new ArrayList<>();
104104

src/com/magento/idea/magento2plugin/stubs/indexes/PluginIndex.java

+34-22
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
import com.intellij.psi.xml.XmlDocument;
1212
import com.intellij.psi.xml.XmlFile;
1313
import com.intellij.psi.xml.XmlTag;
14-
import com.intellij.util.indexing.*;
14+
import com.intellij.util.indexing.DataIndexer;
15+
import com.intellij.util.indexing.FileBasedIndex;
16+
import com.intellij.util.indexing.FileBasedIndexExtension;
17+
import com.intellij.util.indexing.FileContent;
18+
import com.intellij.util.indexing.ID;
1519
import com.intellij.util.io.DataExternalizer;
1620
import com.intellij.util.io.EnumeratorStringDescriptor;
1721
import com.intellij.util.io.KeyDescriptor;
@@ -39,64 +43,72 @@ public ID<String, Set<PluginData>> getName() {
3943

4044
@NotNull
4145
@Override
46+
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
4247
public DataIndexer<String, Set<PluginData>, FileContent> getIndexer() {
4348
return new DataIndexer<>() {
49+
@SuppressWarnings("checkstyle:LineLength")
4450
@NotNull
4551
@Override
46-
public Map<String, Set<PluginData>> map(@NotNull FileContent fileContent) {
47-
Map<String, Set<PluginData>> map = new HashMap<>();
52+
public Map<String, Set<PluginData>> map(final @NotNull FileContent fileContent) {
53+
final Map<String, Set<PluginData>> map = new HashMap<>();
4854

49-
PsiFile psiFile = fileContent.getPsiFile();
55+
final PsiFile psiFile = fileContent.getPsiFile();
5056
if (!Settings.isEnabled(psiFile.getProject())) {
5157
return map;
5258
}
5359

5460
if (!(psiFile instanceof XmlFile)) {
5561
return map;
5662
}
57-
XmlDocument document = ((XmlFile) psiFile).getDocument();
58-
if(document == null) {
63+
final XmlDocument document = ((XmlFile) psiFile).getDocument();
64+
if (document == null) {
5965
return map;
6066
}
6167

62-
XmlTag xmlTags[] = PsiTreeUtil.getChildrenOfType(psiFile.getFirstChild(), XmlTag.class);
68+
final XmlTag[] xmlTags = PsiTreeUtil.getChildrenOfType(psiFile.getFirstChild(), XmlTag.class);
6369
if (xmlTags == null) {
6470
return map;
6571
}
6672

67-
for (XmlTag xmlTag: xmlTags) {
73+
for (final XmlTag xmlTag: xmlTags) {
6874
if (xmlTag.getName().equals("config")) {
69-
for (XmlTag typeNode: xmlTag.findSubTags("type")) {
70-
String typeName = typeNode.getAttributeValue("name");
71-
if (typeName != null) {
72-
Set<PluginData> plugins = getPluginsForType(typeNode);
73-
if (plugins.size() > 0) {
74-
map.put(PhpLangUtil.toPresentableFQN(typeName), plugins);
75-
}
75+
for (final XmlTag typeNode: xmlTag.findSubTags("type")) {
76+
final String typeName = typeNode.getAttributeValue("name");
77+
final Set<PluginData> plugins = getPluginsForType(typeNode);
78+
79+
if (typeName == null || plugins.isEmpty()) {
80+
continue;
7681
}
82+
83+
map.put(PhpLangUtil.toPresentableFQN(typeName), plugins);
7784
}
7885
}
7986
}
8087

8188
return map;
8289
}
8390

84-
private Set<PluginData> getPluginsForType(XmlTag typeNode) {
85-
Set<PluginData> results = new HashSet<>();
91+
@SuppressWarnings("checkstyle:LineLength")
92+
private Set<PluginData> getPluginsForType(final XmlTag typeNode) {
93+
final Set<PluginData> results = new HashSet<>();
8694

87-
for (XmlTag pluginTag: typeNode.findSubTags(ModuleDiXml.PLUGIN_TAG_NAME)) {
88-
String pluginType = pluginTag.getAttributeValue(ModuleDiXml.TYPE_ATTR);
95+
for (final XmlTag pluginTag: typeNode.findSubTags(ModuleDiXml.PLUGIN_TAG_NAME)) {
96+
final String pluginType = pluginTag.getAttributeValue(ModuleDiXml.TYPE_ATTR);
8997
String pluginSortOrder = pluginTag.getAttributeValue(ModuleDiXml.SORT_ORDER_ATTR);
9098

9199
if (pluginType != null) {
92100
pluginSortOrder = pluginSortOrder == null ? "0" : pluginSortOrder;
93-
PluginData pluginData = new PluginData(pluginType, Integer.parseInt(pluginSortOrder));
101+
final PluginData pluginData = getPluginDataObject(pluginType, Integer.parseInt(pluginSortOrder));
94102
results.add(pluginData);
95103
}
96104
}
97105

98106
return results;
99107
}
108+
109+
private PluginData getPluginDataObject(final String pluginType, final Integer sortOrder) {
110+
return new PluginData(pluginType, sortOrder);
111+
}
100112
};
101113
}
102114

@@ -114,9 +126,9 @@ public DataExternalizer<Set<PluginData>> getValueExternalizer() {
114126

115127
@NotNull
116128
@Override
129+
@SuppressWarnings("checkstyle:LineLength")
117130
public FileBasedIndex.InputFilter getInputFilter() {
118-
return virtualFile -> (virtualFile.getFileType() == XmlFileType.INSTANCE
119-
&& virtualFile.getNameWithoutExtension().equals("di"));
131+
return virtualFile -> virtualFile.getFileType().equals(XmlFileType.INSTANCE) && "di".equals(virtualFile.getNameWithoutExtension());
120132
}
121133

122134
@Override

src/com/magento/idea/magento2plugin/stubs/indexes/data/PluginData.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public Collection<PhpClass> getPhpClassCollection() {
4848
*
4949
* @param phpClass collection PHP plugin class
5050
*/
51-
public void setPhpClass(@NotNull PhpClass phpClass) {
51+
public void setPhpClass(final @NotNull PhpClass phpClass) {
5252
final PhpIndex phpIndex = PhpIndex.getInstance(phpClass.getProject());
5353

5454
phpClassCollection = phpIndex.getClassesByFQN(getType());

src/com/magento/idea/magento2plugin/stubs/indexes/data/PluginSetDataExternalizer.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,30 @@
1616
public class PluginSetDataExternalizer implements DataExternalizer<Set<PluginData>> {
1717
public static final PluginSetDataExternalizer INSTANCE = new PluginSetDataExternalizer();
1818

19-
public PluginSetDataExternalizer() {
20-
}
21-
19+
@SuppressWarnings("checkstyle:LineLength")
2220
@Override
23-
public synchronized void save(@NotNull DataOutput out, Set<PluginData> value) throws IOException {
21+
public void save(final @NotNull DataOutput out, final Set<PluginData> value) throws IOException {
2422
out.writeInt(value.size());
2523

26-
for (PluginData plugin : value) {
24+
for (final PluginData plugin : value) {
2725
out.writeUTF(plugin.getType());
2826
out.writeInt(plugin.getSortOrder());
2927
}
3028
}
3129

3230
@Override
33-
public synchronized Set<PluginData> read(@NotNull DataInput in) throws IOException {
34-
int size = in.readInt();
35-
HashSet<PluginData> result = new HashSet<>(size);
31+
public Set<PluginData> read(final @NotNull DataInput income) throws IOException {
32+
final int size = income.readInt();
33+
final HashSet<PluginData> result = new HashSet<>(size);
3634

3735
for (int r = size; r > 0; --r) {
38-
PluginData pluginData = new PluginData(in.readUTF(), in.readInt());
39-
result.add(pluginData);
36+
result.add(getPluginDataObject(income.readUTF(), income.readInt()));
4037
}
4138

4239
return result;
4340
}
41+
42+
private PluginData getPluginDataObject(final String pluginType, final Integer sortOrder) {
43+
return new PluginData(pluginType, sortOrder);
44+
}
4445
}

0 commit comments

Comments
 (0)