Skip to content

Commit 12c722f

Browse files
authored
Merge branch '2.1.0-develop' into tests-06
2 parents 9c1b01b + 9046134 commit 12c722f

File tree

16 files changed

+163
-38
lines changed

16 files changed

+163
-38
lines changed

resources/fileTemplates/code/Magento Module DI Xml Plugin.xml.ft

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
<type name="${TYPE}">
33
#end
44
<plugin name="${NAME}"
5-
type="${PLUGIN_TYPE}" sortOrder="${SORT_ORDER}" />
5+
#if (${SORT_ORDER})
6+
type="${PLUGIN_TYPE}"
7+
sortOrder="${SORT_ORDER}" />
8+
#else
9+
type="${PLUGIN_TYPE}" />
10+
#end
611
#if (${TYPE})
712
</type>
813
#end

src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.form

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131
</grid>
132132
</constraints>
133133
<properties>
134-
<text value="10"/>
135134
<toolTipText value="Plugin sort order in di.xml"/>
136135
</properties>
137136
<clientProperties>

src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ public class CreateAPluginDialog extends AbstractDialog {
8282
message = {DirectoryRule.MESSAGE, DIRECTORY})
8383
private JTextField pluginDirectory;
8484

85-
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
86-
message = {NotEmptyRule.MESSAGE, SORT_ORDER})
8785
@FieldValidation(rule = RuleRegistry.NUMERIC,
8886
message = {NumericRule.MESSAGE, SORT_ORDER})
8987
private JTextField pluginSortOrder;

src/com/magento/idea/magento2plugin/actions/generation/generator/PluginDiXmlGenerator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ protected void fillAttributes(final Properties attributes) {
161161
attributes.setProperty("NAME", pluginFileData.getPluginName());
162162
attributes.setProperty("PLUGIN_TYPE", pluginFileData.getPluginFqn());
163163
attributes.setProperty("PLUGIN_NAME", pluginFileData.getPluginName());
164-
attributes.setProperty("SORT_ORDER", pluginFileData.getSortOrder());
164+
final String sortOrder = pluginFileData.getSortOrder();
165+
if (!sortOrder.isEmpty()) {
166+
attributes.setProperty("SORT_ORDER", sortOrder);
167+
}
165168
}
166169
}

src/com/magento/idea/magento2plugin/reference/provider/EventNameReferenceProvider.java

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.reference.provider;
67

78
import com.intellij.openapi.util.text.StringUtil;
@@ -15,52 +16,63 @@
1516
import com.intellij.util.indexing.FileBasedIndex;
1617
import com.jetbrains.php.lang.PhpFileType;
1718
import com.jetbrains.php.lang.psi.PhpFile;
18-
import com.magento.idea.magento2plugin.util.php.PhpPatternsHelper;
1919
import com.magento.idea.magento2plugin.reference.xml.PolyVariantReferenceBase;
2020
import com.magento.idea.magento2plugin.stubs.indexes.EventNameIndex;
21-
import org.jetbrains.annotations.NotNull;
22-
21+
import com.magento.idea.magento2plugin.util.php.PhpPatternsHelper;
2322
import java.util.ArrayList;
2423
import java.util.Collection;
2524
import java.util.List;
25+
import org.jetbrains.annotations.NotNull;
2626

