Skip to content

Commit c5818ec

Browse files
1030: Extended xml file inspection coverage
1 parent bbcabf3 commit c5818ec

15 files changed

+328
-2
lines changed

resources/META-INF/plugin.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,34 @@
558558
enabledByDefault="true"
559559
level="ERROR"
560560
implementationClass="com.magento.idea.magento2uct.inspections.xml.UsedDeprecatedTypeInConfig"/>
561+
<localInspection language="XML" groupPath="UCT"
562+
shortName="UsedDeprecatedConstantInConfig"
563+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedDeprecatedConstantInConfig"
564+
groupBundle="uct.bundle.inspection" groupKey="inspection.api.group.name"
565+
enabledByDefault="true"
566+
level="ERROR"
567+
implementationClass="com.magento.idea.magento2uct.inspections.xml.UsedDeprecatedConstantInConfig"/>
568+
<localInspection language="XML" groupPath="UCT"
569+
shortName="UsedDeprecatedMethodInConfig"
570+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedDeprecatedMethodInConfig"
571+
groupBundle="uct.bundle.inspection" groupKey="inspection.api.group.name"
572+
enabledByDefault="true"
573+
level="ERROR"
574+
implementationClass="com.magento.idea.magento2uct.inspections.xml.UsedDeprecatedMethodInConfig"/>
575+
<localInspection language="XML" groupPath="UCT"
576+
shortName="UsedNonExistentConstantInConfig"
577+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedNonExistentConstantInConfig"
578+
groupBundle="uct.bundle.inspection" groupKey="inspection.api.group.name"
579+
enabledByDefault="true"
580+
level="ERROR"
581+
implementationClass="com.magento.idea.magento2uct.inspections.xml.UsedNonExistentConstantInConfig"/>
582+
<localInspection language="XML" groupPath="UCT"
583+
shortName="UsedNonExistentMethodInConfig"
584+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedNonExistentMethodInConfig"
585+
groupBundle="uct.bundle.inspection" groupKey="inspection.api.group.name"
586+
enabledByDefault="true"
587+
level="ERROR"
588+
implementationClass="com.magento.idea.magento2uct.inspections.xml.UsedNonExistentMethodInConfig"/>
561589
<!-- \UCT inspection -->
562590

