Skip to content

Commit 0c6d845

Browse files
author
Vitaliy Boyko
committed
Merge branches '1.0.0-develop' and '1.0.1-develop' of https://github.com/magento/magento2-phpstorm-plugin into 1.0.1-develop
� Conflicts: � resources/magento2/inspection.properties
2 parents 2c96624 + 206c795 commit 0c6d845

File tree

52 files changed

+833
-230
lines changed

Some content is hidden

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

52 files changed

+833
-230
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.mftf.ActionGroupIndex" />
108108
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.mftf.DataIndex" />
109109
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.mftf.PageIndex" />
110-
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.mftf.StepKeyIndex" />
110+
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.mftf.TestNameIndex" />
111111
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.js.RequireJsIndex" />
112112
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.js.MagentoLibJsIndex" />
113113

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
inspection.plugin.duplicateInSameFile=The plugin name already used in this file. For more details see Inspection Description.
22
inspection.plugin.duplicateInOtherPlaces=The plugin name "{0}" for targeted "{1}" class is already used in the module "{2}" ({3} scope). For more details see Inspection Description.
3+
inspection.graphql.resolver.mustImplement=Class must implements any of the following interfaces: \\Magento\\Framework\\GraphQl\\Query\\ResolverInterface, \\Magento\\Framework\\GraphQl\\Query\\Resolver\\BatchResolverInterface, \\Magento\\Framework\\GraphQl\\Query\\Resolver\\BatchServiceContractResolverInterface
4+
inspection.graphql.resolver.fix.family=Implement Resolver interface
5+
inspection.graphql.resolver.fix.title=Select one of the following interface

src/com/magento/idea/magento2plugin/actions/generation/generator/code/PluginMethodsGenerator.java

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
import com.jetbrains.php.lang.psi.resolve.types.PhpType;
1818
import com.magento.idea.magento2plugin.actions.generation.data.code.PluginMethodData;
1919
import com.magento.idea.magento2plugin.magento.files.Plugin;
20+
import com.magento.idea.magento2plugin.magento.packages.Package;
2021
import org.jetbrains.annotations.NotNull;
2122
import org.jetbrains.annotations.Nullable;
23+
2224
import java.util.*;
2325
import java.util.regex.Pattern;
2426

@@ -152,7 +154,17 @@ private String getParameterDoc(Collection<PsiElement> parameters, @NotNull Plugi
152154
}
153155

154156
sb.append("* @param ");
155-
String typeStr = PhpDocUtil.getTypePresentation(project, element.getType(), PhpCodeInsightUtil.findScopeForUseOperator(element));
157+
158+
String typeStr;
159+
if (i == 0) {
160+
typeStr = PhpDocUtil.getTypePresentation(project, element.getType(), null);
161+
} else {
162+
typeStr = PhpDocUtil.getTypePresentation(project, element.getType(), PhpCodeInsightUtil.findScopeForUseOperator(element));
163+
if (typeStr.indexOf(Package.FQN_SEPARATOR, 1) > 0) {
164+
String[] fqnArray = typeStr.split("\\\\");
165+
typeStr = fqnArray[fqnArray.length - 1];
166+
}
167+
}
156168

