Skip to content

Commit 83822f4

Browse files
author
Vitaliy Boyko
committed
Merge branch '1.0.1-develop' of https://github.com/magento/magento2-phpstorm-plugin into 184-setup-code-style-checks
2 parents 452e4e3 + 99a277d commit 83822f4

File tree

55 files changed

+1024
-107
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1024
-107
lines changed

.github/workflows/gradlepublishalpha.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: Publish Plugin alpha version
55
on:
66
push:
77
branches:
8-
- 1.0.1-develop
8+
- master
99

1010
jobs:
1111
build:
@@ -23,7 +23,6 @@ jobs:
2323
- name: Grant execute permission for gradlew
2424
run: chmod +x gradlew
2525
- name: Run publish plugin
26-
if: contains(github.event.pull_request.labels.*.name, 'deploy-alpha')
2726
run: ./gradlew publishPlugin -i
2827
env:
2928
MAGENTO_PHPSTORM_intellijPublishToken: ${{ secrets.JET_BRAINS_TOKEN }}

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,20 @@ public void update(AnActionEvent event) {
4444
Pair<PsiFile, PhpClass> pair = this.findPhpClass(event);
4545
PsiFile psiFile = pair.getFirst();
4646
PhpClass phpClass = pair.getSecond();
47-
if (phpClass == null || psiFile == null) {
48-
return;
49-
}
50-
targetClass = phpClass;
51-
if (!(psiFile instanceof PhpFile) || phpClass.isFinal() || this.targetMethod == null) {
47+
if ((phpClass == null || psiFile == null)
48+
|| !(psiFile instanceof PhpFile)
49+
|| phpClass.isFinal()
50+
|| this.targetMethod == null
51+
) {
5252
this.setStatus(event, false);
5353
return;
5454
}
55-
} else {
56-
this.setStatus(event, false);
55+
targetClass = phpClass;
56+
this.setStatus(event, true);
5757
return;
5858
}
59-
this.setStatus(event, true);
59+
60+
this.setStatus(event, false);
6061
}
6162

6263
private void setStatus(AnActionEvent event, boolean status) {

src/com/magento/idea/magento2plugin/actions/generation/data/ObserverFileData.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
15
package com.magento.idea.magento2plugin.actions.generation.data;
26

37
public class ObserverFileData {
@@ -13,14 +17,14 @@ public ObserverFileData(
1317
String observerClassName,
1418
String observerModule,
1519
String targetEvent,
16-
String pluginClassFqn,
20+
String observerClassFqn,
1721
String namespace
1822
) {
1923
this.observerDirectory = observerDirectory;
2024
this.observerClassName = observerClassName;
2125
this.observerModule = observerModule;
2226
this.targetEvent = targetEvent;
23-
this.observerClassFqn = pluginClassFqn;
27+
this.observerClassFqn = observerClassFqn;
2428
this.namespace = namespace;
2529
}
2630

src/com/magento/idea/magento2plugin/completion/xml/XmlCompletionContributor.java

+23-6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ public XmlCompletionContributor() {
7676
new FilePathCompletionProvider()
7777
);
7878

79+
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_DATA_CHARACTERS)
80+
.withParent(XmlPatterns.xmlText().withParent(
81+
XmlPatterns.xmlTag().withName(UiComponentXml.XML_TAG_ITEM).withChild(
82+
XmlPatterns.xmlAttribute().withValue(string()
83+
.matches(UiComponentXml.XML_ATTRIBUTE_TEMPLATE))
84+
))
85+
),
86+
new FilePathCompletionProvider()
87+
);
88+
7989
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
8090
.inside(XmlPatterns.xmlAttribute().withName("type")),
8191
new VirtualTypeCompletionProvider()
@@ -198,21 +208,28 @@ public XmlCompletionContributor() {
198208

199209
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
200210
.inside(XmlPatterns.xmlAttributeValue().withParent(
201-
XmlPatterns.xmlAttribute().withName("component")
211+
XmlPatterns.xmlAttribute().withName(UiComponentXml.XML_ATTRIBUTE_COMPONENT)
202212
)),
203-
new RequireJsMappingCompletionProvider()
213+
new CompositeCompletionProvider(
214+
new RequireJsMappingCompletionProvider(),
215+
new FilePathCompletionProvider()
216+
)
204217
);
205218

206219
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_DATA_CHARACTERS)
207220
.withParent(XmlPatterns.xmlText().withParent(
208-
XmlPatterns.xmlTag().withName("item").withChild(
209-
XmlPatterns.xmlAttribute().withValue(string().matches("component"))
221+
XmlPatterns.xmlTag().withName(UiComponentXml.XML_TAG_ITEM).withChild(
222+
XmlPatterns.xmlAttribute().withValue(string()
223+
.matches(UiComponentXml.XML_ATTRIBUTE_COMPONENT))
210224
).withChild(
211-
XmlPatterns.xmlAttribute().withName("name")
225+
XmlPatterns.xmlAttribute().withName(UiComponentXml.XML_ATTRIBUTE_NAME)
212226
)
213227
)
214228
),
215-
new RequireJsMappingCompletionProvider()
229+
new CompositeCompletionProvider(
230+
new RequireJsMappingCompletionProvider(),
231+
new FilePathCompletionProvider()
232+
)
216233
);
217234