563591
<internalFileTemplate name="Magento Composer JSON"/>
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>[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>

resources/uct/bundle/inspection.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ inspection.displayName.PossibleDependencyOnImplDetails=Possible dependency on im
4040
inspection.displayName.CalledNonInterfaceMethod=Called non-interface method
4141
inspection.displayName.UsedNonExistentTypeInConfig=Used non-existent Magento 2 type in the configuration file
4242
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
4347
customCode.warnings.deprecated.1131=[1131] Extended class ''{0}'' that is @deprecated in the ''{1}''
4448
customCode.warnings.deprecated.1132=[1132] Imported class ''{0}'' that is @deprecated in the ''{1}''
4549
customCode.warnings.deprecated.1134=[1134] Used class ''{0}'' that is @deprecated in the ''{1}''

src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.intellij.psi.util.PsiTreeUtil;
1818
import com.intellij.psi.xml.XmlToken;
1919
import com.intellij.psi.xml.XmlTokenType;
20+
import com.jetbrains.php.lang.PhpLangUtil;
2021
import com.magento.idea.magento2uct.settings.UctSettingsService;
2122
import com.magento.idea.magento2uct.versioning.VersionStateManager;
2223
import java.util.ArrayList;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2uct.inspections.xml;
7+
8+
import com.intellij.codeInspection.InspectionManager;
9+
import com.intellij.codeInspection.ProblemDescriptor;
10+
import com.intellij.codeInspection.ProblemHighlightType;
11+
import com.intellij.codeInspection.ProblemsHolder;
12+
import com.intellij.psi.PsiElement;
13+
import com.magento.idea.magento2uct.inspections.UctProblemsHolder;
14+
import com.magento.idea.magento2uct.packages.SupportedIssue;
15+
import com.magento.idea.magento2uct.util.php.MagentoReferenceUtil;
16+
import com.magento.idea.magento2uct.versioning.VersionStateManager;
17+
import java.util.List;
18+
import org.jetbrains.annotations.NotNull;
19+
20+
public class UsedDeprecatedConstantInConfig extends ModuleConfigFileInspection {
21+
22+
@Override
23+
protected void doInspection(
24+
final @NotNull String fqn,
25+
final @NotNull PsiElement target,
26+
final @NotNull InspectionManager manager,
27+
final @NotNull ProblemsHolder holder,
28+
final boolean isOnTheFly,
29+
final @NotNull List<ProblemDescriptor> descriptors
30+
) {
31+
if (!MagentoReferenceUtil.isConstantReference(fqn)) {
32+
return;
33+
}
34+
if (VersionStateManager.getInstance(manager.getProject()).isDeprecated(fqn)) {
35+
final String message = SupportedIssue.USED_DEPRECATED_CONSTANT_IN_CONFIG.getMessage(
36+
fqn,
37+
VersionStateManager.getInstance(
38+
manager.getProject()
39+
).getDeprecatedInVersion(fqn)
40+
);
41+
42+
if (holder instanceof UctProblemsHolder) {
43+
((UctProblemsHolder) holder).setIssue(
44+
SupportedIssue.USED_DEPRECATED_CONSTANT_IN_CONFIG
45+
);
46+
}
47+
final ProblemDescriptor descriptor = manager.createProblemDescriptor(
48+
target,
49+
message,
50+
null,
51+
ProblemHighlightType.WARNING,
52+
isOnTheFly,
53+
false
54+
);
55+
descriptors.add(descriptor);
56+
}
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2uct.inspections.xml;
7+
8+
import com.intellij.codeInspection.InspectionManager;
9+
import com.intellij.codeInspection.ProblemDescriptor;
10+
import com.intellij.codeInspection.ProblemHighlightType;
11+
import com.intellij.codeInspection.ProblemsHolder;
12+
import com.intellij.psi.PsiElement;
13+
import com.magento.idea.magento2uct.inspections.UctProblemsHolder;
14+
import com.magento.idea.magento2uct.packages.SupportedIssue;
15+
import com.magento.idea.magento2uct.util.php.MagentoReferenceUtil;
16+
import com.magento.idea.magento2uct.versioning.VersionStateManager;
17+
import java.util.List;
18+
import org.jetbrains.annotations.NotNull;
19+
20+
public class UsedDeprecatedMethodInConfig extends ModuleConfigFileInspection {
21+
22+
@Override
23+
protected void doInspection(
24+
final @NotNull String fqn,
25+
final @NotNull PsiElement target,
26+
final @NotNull InspectionManager manager,
27+
final @NotNull ProblemsHolder holder,
28+
final boolean isOnTheFly,
29+
final @NotNull List<ProblemDescriptor> descriptors
30+
) {
31+
if (!MagentoReferenceUtil.isMethodReference(fqn)) {
32+
return;
33+
}
34+
if (VersionStateManager.getInstance(manager.getProject()).isDeprecated(fqn)) {
35+
final String message = SupportedIssue.USED_DEPRECATED_METHOD_IN_CONFIG.getMessage(
36+
fqn,
37+
VersionStateManager.getInstance(
38+
manager.getProject()
39+
).getDeprecatedInVersion(fqn)
40+
);
41+
42+
if (holder instanceof UctProblemsHolder) {
43+
((UctProblemsHolder) holder).setIssue(
44+
SupportedIssue.USED_DEPRECATED_METHOD_IN_CONFIG
45+
);
46+
}
47+
final ProblemDescriptor descriptor = manager.createProblemDescriptor(
48+
target,
49+
message,
50+
null,
51+
ProblemHighlightType.WARNING,
52+
isOnTheFly,
53+
false
54+
);
55+
descriptors.add(descriptor);
56+
}
57+
}
58+
}

src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedTypeInConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.intellij.psi.PsiElement;
1313
import com.magento.idea.magento2uct.inspections.UctProblemsHolder;
1414
import com.magento.idea.magento2uct.packages.SupportedIssue;
15+
import com.magento.idea.magento2uct.util.php.MagentoReferenceUtil;
1516
import com.magento.idea.magento2uct.versioning.VersionStateManager;
1617
import java.util.List;
1718
import org.jetbrains.annotations.NotNull;
@@ -27,6 +28,9 @@ protected void doInspection(
2728
final boolean isOnTheFly,
2829
final @NotNull List<ProblemDescriptor> descriptors
2930
) {
31+
if (MagentoReferenceUtil.isReference(fqn)) {
32+
return;
33+
}
3034
if (VersionStateManager.getInstance(manager.getProject()).isDeprecated(fqn)) {
3135
final String message = SupportedIssue.USED_DEPRECATED_TYPE_IN_CONFIG.getMessage(
3236
fqn,

0 commit comments

Comments
 (0)