Skip to content

Commit d455aff

Browse files
author
Vitaliy
authored
Merge branch '1.0.0-develop' into 182-fix-null-pointer-excepiton-in-plugin-declaration-inspection
2 parents 956ffdd + b5355fe commit d455aff

File tree

30 files changed

+430
-91
lines changed

30 files changed

+430
-91
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
inspection.plugin.duplicateInSameFile=The plugin name already used in this file. For more details see Inspection Description.
2-
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.
2+
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

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

Lines changed: 41 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,44 @@ public XmlCompletionContributor() {
282247
),
283248
new DataCompletionProvider()
284249
);
250+
251+
registerCompletionsForDifferentNesting();
252+
}
253+
254+
private void registerCompletionsForDifferentNesting() {
255+
int i = 1;
256+
int maxNesting = 10;
257+
while( i < maxNesting) {
258+
259+
// mftf selector completion contributor
260+
extend(CompletionType.BASIC,
261+
psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
262+
.inside(XmlPatterns.xmlAttribute()
263+
.withName(MftfActionGroup.SELECTOR_ATTRIBUTE).withSuperParent(
264+
i,
265+
XmlPatterns.xmlTag().withParent(
266+
XmlPatterns.xmlTag().withName(
267+
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.ROOT_TAG)
268+
)))
269+
),
270+
new SelectorCompletionProvider()
271+
);
272+
273+
// mftf page url completion contributor
274+
extend(
275+
CompletionType.BASIC,
276+
psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
277+
.inside(
278+
XmlPatterns.xmlAttribute().withName(MftfActionGroup.URL_ATTRIBUTE)
279+
.withSuperParent(i ,XmlPatterns.xmlTag().withParent(
280+
XmlPatterns.xmlTag().withName(
281+
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.ROOT_TAG)
282+
)))
283+
),
284+
new PageCompletionProvider()
285+
);
286+
287+
i++;
288+
}
285289
}
286290
}

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;