218235
// mftf action group completion contributor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
package com.magento.idea.magento2plugin.magento.files;
6+
7+
public class UiComponentXml {
8+
public static String XML_ATTRIBUTE_TEMPLATE = "template";
9+
public static String XML_ATTRIBUTE_COMPONENT = "component";
10+
public static String XML_TAG_ITEM = "item";
11+
public static String XML_ATTRIBUTE_NAME = "name";
12+
}

src/com/magento/idea/magento2plugin/magento/packages/Package.java

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
public class Package {
88
public static String PACKAGES_ROOT = "app/code";
9+
public static String LIB_WEB_ROOT = "lib/web";
910
public static String APP = "app";
1011
public static String VENDOR = "vendor";
1112
public static String MODULE_BASE_AREA_DIR = "etc";

src/com/magento/idea/magento2plugin/reference/xml/XmlReferenceContributor.java

+29-14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.intellij.psi.xml.XmlTokenType;
1111
import com.magento.idea.magento2plugin.magento.files.MftfActionGroup;
1212
import com.magento.idea.magento2plugin.magento.files.MftfTest;
13+
import com.magento.idea.magento2plugin.magento.files.UiComponentXml;
1314
import com.magento.idea.magento2plugin.reference.provider.*;
1415
import com.magento.idea.magento2plugin.reference.provider.mftf.*;
1516
import com.magento.idea.magento2plugin.util.RegExUtil;
@@ -226,24 +227,38 @@ public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar)
226227

227228
// <someXmlTag component="requireJsMappingKey" />
228229
registrar.registerReferenceProvider(
229-
XmlPatterns.xmlAttributeValue().withParent(
230-
XmlPatterns.xmlAttribute().withName("component")
231-
),
232-
new RequireJsPreferenceReferenceProvider()
230+
XmlPatterns.xmlAttributeValue().withParent(
231+
XmlPatterns.xmlAttribute().withName(UiComponentXml.XML_ATTRIBUTE_COMPONENT)
232+
),
233+
new RequireJsPreferenceReferenceProvider()
233234
);
234235

235236
// <item name="component">requireJsMappingKey</item>
236237
registrar.registerReferenceProvider(
237-
XmlPatterns.psiElement(XmlTokenType.XML_DATA_CHARACTERS).withParent(
238-
XmlPatterns.xmlText().withParent(
239-
XmlPatterns.xmlTag().withName("item").withChild(
240-
XmlPatterns.xmlAttribute().withValue(string().matches("component"))
241-
).withChild(
242-
XmlPatterns.xmlAttribute().withName("name")
243-
)
244-
)
245-
),
246-
new RequireJsPreferenceReferenceProvider()
238+
XmlPatterns.psiElement(XmlTokenType.XML_DATA_CHARACTERS).withParent(
239+
XmlPatterns.xmlText().withParent(
240+
XmlPatterns.xmlTag().withName(UiComponentXml.XML_TAG_ITEM).withChild(
241+
XmlPatterns.xmlAttribute().withValue(string().matches(UiComponentXml.XML_ATTRIBUTE_COMPONENT))
242+
).withChild(
243+
XmlPatterns.xmlAttribute().withName(UiComponentXml.XML_ATTRIBUTE_NAME)
244+
)
245+
)
246+
),
247+
new RequireJsPreferenceReferenceProvider()
248+
);
249+
250+
// <item name="template">reference</item>
251+
registrar.registerReferenceProvider(
252+
XmlPatterns.psiElement(XmlTokenType.XML_DATA_CHARACTERS).withParent(
253+
XmlPatterns.xmlText().withParent(
254+
XmlPatterns.xmlTag().withName(UiComponentXml.XML_TAG_ITEM).withChild(
255+
XmlPatterns.xmlAttribute().withValue(string().matches(UiComponentXml.XML_ATTRIBUTE_TEMPLATE))
256+
).withChild(
257+
XmlPatterns.xmlAttribute().withName(UiComponentXml.XML_ATTRIBUTE_NAME)
258+
)
259+
)
260+
),
261+
new FilePathReferenceProvider()
247262
);
248263

249264
registerReferenceForDifferentNesting(registrar);

src/com/magento/idea/magento2plugin/stubs/indexes/js/MagentoLibJsIndex.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import com.intellij.util.indexing.*;
1010
import com.intellij.util.io.EnumeratorStringDescriptor;
1111
import com.intellij.util.io.KeyDescriptor;
12+
import com.magento.idea.magento2plugin.magento.packages.File;
13+
import com.magento.idea.magento2plugin.magento.packages.Package;
14+
import com.magento.idea.magento2plugin.project.Settings;
1215
import org.jetbrains.annotations.NotNull;
1316

