Skip to content

Commit 432e334

Browse files
author
Vitaliy Boyko
committed
Merge branch '4.3.0-develop' of github.com:magento/magento2-phpstorm-plugin into mainline-eav-attr-code-genearators
� Conflicts: � src/com/magento/idea/magento2plugin/reference/js/JsReferenceContributor.java
2 parents b0172d3 + cb76518 commit 432e334

File tree

40 files changed

+1231
-94
lines changed

40 files changed

+1231
-94
lines changed

resources/META-INF/plugin.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,50 @@
552552
enabledByDefault="false"
553553
level="WARNING"
554554
implementationClass="com.magento.idea.magento2uct.inspections.php.api.CalledNonInterfaceMethod"/>
555+
556+
<localInspection language="XML" groupPath="UCT"
557+
shortName="UsedDeprecatedTypeInConfig"
558+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedDeprecatedTypeInConfig"
559+
groupBundle="uct.bundle.inspection" groupKey="inspection.deprecation.group.name"
560+
enabledByDefault="false"
561+
level="WARNING"
562+
implementationClass="com.magento.idea.magento2uct.inspections.xml.UsedDeprecatedTypeInConfig"/>
563+
<localInspection language="XML" groupPath="UCT"
564+
shortName="UsedDeprecatedConstantInConfig"
565+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedDeprecatedConstantInConfig"
566+
groupBundle="uct.bundle.inspection" groupKey="inspection.deprecation.group.name"
567+
enabledByDefault="false"
568+
level="WARNING"
569+
implementationClass="com.magento.idea.magento2uct.inspections.xml.UsedDeprecatedConstantInConfig"/>
570+
<localInspection language="XML" groupPath="UCT"
571+
shortName="UsedDeprecatedMethodInConfig"
572+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedDeprecatedMethodInConfig"
573+
groupBundle="uct.bundle.inspection" groupKey="inspection.deprecation.group.name"
574+
enabledByDefault="false"
575+
level="WARNING"
576+
implementationClass="com.magento.idea.magento2uct.inspections.xml.UsedDeprecatedMethodInConfig"/>
577+
578+
<localInspection language="XML" groupPath="UCT"
579+
shortName="UsedNonExistentTypeInConfig"
580+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedNonExistentTypeInConfig"
581+
groupBundle="uct.bundle.inspection" groupKey="inspection.existence.group.name"
582+
enabledByDefault="false"
583+
level="ERROR"
584+
implementationClass="com.magento.idea.magento2uct.inspections.xml.UsedNonExistentTypeInConfig"/>
585+
<localInspection language="XML" groupPath="UCT"
586+
shortName="UsedNonExistentConstantInConfig"
587+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedNonExistentConstantInConfig"
588+
groupBundle="uct.bundle.inspection" groupKey="inspection.existence.group.name"
589+
enabledByDefault="false"
590+
level="ERROR"
591+
implementationClass="com.magento.idea.magento2uct.inspections.xml.UsedNonExistentConstantInConfig"/>
592+
<localInspection language="XML" groupPath="UCT"
593+
shortName="UsedNonExistentMethodInConfig"
594+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedNonExistentMethodInConfig"
595+
groupBundle="uct.bundle.inspection" groupKey="inspection.existence.group.name"
596+
enabledByDefault="false"
597+
level="ERROR"
598+
implementationClass="com.magento.idea.magento2uct.inspections.xml.UsedNonExistentMethodInConfig"/>
555599
<!-- \UCT inspection -->
556600

557601
<internalFileTemplate name="Magento Composer JSON"/>

resources/META-INF/pluginIcon.svg

