Skip to content

Commit 26f7c1c

Browse files
author
Vitaliy
authored
Merge branch '2.1.0-develop' into feature/issue-179
2 parents 1c93c88 + 09b3683 commit 26f7c1c

File tree

37 files changed

+1567
-99
lines changed

37 files changed

+1567
-99
lines changed

resources/META-INF/plugin.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<idea-plugin>
88
<id>com.magento.idea.magento2plugin</id>
99
<name>Magento PhpStorm</name>
10-
<version>2.0.1</version>
10+
<version>2.1.0</version>
1111
<vendor url="https://github.com/magento/magento2-phpstorm-plugin">Magento Inc.</vendor>
1212

1313
<description><![CDATA[
@@ -126,6 +126,8 @@
126126
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.js.MagentoLibJsIndex" />
127127
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.AclResourceIndex" />
128128
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.MenuIndex" />
129+
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.DeclarativeSchemaElementsIndex" />
130+
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.UIComponentIndex" />
129131

130132
<codeInsight.lineMarkerProvider language="PHP" implementationClass="com.magento.idea.magento2plugin.linemarker.php.PluginLineMarkerProvider"/>
131133
<codeInsight.lineMarkerProvider language="PHP" implementationClass="com.magento.idea.magento2plugin.linemarker.php.PluginTargetLineMarkerProvider"/>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.magento.idea.magento2plugin.actions.generation.data.PluginFileData;
1414
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
1515
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
16+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.BoxNotEmptyRule;
1617
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule;
1718
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierRule;
1819
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
@@ -65,6 +66,8 @@ public class CreateAPluginDialog extends AbstractDialog {
6566

6667
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
6768
message = {NotEmptyRule.MESSAGE, TARGET_MODULE})
69+
@FieldValidation(rule = RuleRegistry.BOX_NOT_EMPTY,
70+
message = {BoxNotEmptyRule.MESSAGE, TARGET_MODULE})
6871
private FilteredComboBox pluginModule;
6972

7073
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
1414
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
1515
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphanumericWithUnderscoreRule;
16+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.BoxNotEmptyRule;
1617
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule;
1718
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
1819
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule;
@@ -63,6 +64,8 @@ public class CreateAnObserverDialog extends AbstractDialog {
6364

6465
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
6566
message = {NotEmptyRule.MESSAGE, OBSERVER_MODULE})
67+
@FieldValidation(rule = RuleRegistry.BOX_NOT_EMPTY,
68+
message = {BoxNotEmptyRule.MESSAGE, OBSERVER_MODULE})
6669
private FilteredComboBox observerModule;
6770

6871
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.magento.idea.magento2plugin.actions.generation.data.PreferenceFileData;
1515
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
1616
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.BoxNotEmptyRule;
1718
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule;
1819
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
1920
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule;
@@ -65,6 +66,8 @@ public class OverrideClassByAPreferenceDialog extends AbstractDialog { //NOPMD
6566

6667
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
6768
message = {NotEmptyRule.MESSAGE, MODULE})
69+
@FieldValidation(rule = RuleRegistry.BOX_NOT_EMPTY,
70+
message = {BoxNotEmptyRule.MESSAGE, MODULE})
6871
private FilteredComboBox preferenceModule;
6972

7073
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.completion.provider;
7+
8+
import com.intellij.codeInsight.completion.CompletionParameters;
9+
import com.intellij.codeInsight.completion.CompletionProvider;
10+
import com.intellij.codeInsight.completion.CompletionResultSet;
11+
import com.intellij.codeInsight.lookup.LookupElementBuilder;
12+
import com.intellij.psi.PsiElement;
13+
import com.intellij.psi.impl.source.xml.XmlAttributeImpl;
14+
import com.intellij.psi.impl.source.xml.XmlTagImpl;
15+
import com.intellij.psi.xml.XmlTag;
16+
import com.intellij.util.ProcessingContext;
17+
import com.intellij.util.indexing.FileBasedIndex;
18+
import com.magento.idea.magento2plugin.magento.files.ModuleDbSchemaXml;
19+
import com.magento.idea.magento2plugin.stubs.indexes.xml.DeclarativeSchemaElementsIndex;
20+
import java.util.Collection;
21+
import java.util.List;
22+
import java.util.stream.Collectors;
23+
import org.jetbrains.annotations.NotNull;
24+
25+
/**
26+
* Provides column names for completion.
27+
*/
28+
public class ColumnNameCompletionProvider extends CompletionProvider<CompletionParameters> {
29+
@Override
30+
protected void addCompletions(
31+
final @NotNull CompletionParameters parameters,
32+
final @NotNull ProcessingContext context,
33+
final @NotNull CompletionResultSet result
34+
) {
35+
final PsiElement position = parameters.getPosition().getOriginalElement();
36+
final String currentAttrName = getCurrentAttributeName(position);
37+
if (position == null || currentAttrName == null) {
38+
return;
39+
}
40+
String targetTableAttrName;
41+
42+
switch (currentAttrName) {
43+
case ModuleDbSchemaXml.XML_ATTR_CONSTRAINT_COLUMN_NAME:
44+
targetTableAttrName = ModuleDbSchemaXml.XML_ATTR_CONSTRAINT_TABLE_NAME;
45+
break;
46+
case ModuleDbSchemaXml.XML_ATTR_CONSTRAINT_REFERENCE_COLUMN_NAME:
47+
targetTableAttrName = ModuleDbSchemaXml.XML_ATTR_CONSTRAINT_REFERENCE_TABLE_NAME;
48+
break;
49+
default:
50+
return;
51+
}
52+
final String targetTableName = getTargetTableFromPositionAndAttrName(
53+
position,
54+
targetTableAttrName
55+
);
56+
57+
if (targetTableName == null) {
58+
return;
59+
}
60+
final Collection<String> tableAndColumnNames = FileBasedIndex.getInstance().getAllKeys(
61+
DeclarativeSchemaElementsIndex.KEY, position.getProject()
62+
);
63+
final List<String> filteredColumnNames = tableAndColumnNames.stream()
64+
.filter(name -> name.contains(targetTableName + ".")).collect(Collectors.toList())
65+
.stream().map(name -> name.substring(name.indexOf(".") + 1))
66+
.collect(Collectors.toList());
67+
68+
for (final String columnName: filteredColumnNames) {
69+
result.addElement(LookupElementBuilder.create(columnName));
70+
}
71+
}
72+
73+
/**
74+
* Get attribute name from position.
75+
*
76+
* @param position PsiElement
77+
*
78+
* @return String
79+
*/
80+
private String getCurrentAttributeName(final PsiElement position) {
81+
if (position instanceof XmlAttributeImpl) {
82+
return ((XmlAttributeImpl) position).getName();
83+
} else {
84+
return getCurrentAttributeName(position.getParent());
85+
}
86+
}
87+
88+
/**
89+
* Get reference table name from current position.
90+
*
91+
* @param position PsiElement
92+
* @param targetTableAttrName String
93+
*
94+
* @return String
95+
*/
96+
private String getTargetTableFromPositionAndAttrName(
97+
final PsiElement position,
98+
final String targetTableAttrName
99+
) {
100+
if (targetTableAttrName == null) {
101+
return null;
102+
}
103+
104+
if (position instanceof XmlTagImpl
105+
&& ((XmlTag) position).getName().equals(ModuleDbSchemaXml.XML_TAG_CONSTRAINT)) {
106+
return ((XmlTag) position)
107+
.getAttributeValue(targetTableAttrName);
108+
} else {
109+
return getTargetTableFromPositionAndAttrName(
110+
position.getParent(),
111+
targetTableAttrName
112+
);
113+
}
114+
}
115+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.completion.provider;
7+
8+
import com.intellij.codeInsight.completion.CompletionParameters;
9+
import com.intellij.codeInsight.completion.CompletionProvider;
10+
import com.intellij.codeInsight.completion.CompletionResultSet;
11+
import com.intellij.codeInsight.lookup.LookupElementBuilder;
12+
import com.intellij.psi.PsiElement;
13+
import com.intellij.util.ProcessingContext;
14+
import com.intellij.util.indexing.FileBasedIndex;
15+
import com.magento.idea.magento2plugin.stubs.indexes.xml.DeclarativeSchemaElementsIndex;
16+
import java.util.Collection;
17+
import java.util.List;
18+
import java.util.stream.Collectors;
19+
import org.jetbrains.annotations.NotNull;
20+
21+
/**
22+
* Provides table names for completion.
23+
*/
24+
public class TableNameCompletionProvider extends CompletionProvider<CompletionParameters> {
25+
@Override
26+
protected void addCompletions(
27+
final @NotNull CompletionParameters parameters,
28+
final @NotNull ProcessingContext context,
29+
final @NotNull CompletionResultSet result
30+
) {
31+
final PsiElement position = parameters.getPosition().getOriginalElement();
32+
if (position == null) {
33+
return;
34+
}
35+
36+
final Collection<String> tableNames = FileBasedIndex.getInstance().getAllKeys(
37+
DeclarativeSchemaElementsIndex.KEY, position.getProject()
38+
);
39+
final List<String> filteredTableNames = tableNames.stream()
40+
.filter(name -> !name.contains(".")).collect(Collectors.toList());
41+
42+
for (final String tableName: filteredTableNames) {
43+
result.addElement(LookupElementBuilder.create(tableName));
44+
}
45+
}
46+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.completion.provider;
7+
8+
import com.intellij.codeInsight.completion.CompletionParameters;
9+
import com.intellij.codeInsight.completion.CompletionProvider;
10+
import com.intellij.codeInsight.completion.CompletionResultSet;
11+
import com.intellij.codeInsight.lookup.LookupElementBuilder;
12+
import com.intellij.psi.PsiElement;
13+
import com.intellij.psi.xml.XmlFile;
14+
import com.intellij.util.ProcessingContext;
15+
import com.jetbrains.php.PhpIcons;
16+
import com.magento.idea.magento2plugin.indexes.UIComponentIndex;
17+
import java.util.List;
18+
import org.jetbrains.annotations.NotNull;
19+
20+
21+
public class UiComponentCompletionProvider extends CompletionProvider<CompletionParameters> {
22+
23+
@Override
24+
protected void addCompletions(@NotNull final CompletionParameters parameters,
25+
final ProcessingContext context,
26+
@NotNull final CompletionResultSet result) {
27+
final PsiElement position = parameters.getPosition().getOriginalElement();
28+
if (position == null) {
29+
return;
30+
}
31+
32+
final List<XmlFile> targets = UIComponentIndex.getUiComponentFiles(position.getProject());
33+
if (!targets.isEmpty()) {
34+
for (final XmlFile file : targets) {
35+
result.addElement(LookupElementBuilder
36+
.create(file.getVirtualFile().getNameWithoutExtension())
37+
.withIcon(PhpIcons.XML_TAG_ICON)
38+
);
39+
}
40+
}
41+
}
42+
}

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

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ public XmlCompletionContributor() {
8888
new FilePathCompletionProvider()
8989
);
9090

91+
// <uiComponent name="completion"/>
92+
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
93+
.inside(XmlPatterns.xmlAttribute().withName(LayoutXml.NAME_ATTRIBUTE)
94+
.withParent(XmlPatterns.xmlTag().withName(LayoutXml.UI_COMPONENT_TAG_NAME))),
95+
new UiComponentCompletionProvider()
96+
);
97+
9198
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_DATA_CHARACTERS)
9299
.withParent(XmlPatterns.xmlText().withParent(
93100
XmlPatterns.xmlTag().withName(UiComponentXml.XML_TAG_ITEM).withChild(
@@ -126,20 +133,20 @@ public XmlCompletionContributor() {
126133

127134
// <observer instance="Class">
128135
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
129-
.inside(XmlPatterns.xmlAttribute().withName(ModuleEventsXml.INSTANCE_ATTRIBUTE)
130-
.withParent(XmlPatterns.xmlTag().withName(ModuleEventsXml.OBSERVER_TAG)
131-
)
132-
).inFile(xmlFile().withName(string().matches(ModuleEventsXml.FILE_NAME))),
133-
new PhpClassCompletionProvider()
136+
.inside(XmlPatterns.xmlAttribute().withName(ModuleEventsXml.INSTANCE_ATTRIBUTE)
137+
.withParent(XmlPatterns.xmlTag().withName(ModuleEventsXml.OBSERVER_TAG)
138+
)
139+
).inFile(xmlFile().withName(string().matches(ModuleEventsXml.FILE_NAME))),
140+
new PhpClassCompletionProvider()
134141
);
135142

136143
// <job instance="class">
137144
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
138-
.inside(XmlPatterns.xmlAttribute().withName(CommonXml.ATTR_INSTANCE)
139-
.withParent(XmlPatterns.xmlTag().withName(CrontabXmlTemplate.CRON_JOB_TAG)
140-
)
141-
).inFile(xmlFile().withName(string().matches(CrontabXmlTemplate.FILE_NAME))),
142-
new PhpClassCompletionProvider()
145+
.inside(XmlPatterns.xmlAttribute().withName(CommonXml.ATTR_INSTANCE)
146+
.withParent(XmlPatterns.xmlTag().withName(CrontabXmlTemplate.CRON_JOB_TAG)
147+
)
148+
).inFile(xmlFile().withName(string().matches(CrontabXmlTemplate.FILE_NAME))),
149+
new PhpClassCompletionProvider()
143150
);
144151

145152
// <source_model>php class completion</source_model> in system.xml files.
@@ -317,6 +324,64 @@ public XmlCompletionContributor() {
317324
new MenuCompletionProvider()
318325
);
319326

327+
// <table name="completion" /> in db_schema.xml
328+
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
329+
.inside(XmlPatterns.xmlAttribute().withName(ModuleDbSchemaXml.XML_ATTR_TABLE_NAME)
330+
.withParent(XmlPatterns.xmlTag().withName(ModuleDbSchemaXml.XML_TAG_TABLE)
331+
.withParent(XmlPatterns.xmlTag()
332+
.withName(ModuleDbSchemaXml.XML_TAG_SCHEMA))))
333+
.inFile(xmlFile().withName(string().matches(ModuleDbSchemaXml.FILE_NAME))),
334+
new TableNameCompletionProvider()
335+
);
336+
337+
// <constraint table="completion" /> in db_schema.xml
338+
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
339+
.inside(XmlPatterns.xmlAttribute()
340+
.withName(ModuleDbSchemaXml.XML_ATTR_CONSTRAINT_TABLE_NAME)
341+
.withParent(XmlPatterns.xmlTag()
342+
.withName(ModuleDbSchemaXml.XML_TAG_CONSTRAINT)
343+
.withParent(XmlPatterns.xmlTag()
344+
.withName(ModuleDbSchemaXml.XML_TAG_TABLE))))
345+
.inFile(xmlFile().withName(string().matches(ModuleDbSchemaXml.FILE_NAME))),
346+
new TableNameCompletionProvider()
347+
);
348+
349+
// <constraint referenceTable="completion" /> in db_schema.xml
350+
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
351+
.inside(XmlPatterns.xmlAttribute()
352+
.withName(ModuleDbSchemaXml.XML_ATTR_CONSTRAINT_REFERENCE_TABLE_NAME)
353+
.withParent(XmlPatterns.xmlTag()
354+
.withName(ModuleDbSchemaXml.XML_TAG_CONSTRAINT)
355+
.withParent(XmlPatterns.xmlTag()
356+
.withName(ModuleDbSchemaXml.XML_TAG_TABLE))))
357+
.inFile(xmlFile().withName(string().matches(ModuleDbSchemaXml.FILE_NAME))),
358+
new TableNameCompletionProvider()
359+
);
360+
361+
// <constraint column="completion" /> in db_schema.xml
362+
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
363+
.inside(XmlPatterns.xmlAttribute()
364+
.withName(ModuleDbSchemaXml.XML_ATTR_CONSTRAINT_COLUMN_NAME)
365+
.withParent(XmlPatterns.xmlTag()
366+
.withName(ModuleDbSchemaXml.XML_TAG_CONSTRAINT)
367+
.withParent(XmlPatterns.xmlTag()
368+
.withName(ModuleDbSchemaXml.XML_TAG_TABLE))))
369+
.inFile(xmlFile().withName(string().matches(ModuleDbSchemaXml.FILE_NAME))),
370+
new ColumnNameCompletionProvider()
371+
);
372+
373+
// <constraint referenceColumn="completion" /> in db_schema.xml
374+
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
375+
.inside(XmlPatterns.xmlAttribute()
376+
.withName(ModuleDbSchemaXml.XML_ATTR_CONSTRAINT_REFERENCE_COLUMN_NAME)
377+
.withParent(XmlPatterns.xmlTag()
378+
.withName(ModuleDbSchemaXml.XML_TAG_CONSTRAINT)
379+
.withParent(XmlPatterns.xmlTag()
380+
.withName(ModuleDbSchemaXml.XML_TAG_TABLE))))
381+
.inFile(xmlFile().withName(string().matches(ModuleDbSchemaXml.FILE_NAME))),
382+
new ColumnNameCompletionProvider()
383+
);
384+
320385
registerCompletionsForDifferentNesting();
321386
}
322387

0 commit comments

Comments
 (0)