1417
import java.util.HashMap;
@@ -29,7 +32,8 @@ public ID<String, Void> getName() {
2932
public DataIndexer<String, Void, FileContent> getIndexer() {
3033
return inputData -> {
3134
Map<String, Void> map = new HashMap<>();
32-
String libPath = inputData.getProject().getBasePath() + "/lib/web/";
35+
String libPath = Settings.getMagentoPath(inputData.getProject()) +
36+
File.separator + Package.LIB_WEB_ROOT + File.separator;
3337
VirtualFile file = inputData.getFile();
3438

3539
if (!file.getPath().contains(libPath)){
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
4+
namespace Foo\Bar\Observer;
5+
6+
use Magento\Framework\Event\ObserverInterface;
7+
use Magento\Framework\Event\Observer;
8+
9+
class TestObserver implements ObserverInterface
10+
{
11+
/**
12+
* Observer for test_event
13+
*
14+
* @param Observer $observer
15+
* @return void
16+
*/
17+
public function execute(Observer $observer)
18+
{
19+
$event = $observer->getEvent();
20+
// TODO: Implement observer method.
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
4+
<event name="test_event">
5+
<observer name="test_observer" instance="Foo\Bar\Observer\Test\TestEventObserver"/>
6+
</event>
7+
<event name="test_event_2">
8+
<observer name="test_observer_2" instance="Foo\Bar\Observer\Test\TestEventObserverTwo"/>
9+
</event>
10+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
4+
<event name="test_event">
5+
<observer name="test_observer" instance="Foo\Bar\Observer\Test\TestEventObserver"/>
6+
</event>
7+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
4+
<event name="test_event">
5+
<observer name="test_observer" instance="Foo\Bar\Observer\Test\TestEventObserver"/>
6+
</event>
7+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
4+
namespace Foo\Bar\Plugin;
5+
6+
7+
use Foo\Bar\Service\SimpleService;
8+
9+
class TestPlugin
10+
{
11+
12+
/**
13+
* @param \Foo\Bar\Service\SimpleService $subject
14+
* @param int $param1
15+
* @param string $param2
16+
* @return array
17+
*/
18+
public function beforeExecute(\Foo\Bar\Service\SimpleService $subject, int $param1, string $param2)
19+
{
20+
// TODO: Implement plugin method.
21+
return [$param1, $param2];
22+
}
23+
24+
/**
25+
* @param \Foo\Bar\Service\SimpleService $subject
26+
* @param callable $proceed
27+
* @param int $param1
28+
* @param string $param2
29+
*/
30+
public function aroundExecute(\Foo\Bar\Service\SimpleService $subject, callable $proceed, int $param1, string $param2)
31+
{
32+
// TODO: Implement plugin method.
33+
return $proceed($param1, $param2);
34+
}
35+
36+
/**
37+
* @param \Foo\Bar\Service\SimpleService $subject
38+
* @param $result
39+
* @param int $param1
40+
* @param string $param2
41+
*/
42+
public function afterExecute(\Foo\Bar\Service\SimpleService $subject, $result, int $param1, string $param2)
43+
{
44+
// TODO: Implement plugin method.
45+
return $result;
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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" sortOrder="10"/>
7+
</type>
8+
<type name="Foo\Bar\Model\PluginTargetClassTwo">
9+
<plugin name="test_plugin_name_2"
10+
type="Foo\Bar\Plugin\TestTwoPlugin" sortOrder="20"/>
11+
</type>
12+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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" sortOrder="10"/>
7+
<plugin name="test_plugin_name_2"
8+
type="Foo\Bar\Plugin\TestTwoPlugin" sortOrder="20"/>
9+
</type>
10+
</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\PluginTargetClassTwo">
5+
<plugin name="test_plugin_name_2"
6+
type="Foo\Bar\Plugin\TestTwoPlugin" sortOrder="20"/>
7+
</type>
8+
</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" sortOrder="10"/>
7+
</type>
8+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
4+
<fieldset name="general" >
5+
<field name="test_field" component="Foo_Bar/js/fi<caret>">
6+
</field>
7+
</fieldset>
8+
</form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
4+
<dataSource name="test_source">
5+
<argument name="data" xsi:type="array">
6+
<item name="js_config" xsi:type="array">
7+
<item name="component" xsi:type="string">Foo_Bar/js/fi<caret></item>
8+
</item>
9+
</argument>
10+
</dataSource>
11+
</form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
4+
<fieldset name="general" >
5+
<field name="test_field" component="testF<caret>">
6+
</field>
7+
</fieldset>
8+
</form>

0 commit comments

Comments
 (0)