Lines changed: 2 additions & 0 deletions
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var config = {
2+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html lang="en">
8+
<body>
9+
<font face="verdana" size="-1">
10+
<p>
11+
All configuration is done in the requirejs-config.js file. It has a single root object config which contains
12+
the configuration options described below. All the configuration settings are optional and are used only when required.
13+
</p>
14+
<p>
15+
Read more about requirejs-config.js in the
16+
<a href="https://devdocs.magento.com/guides/v2.4/javascript-dev-guide/javascript/requirejs.html">DevDocs</a>.
17+
</p>
18+
</font>
19+
</body>
20+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
<body>
3+
<p>[1234] Using Magento 2 @deprecated constant: consider using Magento Open Source|Adobe Commerce constant marked as @api instead.</p>
4+
<!-- tooltip end -->
5+
</body>
6+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
<body>
3+
<p>[1439] Using Magento 2 @deprecated method: this method will be removed in upcoming versions. Consider relying on methods declared in API interfaces instead.</p>
4+
<!-- tooltip end -->
5+
</body>
6+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
<body>
3+
<p>[1134] Using Magento 2 @deprecated type: consider using Magento Open Source|Adobe Commerce type marked as @api instead.</p>
4+
<!-- tooltip end -->
5+
</body>
6+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
<body>
3+
<p>[1214] The used constant is no longer present in the codebase.</p>
4+
<!-- tooltip end -->
5+
</body>
6+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
<body>
3+
<p>[1410] The used method is no longer present in the codebase.</p>
4+
<!-- tooltip end -->
5+
</body>
6+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
<body>
3+
<p>[1110] The used type is no longer present in the codebase.</p>
4+
<!-- tooltip end -->
5+
</body>
6+
</html>

resources/uct/bundle/inspection.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ inspection.displayName.ExtendedNonApiClass=Extended non Magento 2 API class
3838
inspection.displayName.InheritedNonApiInterface=Inherited non Magento 2 API interface
3939
inspection.displayName.PossibleDependencyOnImplDetails=Possible dependency on implementation details
4040
inspection.displayName.CalledNonInterfaceMethod=Called non-interface method
41+
inspection.displayName.UsedNonExistentTypeInConfig=Used non-existent Magento 2 type in the configuration file
42+
inspection.displayName.UsedDeprecatedTypeInConfig=Used deprecated Magento 2 type in the configuration file
43+
inspection.displayName.UsedDeprecatedConstantInConfig=Used deprecated Magento 2 constant in the configuration file
44+
inspection.displayName.UsedDeprecatedMethodInConfig=Used deprecated Magento 2 method in the configuration file
45+
inspection.displayName.UsedNonExistentConstantInConfig=Used non-existent Magento 2 constant in the configuration file
46+
inspection.displayName.UsedNonExistentMethodInConfig=Used non-existent Magento 2 method in the configuration file
4147
customCode.warnings.deprecated.1131=[1131] Extended class ''{0}'' that is @deprecated in the ''{1}''
4248
customCode.warnings.deprecated.1132=[1132] Imported class ''{0}'' that is @deprecated in the ''{1}''
4349
customCode.warnings.deprecated.1134=[1134] Used class ''{0}'' that is @deprecated in the ''{1}''

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@
1010
import com.intellij.openapi.vfs.VirtualFile;
1111
import com.intellij.psi.PsiFile;
1212
import com.magento.idea.magento2plugin.MagentoIcons;
13-
import com.magento.idea.magento2plugin.actions.CopyMagentoPath;
1413
import com.magento.idea.magento2plugin.actions.generation.dialog.OverrideTemplateInThemeDialog;
14+
import com.magento.idea.magento2plugin.magento.packages.OverridableFileType;
15+
import com.magento.idea.magento2plugin.magento.packages.Package;
16+
import java.util.Arrays;
1517
import org.jetbrains.annotations.NotNull;
1618

1719
public class OverrideTemplateInThemeAction extends OverrideFileInThemeAction {
1820

1921
public static final String ACTION_NAME = "Override this file in a project theme";
20-
public static final String ACTION_TEMPLATE_DESCRIPTION = "Override template in project theme";
21-
public static final String ACTION_STYLES_DESCRIPTION = "Override styles in project theme";
22-
public static final String LESS_FILE_EXTENSION = "less";
22+
public static final String ACTION_TEMPLATE_DESCRIPTION =
23+
"Override template file in project theme";
24+
public static final String ACTION_STYLES_DESCRIPTION = "Override styles file in project theme";
25+
public static final String ACTION_JS_DESCRIPTION = "Override javascript file in project theme";
2326

2427
public OverrideTemplateInThemeAction() {
2528
super(ACTION_NAME, ACTION_TEMPLATE_DESCRIPTION, MagentoIcons.MODULE);
@@ -47,11 +50,18 @@ protected boolean isOverrideAllowed(
4750
}
4851
final String fileExtension = virtualFile.getExtension();
4952

50-
if (!CopyMagentoPath.PHTML_EXTENSION.equals(fileExtension)
51-
&& !LESS_FILE_EXTENSION.equals(fileExtension)) {
53+
if (!OverridableFileType.getOverwritableFileExtensions().contains(fileExtension)) {
5254
return false;
5355
}
5456

55-
return isFileInModuleOrTheme(file, project);
57+
if (OverridableFileType.isFileJS(fileExtension)
58+
&& !virtualFile.getCanonicalPath().contains(Package.libWebRoot)
59+
&& !Arrays.asList(virtualFile.getCanonicalPath()
60+
.split(Package.V_FILE_SEPARATOR)).contains("web")) {
61+
return false;
62+
}
63+
64+
return OverridableFileType.isFileJS(fileExtension)
65+
|| isFileInModuleOrTheme(file, project);
5666
}
5767
}

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

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.intellij.openapi.project.Project;
99
import com.intellij.psi.PsiDirectory;
1010
import com.intellij.psi.PsiFile;
11-
import com.magento.idea.magento2plugin.actions.CopyMagentoPath;
1211
import com.magento.idea.magento2plugin.actions.generation.OverrideTemplateInThemeAction;
1312
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
1413
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
@@ -17,6 +16,7 @@
1716
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
1817
import com.magento.idea.magento2plugin.magento.packages.Areas;
1918
import com.magento.idea.magento2plugin.magento.packages.ComponentType;
19+
import com.magento.idea.magento2plugin.magento.packages.OverridableFileType;
2020
import com.magento.idea.magento2plugin.magento.packages.Package;
2121
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
2222
import java.awt.event.ActionEvent;
@@ -65,9 +65,12 @@ public OverrideTemplateInThemeDialog(
6565
setContentPane(contentPane);
6666
setModal(true);
6767

68-
if (CopyMagentoPath.PHTML_EXTENSION.equals(psiFile.getVirtualFile().getExtension())) {
68+
final String fileType = psiFile.getVirtualFile().getExtension();
69+
if (OverridableFileType.isFilePhtml(fileType)) {
6970
setTitle(OverrideTemplateInThemeAction.ACTION_TEMPLATE_DESCRIPTION);
70-
} else {
71+
} else if (OverridableFileType.isFileJS(fileType)) {
72+
setTitle(OverrideTemplateInThemeAction.ACTION_JS_DESCRIPTION);
73+
} else if (OverridableFileType.isFileStyle(fileType)) {
7174
setTitle(OverrideTemplateInThemeAction.ACTION_STYLES_DESCRIPTION);
7275
}
7376
getRootPane().setDefaultButton(buttonOK);
@@ -121,27 +124,37 @@ private String getTheme() {
121124
return this.theme.getSelectedItem().toString();
122125
}
123126

127+
@SuppressWarnings("PMD.CognitiveComplexity")
124128
private void fillThemeOptions() {
125129
final GetMagentoModuleUtil.MagentoModuleData moduleData =
126130
GetMagentoModuleUtil.getByContext(psiFile.getContainingDirectory(), project);
127-
128-
if (moduleData == null) {
129-
return;
130-
}
131131
String area = ""; // NOPMD
132132

133-
if (moduleData.getType().equals(ComponentType.module)) {
134-
final PsiDirectory viewDir = moduleData.getViewDir();
135-
136-
if (viewDir == null) {
133+
if (moduleData == null) {
134+
if (psiFile.getVirtualFile().getExtension()
135+
.equals(OverridableFileType.JS.getType())) {
136+
area = "base";
137+
} else {
137138
return;
138139
}
139-
final String filePath = psiFile.getVirtualFile().getPath();
140-
final String relativePath = filePath.replace(viewDir.getVirtualFile().getPath(), "");
141-
area = relativePath.split(Package.V_FILE_SEPARATOR)[1];
142140
} else {
143-
area = moduleData.getName().split(Package.V_FILE_SEPARATOR)[0];
141+
if (moduleData.getType().equals(ComponentType.module)) {
142+
final PsiDirectory viewDir = moduleData.getViewDir();
143+
144+
if (viewDir == null) {
145+
return;
146+
}
147+
final String filePath = psiFile.getVirtualFile().getPath();
148+
final String relativePath = filePath.replace(
149+
viewDir.getVirtualFile().getPath(),
150+
""
151+
);
152+
area = relativePath.split(Package.V_FILE_SEPARATOR)[1];
153+
} else {
154+
area = moduleData.getName().split(Package.V_FILE_SEPARATOR)[0];
155+
}
144156
}
157+
145158
final List<String> themeNames = new ModuleIndex(project).getEditableThemeNames();
146159

147160
for (final String themeName : themeNames) {

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

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator;
1212
import com.magento.idea.magento2plugin.bundles.ValidatorBundle;
1313
import com.magento.idea.magento2plugin.magento.packages.Areas;
14+
import com.magento.idea.magento2plugin.magento.packages.File;
1415
import com.magento.idea.magento2plugin.util.RegExUtil;
1516
import java.util.ArrayList;
1617
import java.util.Collections;
1718
import java.util.List;
1819
import java.util.regex.Pattern;
20+
import java.util.stream.Collectors;
1921

2022
@SuppressWarnings("PMD.AbstractClassWithoutAbstractMethod")
2123
public abstract class OverrideInThemeGenerator {
@@ -45,16 +47,12 @@ protected PsiDirectory getTargetDirectory(
4547
final PsiDirectory directory,
4648
final List<String> pathComponents
4749
) {
48-
PsiDirectory result = directory;
49-
PsiDirectory tempDirectory = directory;
5050
final DirectoryGenerator generator = DirectoryGenerator.getInstance();
5151

52-
for (final String directoryName : pathComponents) {
53-
result = generator.findOrCreateSubdirectory(tempDirectory, directoryName);
54-
tempDirectory = result;
55-
}
56-
57-
return result;
52+
return generator.findOrCreateSubdirectories(
53+
directory,
54+
pathComponents.stream().collect(Collectors.joining(File.separator))
55+
);
5856
}
5957

6058
/**
@@ -97,11 +95,42 @@ protected List<String> getThemePathComponents(final PsiFile file) {
9795
final Pattern pattern = Pattern.compile(RegExUtil.Magento.MODULE_NAME);
9896

9997
PsiDirectory parent = file.getParent();
100-
do {
98+
boolean isLib = true;
99+
for (final String filePart : parent.toString().split("/")) {
100+
if (Pattern.matches(String.valueOf(pattern), filePart)) {
101+
isLib = false;
102+
}
103+
}
104+
105+
if (isLib) {
106+
pathComponents.addAll(getLibPathComponets(file));
107+
} else {
108+
do {
109+
pathComponents.add(parent.getName());
110+
parent = parent.getParent();
111+
} while (!pattern.matcher(parent.getName()).find());
112+
pathComponents.add(parent.getName());
113+
Collections.reverse(pathComponents);
114+
}
115+
116+
return pathComponents;
117+
}
118+
119+
/**
120+
* Get file path to lib.
121+
*
122+
* @param file PsiFile
123+
* @return List
124+
*/
125+
protected List<String> getLibPathComponets(final PsiFile file) {
126+
final List<String> pathComponents = new ArrayList<>();
127+
PsiDirectory parent = file.getParent();
128+
129+
while (!"web".equals(parent.getName())) {
101130
pathComponents.add(parent.getName());
102131
parent = parent.getParent();
103-
} while (!pattern.matcher(parent.getName()).find());
104-
pathComponents.add(parent.getName());
132+
}
133+
pathComponents.add("web");
105134
Collections.reverse(pathComponents);
106135

107136
return pathComponents;

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.maddyhome.idea.copyright.actions.UpdateCopyrightProcessor;
1616
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
1717
import com.magento.idea.magento2plugin.magento.packages.ComponentType;
18+
import com.magento.idea.magento2plugin.magento.packages.OverridableFileType;
1819
import com.magento.idea.magento2plugin.util.magento.GetComponentNameByDirectoryUtil;
1920
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
2021
import java.util.List;
@@ -40,24 +41,29 @@ public void execute(final PsiFile baseFile, final String themeName) {
4041

4142
final GetMagentoModuleUtil.MagentoModuleData moduleData =
4243
GetMagentoModuleUtil.getByContext(baseFile.getContainingDirectory(), project);
44+
List<String> pathComponents;
4345

4446
if (moduleData == null) {
45-
return;
46-
}
47-
48-
List<String> pathComponents;
49-
if (moduleData.getType().equals(ComponentType.module)) {
50-
pathComponents = getModulePathComponents(
51-
baseFile,
52-
GetComponentNameByDirectoryUtil.execute(
53-
baseFile.getContainingDirectory(),
54-
project
55-
)
56-
);
57-
} else if (moduleData.getType().equals(ComponentType.theme)) {
58-
pathComponents = getThemePathComponents(baseFile);
47+
if (baseFile.getVirtualFile().getExtension().equals(OverridableFileType.JS.getType())) {
48+
pathComponents = getLibPathComponets(baseFile);
49+
} else {
50+
return;
51+
}
5952
} else {
60-
return;
53+
54+
if (moduleData.getType().equals(ComponentType.module)) {
55+
pathComponents = getModulePathComponents(
56+
baseFile,
57+
GetComponentNameByDirectoryUtil.execute(
58+
baseFile.getContainingDirectory(),
59+
project
60+
)
61+
);
62+
} else if (moduleData.getType().equals(ComponentType.theme)) {
63+
pathComponents = getThemePathComponents(baseFile);
64+
} else {
65+
return;
66+
}
6167
}
6268

6369
final ModuleIndex moduleIndex = new ModuleIndex(project);

0 commit comments

Comments
 (0)