157169
if (!typeStr.isEmpty()) {
158170
sb.append(typeStr).append(' ');
@@ -202,9 +214,15 @@ protected String getParameterList(Collection<PsiElement> parameters, @NotNull Pl
202214
}
203215

204216
if (element instanceof Parameter) {
205-
buf.append(PhpCodeUtil.paramToString(element));
217+
String parameterText = PhpCodeUtil.paramToString(element);
218+
if (parameterText.indexOf(Package.FQN_SEPARATOR, 1) > 0) {
219+
String[] fqnArray = parameterText.split("\\\\");
220+
parameterText = fqnArray[fqnArray.length - 1];
221+
}
222+
buf.append(parameterText);
206223
} else {
207-
String typeHint = this.getTypeHint(element);
224+
Boolean globalType = i != 0;
225+
String typeHint = this.getTypeHint(element, globalType);
208226
if (typeHint != null && !typeHint.isEmpty()) {
209227
buf.append(typeHint).append(' ');
210228
}
@@ -257,21 +275,20 @@ protected String getReturnVariables(@NotNull Plugin.PluginType type) {
257275
}
258276

259277
@Nullable
260-
private String getTypeHint(@NotNull PhpNamedElement element) {
278+
private String getTypeHint(@NotNull PhpNamedElement element, Boolean globalType) {
261279
PhpType filedType = element.getType().global(this.pluginClass.getProject());
262280
Set<String> typeStrings = filedType.getTypes();
263281
String typeString = null;
264282
if (typeStrings.size() == 1) {
265-
typeString = this.convertTypeToString(element, typeStrings);
283+
typeString = this.convertTypeToString(element, typeStrings, globalType);
266284
}
267285

268286
if (typeStrings.size() == 2) {
269287
PhpType filteredNullType = filterNullCaseInsensitive(filedType);
270288
if (filteredNullType.getTypes().size() == 1) {
289+
typeString = this.convertTypeToString(element, filteredNullType.getTypes(), globalType);
271290
if (PhpLanguageFeature.NULLABLES.isSupported(element.getProject())) {
272-
typeString = "?" + this.convertTypeToString(element, filteredNullType.getTypes());
273-
} else {
274-
typeString = this.convertTypeToString(element, filteredNullType.getTypes());
291+
typeString = "?" + typeString;
275292
}
276293
}
277294
}
@@ -280,11 +297,11 @@ private String getTypeHint(@NotNull PhpNamedElement element) {
280297
}
281298

282299
@Nullable
283-
private String convertTypeToString(@NotNull PhpNamedElement element, Set<String> typeStrings) {
300+
private String convertTypeToString(@NotNull PhpNamedElement element, Set<String> typeStrings, Boolean globalType) {
284301
String simpleType = typeStrings.iterator().next();
285302
simpleType = StringUtil.trimStart(simpleType, "\\");
286303
if (!PhpType.isPrimitiveType(simpleType) || PhpLanguageFeature.SCALAR_TYPE_HINTS.isSupported(element.getProject()) || "array".equalsIgnoreCase(simpleType) || "callable".equalsIgnoreCase(simpleType)) {
287-
String typeString = simpleType.endsWith("]") ? "array" : this.getFieldTypeString(element, filterNullCaseInsensitive(element.getType()));
304+
String typeString = simpleType.endsWith("]") ? "array" : this.getFieldTypeString(element, filterNullCaseInsensitive(element.getType()), globalType);
288305
if (!typeString.isEmpty()) {
289306
return typeString;
290307
}
@@ -293,8 +310,9 @@ private String convertTypeToString(@NotNull PhpNamedElement element, Set<String>
293310
return null;
294311
}
295312

296-
private String getFieldTypeString(PhpNamedElement element, @NotNull PhpType type) {
297-
return PhpDocUtil.getTypePresentation(this.pluginClass.getProject(), type, PhpCodeInsightUtil.findScopeForUseOperator(element));
313+
private String getFieldTypeString(PhpNamedElement element, @NotNull PhpType type, Boolean globalType) {
314+
PhpPsiElement scope = (globalType) ? PhpCodeInsightUtil.findScopeForUseOperator(element) : null;
315+
return PhpDocUtil.getTypePresentation(this.pluginClass.getProject(), type, scope);
298316
}
299317

300318
private static PhpType filterNullCaseInsensitive(PhpType filedType) {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
package com.magento.idea.magento2plugin.completion.provider.mftf;
6+
7+
import com.intellij.codeInsight.completion.CompletionParameters;
8+
import com.intellij.codeInsight.completion.CompletionProvider;
9+
import com.intellij.codeInsight.completion.CompletionResultSet;
10+
import com.intellij.codeInsight.lookup.LookupElementBuilder;
11+
import com.intellij.psi.PsiElement;
12+
import com.intellij.psi.util.PsiTreeUtil;
13+
import com.intellij.psi.xml.XmlAttribute;
14+
import com.intellij.psi.xml.XmlAttributeValue;
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.MftfTest;
19+
import com.magento.idea.magento2plugin.stubs.indexes.mftf.TestNameIndex;
20+
import org.jetbrains.annotations.NotNull;
21+
import java.util.Collection;
22+
23+
public class TestNameCompletionProvider extends CompletionProvider<CompletionParameters> {
24+
25+
@Override
26+
protected void addCompletions(
27+
@NotNull CompletionParameters parameters,
28+
ProcessingContext context,
29+
@NotNull CompletionResultSet result) {
30+
PsiElement position = parameters.getPosition().getOriginalElement();
31+
32+
if (position == null) {
33+
return;
34+
}
35+
36+
Collection<String> allKeys = FileBasedIndex.getInstance().getAllKeys(TestNameIndex.KEY, position.getProject());
37+
38+
String currentTestName = getCurrentTestName((XmlAttributeValue) parameters.getPosition().getParent());
39+
for (String testName: allKeys) {
40+
if (testName.equals(currentTestName)) {
41+
continue;
42+
}
43+
result.addElement(LookupElementBuilder.create(testName));
44+
}
45+
}
46+
47+
private String getCurrentTestName(XmlAttributeValue xmlAttributeValue) {
48+
PsiElement xmlAttribute = xmlAttributeValue.getParent();
49+
XmlTag xmlTag = PsiTreeUtil.getParentOfType(xmlAttribute, XmlTag.class);
50+
if (xmlTag == null) {
51+
return null;
52+
}
53+
XmlAttribute nameAttribute = xmlTag.getAttribute(MftfTest.NAME_ATTRIBUTE);
54+
if (nameAttribute == null) {
55+
return null;
56+
}
57+
String value = nameAttribute.getValue();
58+
if (value == null || value.isEmpty()) {
59+
return null;
60+
}
61+
62+
return value;
63+
}
64+
}

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

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -215,51 +215,16 @@ public XmlCompletionContributor() {
215215
new RequireJsMappingCompletionProvider()
216216
);
217217

218-
// mftf selector completion contributor
219-
extend(CompletionType.BASIC,
220-
psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
221-
.inside(XmlPatterns.xmlAttribute()
222-
.withName(MftfActionGroup.SELECTOR_ATTRIBUTE))
223-
.inFile(xmlFile().withName(string().endsWith("Test.xml"))),
224-
new SelectorCompletionProvider()
225-
);
226-
227218
// mftf action group completion contributor
228219
extend(
229220
CompletionType.BASIC,
230221
psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
231222
.inside(
232223
XmlPatterns.xmlAttribute().withName(string().oneOf("ref", "extends"))
233224
.withParent(XmlPatterns.xmlTag().withName("actionGroup")
234-
)
235-
),
236-
new ActionGroupCompletionProvider()
237-
);
238-
239-
// mftf page url completion contributor
240-
extend(
241-
CompletionType.BASIC,
242-
psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
243-
.inside(
244-
XmlPatterns.xmlAttribute().withName(MftfActionGroup.URL_ATTRIBUTE)
245-
.withParent(XmlPatterns.xmlTag().withParent(
246-
XmlPatterns.xmlTag().withName(
247-
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.ROOT_TAG)
248-
)))
225+
)
249226
),
250-
new PageCompletionProvider()
251-
);
252-
extend(
253-
CompletionType.BASIC,
254-
psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
255-
.inside(
256-
XmlPatterns.xmlAttribute().withName(MftfActionGroup.URL_ATTRIBUTE)
257-
.withParent(XmlPatterns.xmlTag().withParent(
258-
XmlPatterns.xmlTag().withParent(XmlPatterns.xmlTag().withName(
259-
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.ROOT_TAG)
260-
))))
261-
),
262-
new PageCompletionProvider()
227+
new ActionGroupCompletionProvider()
263228
);
264229

265230
// mftf data entity completion contributor
@@ -282,5 +247,58 @@ public XmlCompletionContributor() {
282247
),
283248
new DataCompletionProvider()
284249
);
250+
251+
// MFTF Test extends completion contributor
252+
extend(
253+
CompletionType.BASIC,
254+
psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
255+
.inside(
256+
XmlPatterns.xmlAttribute().withName(MftfTest.EXTENDS_ATTRIBUTE)
257+
.withParent(XmlPatterns.xmlTag().withName(MftfTest.TEST_TAG)
258+
.withParent(XmlPatterns.xmlTag().withName(MftfTest.ROOT_TAG)
259+
)
260+
)
261+
),
262+
new TestNameCompletionProvider()
263+
);
264+
265+
registerCompletionsForDifferentNesting();
266+
}
267+
268+
private void registerCompletionsForDifferentNesting() {
269+
int i = 1;
270+
int maxNesting = 10;
271+
while( i < maxNesting) {
272+
273+
// mftf selector completion contributor
274+
extend(CompletionType.BASIC,
275+
psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
276+
.inside(XmlPatterns.xmlAttribute()
277+
.withName(MftfActionGroup.SELECTOR_ATTRIBUTE).withSuperParent(
278+
i,
279+
XmlPatterns.xmlTag().withParent(
280+
XmlPatterns.xmlTag().withName(
281+
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.TEST_TAG)
282+
)))
283+
),
284+
new SelectorCompletionProvider()
285+
);
286+
287+
// mftf page url completion contributor
288+
extend(
289+
CompletionType.BASIC,
290+
psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
291+
.inside(
292+
XmlPatterns.xmlAttribute().withName(MftfActionGroup.URL_ATTRIBUTE)
293+
.withSuperParent(i ,XmlPatterns.xmlTag().withParent(
294+
XmlPatterns.xmlTag().withName(
295+
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.TEST_TAG)
296+
)))
297+
),
298+
new PageCompletionProvider()
299+
);
300+
301+
i++;
302+
}
285303
}
286304
}

src/com/magento/idea/magento2plugin/indexes/IndexManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void manualReindex() {
4040
DataIndex.KEY,
4141
PageIndex.KEY,
4242
SectionIndex.KEY,
43-
StepKeyIndex.KEY,
43+
TestNameIndex.KEY,
4444
//graphql
4545
GraphQlResolverIndex.KEY
4646
};

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.jetbrains.php.lang.inspections.PhpInspection;
1313
import com.jetbrains.php.lang.psi.elements.PhpClass;
1414
import com.jetbrains.php.lang.psi.visitors.PhpElementVisitor;
15+
import com.magento.idea.magento2plugin.bundles.InspectionBundle;
1516
import com.magento.idea.magento2plugin.inspections.php.fix.PhpImplementResolverClassQuickFix;
1617
import com.magento.idea.magento2plugin.util.magento.graphql.GraphQlUsagesCollector;
1718
import com.magento.idea.magento2plugin.util.magento.graphql.GraphQlUtil;
@@ -21,7 +22,7 @@
2122

2223
public class GraphQlResolverInspection extends PhpInspection {
2324

24-
public static final String GraphQlResolverProblemDescription = "Class must implements \\Magento\\Framework\\GraphQl\\Query\\ResolverInterface";
25+
private final InspectionBundle inspectionBundle = new InspectionBundle();
2526

2627
@NotNull
2728
@Override
@@ -32,11 +33,13 @@ public void visitPhpClass(PhpClass resolverClass) {
3233
GraphQlUsagesCollector collector = new GraphQlUsagesCollector();
3334
results = collector.getGraphQLUsages(resolverClass);
3435
if (results.size() > 0 ) {
35-
if (GraphQlUtil.isResolver(resolverClass)) {
36+
if (!GraphQlUtil.isResolver(resolverClass)) {
3637
PsiElement currentClassNameIdentifier = resolverClass.getNameIdentifier();
3738
assert currentClassNameIdentifier != null;
3839
problemsHolder.registerProblem(currentClassNameIdentifier,
39-
GraphQlResolverProblemDescription,
40+
inspectionBundle.message(
41+
"inspection.graphql.resolver.mustImplement"
42+
),
4043
ProblemHighlightType.ERROR,
4144
new PhpImplementResolverClassQuickFix());
4245
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.jetbrains.php.lang.psi.visitors.PhpElementVisitor;
2121
import com.magento.idea.magento2plugin.inspections.php.util.PhpClassImplementsInterfaceUtil;
2222
import com.magento.idea.magento2plugin.magento.files.Plugin;
23+
import com.magento.idea.magento2plugin.magento.packages.Package;
2324
import com.magento.idea.magento2plugin.util.GetPhpClassByFQN;
2425
import com.magento.idea.magento2plugin.util.magento.plugin.GetTargetClassNamesByPluginClassName;
2526
import org.jetbrains.annotations.NotNull;
@@ -128,7 +129,7 @@ private void checkParametersCompatibility(Method pluginMethod, String pluginPref
128129
String declaredType = pluginMethodParameter.getDeclaredType().toString();
129130

130131
if (index == 1) {
131-
String targetClassFqn = "\\".concat(targetClassName);
132+
String targetClassFqn = Package.FQN_SEPARATOR.concat(targetClassName);
132133
if (!checkTypeIncompatibility(targetClassFqn, declaredType, phpIndex)) {
133134
problemsHolder.registerProblem(pluginMethodParameter, PhpBundle.message("inspection.wrong_param_type", new Object[]{declaredType, targetClassFqn}), ProblemHighlightType.ERROR);
134135
}
@@ -138,7 +139,8 @@ private void checkParametersCompatibility(Method pluginMethod, String pluginPref
138139
continue;
139140
}
140141
if (index == 2 && pluginPrefix.equals(Plugin.PluginType.around.toString())) {
141-
if (!checkTypeIncompatibility("callable", declaredType, phpIndex)) {
142+
if (!checkTypeIncompatibility(Plugin.CALLABLE_PARAM, declaredType, phpIndex) &&
143+
!checkTypeIncompatibility(Package.FQN_SEPARATOR.concat(Plugin.CLOSURE_PARAM), declaredType, phpIndex)) {
142144
problemsHolder.registerProblem(pluginMethodParameter, PhpBundle.message("inspection.wrong_param_type", new Object[]{declaredType, "callable"}), ProblemHighlightType.ERROR);
143145
}
144146
continue;

0 commit comments

Comments
 (0)