2727
public class EventNameReferenceProvider extends PsiReferenceProvider {
2828

2929
@NotNull
3030
@Override
31-
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
32-
String value = StringUtil.unquoteString(element.getText());
33-
Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance()
34-
.getContainingFiles(EventNameIndex.KEY, value,
35-
GlobalSearchScope.getScopeRestrictedByFileTypes(
36-
GlobalSearchScope.allScope(element.getProject()),
37-
PhpFileType.INSTANCE
38-
)
39-
);
31+
public PsiReference[] getReferencesByElement(
32+
@NotNull final PsiElement element,
33+
@NotNull final ProcessingContext context
34+
) {
35+
final String value = StringUtil.unquoteString(element.getText());
36+
final List<PsiReference> psiReferences = new ArrayList<>();
37+
final Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance()
38+
.getContainingFiles(
39+
EventNameIndex.KEY,
40+
value,
41+
GlobalSearchScope.getScopeRestrictedByFileTypes(
42+
GlobalSearchScope.allScope(element.getProject()),
43+
PhpFileType.INSTANCE
44+
)
45+
);
4046

41-
PsiManager psiManager = PsiManager.getInstance(element.getProject());
42-
for (VirtualFile virtualFile: containingFiles) {
43-
PhpFile phpFile = (PhpFile) psiManager.findFile(virtualFile);
47+
final PsiManager psiManager = PsiManager.getInstance(element.getProject());
48+
final List<PsiElement> psiElements = new ArrayList<>();
49+
for (final VirtualFile virtualFile: containingFiles) {
50+
final PhpFile phpFile = (PhpFile) psiManager.findFile(virtualFile);
4451
if (phpFile != null) {
45-
List<PsiElement> psiElements = new ArrayList<>();
4652
recursiveFill(psiElements, phpFile, value);
47-
if (psiElements.size() > 0) {
48-
return new PsiReference[] {new PolyVariantReferenceBase(element, psiElements)};
53+
if (!psiElements.isEmpty()) {
54+
psiReferences.add(new PolyVariantReferenceBase(element, psiElements));//NOPMD
55+
break;
4956
}
5057
}
5158
}
52-
return PsiReference.EMPTY_ARRAY;
59+
60+
return psiReferences.toArray(new PsiReference[0]);
5361
}
5462

55-
private void recursiveFill(List<PsiElement> psiElements, PsiElement psiElement, String typeName) {
63+
private void recursiveFill(
64+
final List<PsiElement> psiElements,
65+
final PsiElement psiElement,
66+
final String typeName
67+
) {
5668
if (PhpPatternsHelper.STRING_METHOD_ARGUMENT.accepts(psiElement)) {
5769
if (StringUtil.unquoteString(psiElement.getText()).equals(typeName)) {
5870
psiElements.add(psiElement);
5971
}
6072
return;
6173
}
6274

63-
for (PsiElement child: psiElement.getChildren()) {
75+
for (final PsiElement child: psiElement.getChildren()) {
6476
recursiveFill(psiElements, child, typeName);
6577
}
6678
}

testData/actions/generation/generator/PluginDiXmlGenerator/addTwoPluginsToOneDiXml/di.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
44
<type name="Foo\Bar\Model\PluginTargetClassOne">
55
<plugin name="test_plugin_name_1"
6-
type="Foo\Bar\Plugin\TestOnePlugin" sortOrder="10"/>
6+
type="Foo\Bar\Plugin\TestOnePlugin"
7+
sortOrder="10"/>
78
</type>
89
<type name="Foo\Bar\Model\PluginTargetClassTwo">
910
<plugin name="test_plugin_name_2"
10-
type="Foo\Bar\Plugin\TestTwoPlugin" sortOrder="20"/>
11+
type="Foo\Bar\Plugin\TestTwoPlugin"
12+
sortOrder="20"/>
1113
</type>
1214
</config>

testData/actions/generation/generator/PluginDiXmlGenerator/addTwoPluginsToOneTargetClass/di.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
44
<type name="Foo\Bar\Model\PluginTargetClassOne">
55
<plugin name="test_plugin_name_1"
6-
type="Foo\Bar\Plugin\TestOnePlugin" sortOrder="10"/>
6+
type="Foo\Bar\Plugin\TestOnePlugin"
7+
sortOrder="10"/>
78
<plugin name="test_plugin_name_2"
8-
type="Foo\Bar\Plugin\TestTwoPlugin" sortOrder="20"/>
9+
type="Foo\Bar\Plugin\TestTwoPlugin"
10+
sortOrder="20"/>
911
</type>
1012
</config>

testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileForAdminhtmlArea/di.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
44
<type name="Foo\Bar\Model\PluginTargetClassTwo">
55
<plugin name="test_plugin_name_2"
6-
type="Foo\Bar\Plugin\TestTwoPlugin" sortOrder="20"/>
6+
type="Foo\Bar\Plugin\TestTwoPlugin"
7+
sortOrder="20"/>
78
</type>
89
</config>

testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileForBaseArea/di.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
44
<type name="Foo\Bar\Model\PluginTargetClassOne">
55
<plugin name="test_plugin_name_1"
6-
type="Foo\Bar\Plugin\TestOnePlugin" sortOrder="10"/>
6+
type="Foo\Bar\Plugin\TestOnePlugin"
7+
sortOrder="10"/>
78
</type>
89
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
4+
<type name="Foo\Bar\Model\PluginTargetClassOne">
5+
<plugin name="test_plugin_name_1"
6+
type="Foo\Bar\Plugin\TestOnePlugin"/>
7+
</type>
8+
</config>

0 commit comments

Comments
 (0)