src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void visitFile(PsiFile file) {
7272

7373
List<XmlTag> targetObservers = fetchObserverTagsFromEventTag(eventXmlTag);
7474
if (targetObservers.isEmpty()) {
75-
return;
75+
continue;
7676
}
7777

7878
for (XmlTag observerXmlTag: targetObservers) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
3939
if (psiElement instanceof PhpClass) {
4040
List<? extends PsiElement> results;
4141

42-
if (GraphQlUtil.isResolver((PhpClass) psiElement)) {
42+
if (!GraphQlUtil.isResolver((PhpClass) psiElement)) {
4343
return;
4444
}
4545
GraphQlUsagesCollector collector = new GraphQlUsagesCollector();

src/com/magento/idea/magento2plugin/magento/files/GraphQlResolver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66

77
public class GraphQlResolver {
88
public static final String RESOLVER_INTERFACE = "\\Magento\\Framework\\GraphQl\\Query\\ResolverInterface";
9+
public static final String BATCH_RESOLVER_INTERFACE = "\\Magento\\Framework\\GraphQl\\Query\\Resolver\\BatchResolverInterface";
10+
public static final String BATCH_SERVICE_CONTRACT_RESOLVER_INTERFACE = "\\Magento\\Framework\\GraphQl\\Query\\Resolver\\BatchServiceContractResolverInterface";
911
public static final String CLASS_ARGUMENT = "class";
1012
}

src/com/magento/idea/magento2plugin/magento/files/Plugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public class Plugin implements ModuleFileInterface {
1212
private static final String AROUND_METHOD_TEMPLATE_NAME = "Magento Plugin Around Method";
1313
private static final String AFTER_METHOD_TEMPLATE_NAME = "Magento Plugin After Method";
1414

15+
public static final String CALLABLE_PARAM = "callable";
16+
public static final String CLOSURE_PARAM = "Closure";
17+
1518
public enum PluginType {
1619
before,
1720
after,

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

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -170,34 +170,6 @@ public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar)
170170
)
171171
);
172172

173-
// <someXmlTag url="{{someValue}}" /> in MFTF Tests and ActionGroups
174-
registrar.registerReferenceProvider(
175-
XmlPatterns.xmlAttributeValue().withValue(
176-
string().matches(RegExUtil.Magento.MFTF_CURLY_BRACES)
177-
).withParent(XmlPatterns.xmlAttribute().withName(
178-
MftfActionGroup.URL_ATTRIBUTE
179-
).withParent(XmlPatterns.xmlTag().withParent(XmlPatterns.xmlTag().withName(
180-
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.ROOT_TAG)
181-
)))),
182-
new CompositeReferenceProvider(
183-
new PageReferenceProvider()
184-
)
185-
);
186-
registrar.registerReferenceProvider(
187-
XmlPatterns.xmlAttributeValue().withValue(
188-
string().matches(RegExUtil.Magento.MFTF_CURLY_BRACES)
189-
).withParent(XmlPatterns.xmlAttribute().withName(
190-
MftfActionGroup.URL_ATTRIBUTE
191-
).withParent(XmlPatterns.xmlTag().withParent(XmlPatterns.xmlTag().withParent(
192-
XmlPatterns.xmlTag().withName(
193-
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.ROOT_TAG)
194-
)
195-
)))),
196-
new CompositeReferenceProvider(
197-
new PageReferenceProvider()
198-
)
199-
);
200-
201173
// <createData entity="SimpleProduct" />
202174
// <updateData entity="SimpleProduct" />
203175
registrar.registerReferenceProvider(
@@ -273,5 +245,44 @@ public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar)
273245
),
274246
new RequireJsPreferenceReferenceProvider()
275247
);
248+
249+
registerReferenceForDifferentNesting(registrar);
250+
}
251+
252+
private void registerReferenceForDifferentNesting(@NotNull PsiReferenceRegistrar registrar) {
253+
int i = 1;
254+
int maxNesting = 10;
255+
while( i < maxNesting) {
256+
257+
// <someXmlTag url="{{someValue}}" /> in MFTF Tests and ActionGroups
258+
registrar.registerReferenceProvider(
259+
XmlPatterns.xmlAttributeValue().withValue(
260+
string().matches(RegExUtil.Magento.MFTF_CURLY_BRACES)
261+
).withParent(XmlPatterns.xmlAttribute().withName(
262+
MftfActionGroup.URL_ATTRIBUTE
263+
).withParent(XmlPatterns.xmlTag().withSuperParent(i, XmlPatterns.xmlTag().withName(
264+
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.ROOT_TAG)
265+
)))),
266+
new CompositeReferenceProvider(
267+
new PageReferenceProvider()
268+
)
269+
);
270+
271+
// <someXmlTag selector="{{someValue}}" /> in MFTF Tests and ActionGroups
272+
registrar.registerReferenceProvider(
273+
XmlPatterns.xmlAttributeValue().withValue(
274+
string().matches(RegExUtil.Magento.MFTF_CURLY_BRACES)
275+
).withParent(XmlPatterns.xmlAttribute().withName(
276+
MftfActionGroup.SELECTOR_ATTRIBUTE
277+
).withParent(XmlPatterns.xmlTag().withSuperParent(i, XmlPatterns.xmlTag().withName(
278+
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.ROOT_TAG)
279+
)))),
280+
new CompositeReferenceProvider(
281+
new SectionReferenceProvider()
282+
)
283+
);
284+
285+
i++;
286+
}
276287
}
277288
}

src/com/magento/idea/magento2plugin/util/magento/graphql/GraphQlUtil.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,19 @@ public static GraphQLStringValue fetchResolverQuotedStringFromArgument(PsiElemen
4444
return argumentStringValue;
4545
}
4646

47-
public static boolean isResolver(PhpClass psiElement) {
47+
public static boolean isResolver(PhpClass psiElement) {
4848
PhpClass[] implementedInterfaces = psiElement.getImplementedInterfaces();
4949
for (PhpClass implementedInterface: implementedInterfaces) {
50-
if (!implementedInterface.getFQN().equals(GraphQlResolver.RESOLVER_INTERFACE)) {
51-
continue;
50+
if (implementedInterface.getFQN().equals(
51+
GraphQlResolver.RESOLVER_INTERFACE
52+
) || implementedInterface.getFQN().equals(
53+
GraphQlResolver.BATCH_RESOLVER_INTERFACE
54+
) || implementedInterface.getFQN().equals(
55+
GraphQlResolver.BATCH_SERVICE_CONTRACT_RESOLVER_INTERFACE
56+
)) {
57+
return true;
5258
}
53-
return false;
5459
}
55-
return true;
60+
return false;
5661
}
5762
}

0 commit comments

Comments
 (0)