Skip to content

Commit 251d440

Browse files
author
Vitaliy
authored
Merge branch '1.0.0-develop' into schema-graphql-resolver-inspection--task-35
2 parents d4803e9 + 274fbd7 commit 251d440

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

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
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.intellij.icons.AllIcons;
1111
import com.intellij.psi.PsiElement;
1212
import com.intellij.psi.search.GlobalSearchScope;
13+
import com.intellij.psi.util.PsiTreeUtil;
1314
import com.intellij.util.indexing.FileBasedIndex;
1415
import com.jetbrains.php.PhpIndex;
1516
import com.jetbrains.php.lang.psi.elements.Method;
@@ -55,7 +56,7 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
5556
.create(AllIcons.Nodes.Plugin)
5657
.setTargets(results)
5758
.setTooltipText("Navigate to plugins")
58-
.createLineMarkerInfo(psiElement)
59+
.createLineMarkerInfo(PsiTreeUtil.getDeepestFirst(psiElement))
5960
);
6061
}
6162
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class ComposerJson implements ModuleFileInterface {
1111
public static String FILE_NAME = "composer.json";
1212
public static String TEMPLATE = "Magento Module Composer";
1313
public static String DEFAULT_DEPENDENCY = "\"magento/framework\": \"*\"";
14+
public static String NO_DEPENDENCY_LABEL = "None";
1415
private static ComposerJson INSTANCE = null;
1516

1617
public static ComposerJson getInstance() {

0 commit comments

Comments
 (0)