Skip to content

Commit d46051b

Browse files
author
Vitaliy
authored
Merge branch '1.0.0-develop' into 1.0.0-develop
2 parents 7620d21 + 274fbd7 commit d46051b

File tree

42 files changed

+581
-103
lines changed

Some content is hidden

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

42 files changed

+581
-103
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
<internalFileTemplate name="Magento Module Common Php Class"/>
157157
<internalFileTemplate name="Magento Observer Class"/>
158158
<internalFileTemplate name="Magento Module Events Xml"/>
159+
<internalFileTemplate name="Magento GraphQL Resolver Class"/>
159160
</extensions>
160161

161162
<extensions defaultExtensionNs="com.jetbrains.php">
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!--
2+
/*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html>
8+
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td><font face="verdana" size="-1">A resolver performs GraphQL request processing. In general, it is responsible
12+
for constructing a query, fetching data and performing any calculations, then transforming the fetched and
13+
calculated data into a GraphQL array format. Finally, it returns the results wrapped by a callable function.
14+
</font><br>
15+
</td>
16+
</tr>
17+
</table>
18+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
19+
<tr>
20+
<tr>
21+
<td><font face="verdana" size="-1">
22+
<a href="https://devdocs.magento.com/guides/v2.3/graphql/develop/resolvers.html">Read more</a> about GraphQL Resolver, including when those can be used.
23+
</font><br>
24+
</td>
25+
</tr>
26+
</tr>
27+
</table>
28+
</body>
29+
</html>

resources/fileTemplates/code/Magento GraphQL Resolver.php.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

resources/fileTemplates/internal/Magento GraphQL Resolver Class.php.html

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,43 @@
66
-->
77
<html>
88
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td><font face="verdana" size="-1">A resolver performs GraphQL request processing. In general, it is responsible
12+
for constructing a query, fetching data and performing any calculations, then transforming the fetched and
13+
calculated data into a GraphQL array format. Finally, it returns the results wrapped by a callable function.
14+
</font><br>
15+
</td>
16+
</tr>
17+
<tr>
18+
<td><font face="verdana" size="-1">A GraphQL resolver must implement interface Magento\Framework\GraphQl\Query\Resolver\BatchResolverInterface.
19+
This interface provides a way to resolve multiple branches/leaves at once (known as batching).
20+
Magento recommends using batch resolvers for queries because they improve performance by fetching information
21+
required to resolve multiple GraphQL requests with a single operation.
22+
</font><br>
23+
</td>
24+
</tr>
25+
<tr>
26+
<td><font face="verdana" size="-1">
27+
<a href="https://devdocs.magento.com/guides/v2.3/graphql/develop/resolvers.html">Read more</a> about GraphQL Resolver, including when those can be used.
28+
</font><br>
29+
</td>
30+
</tr>
31+
</table>
32+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
33+
<tr>
34+
<td colspan="3"><font face="verdana" size="-1">Template's variables:</font></td>
35+
</tr>
36+
<tr>
37+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAMESPACE}</b></font></nobr></td>
38+
<td width="10">&nbsp;</td>
39+
<td width="100%" valign="top"><font face="verdana" size="-1">Created PHP GraphQL resolver class namespace.</font></td>
40+
</tr>
41+
<tr>
42+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAME}</b></font></nobr></td>
43+
<td width="10">&nbsp;</td>
44+
<td width="100%" valign="top"><font face="verdana" size="-1">PHP class for the GraphQL resolver name.</font></td>
45+
</tr>
46+
</table>
947
</body>
10-
</html>
48+
</html>

resources/magento2/validation.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ validator.file.alreadyExists={0} already exists
1010
validator.file.cantBeCreated={0} can't be created
1111
validator.class.alreadyDeclared={0} already declared in the target module
1212
validator.magentoVersionInvalid=Please specify valid Magento version or use 'any' keyword as default
13+
validator.class.targetClassNotFound=Target class is not found. Check the di.xml file

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@
2525
import com.jetbrains.php.lang.psi.PhpCodeEditUtil;
2626
import com.jetbrains.php.lang.psi.PhpFile;
2727
import com.jetbrains.php.lang.psi.PhpPsiUtil;
28-
import com.jetbrains.php.lang.psi.elements.*;
29-
import java.util.*;
28+
import com.jetbrains.php.lang.psi.elements.Method;
29+
import com.jetbrains.php.lang.psi.elements.PhpClass;
30+
import com.jetbrains.php.lang.psi.elements.PhpPsiElement;
3031
import com.magento.idea.magento2plugin.actions.generation.ImportReferences.PhpClassReferenceResolver;
3132
import com.magento.idea.magento2plugin.actions.generation.data.code.PluginMethodData;
3233
import com.magento.idea.magento2plugin.actions.generation.generator.code.PluginMethodsGenerator;
3334
import com.magento.idea.magento2plugin.actions.generation.util.CodeStyleSettings;
3435
import com.magento.idea.magento2plugin.actions.generation.util.CollectInsertedMethods;
3536
import com.magento.idea.magento2plugin.actions.generation.util.FillTextBufferWithPluginMethods;
37+
import com.magento.idea.magento2plugin.bundles.ValidatorBundle;
3638
import com.magento.idea.magento2plugin.magento.files.Plugin;
3739
import com.magento.idea.magento2plugin.util.GetPhpClassByFQN;
3840
import com.magento.idea.magento2plugin.util.magento.plugin.GetTargetClassNamesByPluginClassName;
@@ -41,15 +43,20 @@
4143
import org.jetbrains.annotations.NotNull;
4244
import org.jetbrains.annotations.Nullable;
4345

46+
import javax.swing.*;
47+
import java.util.*;
48+
4449
public abstract class PluginGenerateMethodHandlerBase implements LanguageCodeInsightActionHandler {
4550
private CollectInsertedMethods collectInsertedMethods;
51+
private ValidatorBundle validatorBundle;
4652
public String type;
4753
public FillTextBufferWithPluginMethods fillTextBuffer;
4854

4955
public PluginGenerateMethodHandlerBase(Plugin.PluginType type) {
5056
this.type = type.toString();
5157
this.fillTextBuffer = FillTextBufferWithPluginMethods.getInstance();
5258
this.collectInsertedMethods = CollectInsertedMethods.getInstance();
59+
this.validatorBundle = new ValidatorBundle();
5360
}
5461

5562
public boolean isValidFor(Editor editor, PsiFile file) {
@@ -155,9 +162,17 @@ protected PhpNamedElementNode[] targetMethods(@NotNull PhpClass phpClass, Key<Ob
155162
ArrayList<String> targetClassNames = targetClassesService.execute(currentClass);
156163
for (String targetClassName : targetClassNames) {
157164
PhpClass targetClass = GetPhpClassByFQN.getInstance(phpClass.getProject()).execute(targetClassName);
165+
166+
if (targetClass == null) {
167+
String errorMessage = validatorBundle.message("validator.class.targetClassNotFound");
168+
JOptionPane.showMessageDialog(null, errorMessage, "Error", JOptionPane.ERROR_MESSAGE);
169+
continue;
170+
}
171+
158172
if (targetClass.isFinal()) {
159173
continue;
160174
}
175+
161176
Collection<Method> methods = targetClass.getMethods();
162177
Iterator methodIterator = methods.iterator();
163178

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@
2121
import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator;
2222
import com.magento.idea.magento2plugin.actions.generation.util.NavigateToCreatedFile;
2323
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
24+
import com.magento.idea.magento2plugin.magento.files.ComposerJson;
2425
import com.magento.idea.magento2plugin.magento.packages.Package;
2526
import com.magento.idea.magento2plugin.project.Settings;
2627
import com.magento.idea.magento2plugin.util.CamelCaseToHyphen;
28+
import org.apache.commons.lang.ArrayUtils;
2729
import org.jetbrains.annotations.NotNull;
2830
import org.jetbrains.annotations.Nullable;
2931
import javax.swing.*;
3032
import javax.swing.event.ListSelectionEvent;
3133
import javax.swing.event.ListSelectionListener;
3234
import java.awt.event.*;
35+
import java.util.ArrayList;
3336
import java.util.List;
3437
import java.util.Vector;
38+
import java.util.stream.IntStream;
3539

3640
public class NewModuleDialog extends AbstractDialog implements ListSelectionListener {
3741
@NotNull
@@ -254,7 +258,8 @@ private void setLicenses() {
254258

255259
private void setModuleDependencies() {
256260
List<String> moduleNames = moduleIndex.getModuleNames();
257-
Vector<String> licenseNames = new Vector<>(moduleNames.size());
261+
Vector<String> licenseNames = new Vector<>(moduleNames.size() + 1);
262+
licenseNames.add(ComposerJson.NO_DEPENDENCY_LABEL);
258263
for (String name : moduleNames) {
259264
licenseNames.add(name);
260265
}
@@ -263,7 +268,7 @@ private void setModuleDependencies() {
263268
moduleDependencies.addListSelectionListener(this);
264269
}
265270

266-
private void handleModuleCustomLicenseInputVisibility () {
271+
private void handleModuleCustomLicenseInputVisibility() {
267272
boolean isCustomLicenseSelected = false;
268273

269274
for (Object value: moduleLicense.getSelectedValuesList()) {
@@ -278,8 +283,18 @@ private void handleModuleCustomLicenseInputVisibility () {
278283
moduleLicenseCustom.setEditable(isCustomLicenseSelected);
279284
}
280285

286+
private void handleModuleSelectedDependencies() {
287+
// unselect the "None" dependency when others are selected
288+
int[] selectedDependencies = moduleDependencies.getSelectedIndices();
289+
if (moduleDependencies.getSelectedIndices().length > 1 && moduleDependencies.isSelectedIndex(0)) {
290+
selectedDependencies = ArrayUtils.remove(selectedDependencies, 0);
291+
moduleDependencies.setSelectedIndices(selectedDependencies);
292+
}
293+
}
294+
281295
@Override
282296
public void valueChanged(ListSelectionEvent listSelectionEvent) {
283297
handleModuleCustomLicenseInputVisibility();
298+
handleModuleSelectedDependencies();
284299
}
285300
}

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
1717
import com.magento.idea.magento2plugin.magento.files.ComposerJson;
1818
import com.magento.idea.magento2plugin.util.CamelCaseToHyphen;
19+
import com.intellij.openapi.util.Pair;
1920
import org.jetbrains.annotations.NotNull;
2021
import java.io.FileNotFoundException;
2122
import java.io.FileReader;
@@ -82,20 +83,24 @@ private String getDependenciesString(List dependenciesList) {
8283
String result = "";
8384
Object[] dependencies = dependenciesList.toArray();
8485
result = result.concat(ComposerJson.DEFAULT_DEPENDENCY);
85-
if (dependencies.length == 0) {
86+
boolean noDependency = dependencies.length == 1 && dependencies[0].equals(ComposerJson.NO_DEPENDENCY_LABEL);
87+
if (dependencies.length == 0 || noDependency) {
8688
result = result.concat("\n");
8789
} else {
8890
result = result.concat(",\n");
8991
}
9092

93+
if (noDependency) {
94+
return result;
95+
}
96+
9197
for (int i = 0; i < dependencies.length; i++) {
9298
String dependency = dependencies[i].toString();
99+
Pair<String, String> dependencyData = getDependencyData(dependency);
93100
result = result.concat("\"");
94-
result = result.concat(
95-
camelCaseToHyphen.convert(dependency).replace("_-", "/")
96-
);
101+
result = result.concat(dependencyData.getFirst());
97102
result = result.concat("\"");
98-
result = result.concat(": \"" + getDependencyVersion(dependency) + "\"");
103+
result = result.concat(": \"" + dependencyData.getSecond() + "\"");
99104

100105
if (dependencies.length != (i + 1)) {
101106
result = result.concat(",");
@@ -107,26 +112,32 @@ private String getDependenciesString(List dependenciesList) {
107112
return result;
108113
}
109114

110-
private String getDependencyVersion(String dependency) {
115+
private Pair<String, String> getDependencyData(String dependency) {
111116
String version = "*";
117+
String moduleName = camelCaseToHyphen.convert(dependency).replace("_-", "/");
112118
try {
113119
VirtualFile virtualFile = moduleIndex.getModuleDirectoryByModuleName(dependency)
114120
.findFile(ComposerJson.FILE_NAME)
115121
.getVirtualFile();
116122
if (virtualFile.exists()) {
117123
JsonElement jsonElement = new JsonParser().parse(new FileReader(virtualFile.getPath()));
118124
JsonElement versionJsonElement = jsonElement.getAsJsonObject().get("version");
125+
JsonElement nameJsonElement = jsonElement.getAsJsonObject().get("name");
119126
if (versionJsonElement != null) {
120127
version = versionJsonElement.getAsString();
121128
int minorVersionSeparator = version.lastIndexOf(".");
122129
version = new StringBuilder(version)
123130
.replace(minorVersionSeparator + 1, version.length(),"*")
124131
.toString();
125132
}
133+
if (nameJsonElement != null) {
134+
moduleName = nameJsonElement.getAsString();
135+
}
126136
}
127137
} catch (FileNotFoundException e) {
128138
// It's fine
129139
}
130-
return version;
140+
141+
return Pair.create(moduleName, version);
131142
}
132143
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
import com.magento.idea.magento2plugin.stubs.indexes.mftf.*;
1515
import com.magento.idea.magento2plugin.stubs.indexes.xml.PhpClassNameIndex;
1616

17-
/**
18-
* Created by dkvashnin on 1/9/16.
19-
*/
2017
public class IndexManager {
2118
public static void manualReindex() {
2219
ID<?, ?>[] indexIds = new ID<?, ?>[] {
@@ -49,8 +46,12 @@ public static void manualReindex() {
4946
};
5047

5148
for (ID<?, ?> id: indexIds) {
52-
FileBasedIndexImpl.getInstance().requestRebuild(id);
53-
FileBasedIndexImpl.getInstance().scheduleRebuild(id, new Throwable());
49+
try {
50+
FileBasedIndexImpl.getInstance().requestRebuild(id);
51+
FileBasedIndexImpl.getInstance().scheduleRebuild(id, new Throwable());
52+
} catch (NullPointerException exception) {
53+
//that's fine, indexer is not present in map java.util.Map.get
54+
}
5455
}
5556
}
5657
}

0 commit comments

Comments
 (0)