Skip to content

Commit 68d498f

Browse files
Enhanced the built-in UCT architecture
1 parent 8e4461e commit 68d498f

25 files changed

+631
-200
lines changed

resources/META-INF/plugin.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,19 @@
260260
level="WARNING"
261261
implementationClass="com.magento.idea.magento2uct.inspections.php.deprecation.ExtendingDeprecatedClass"/>
262262
<localInspection language="PHP" groupPath="UCT"
263-
shortName="ImportingDeprecatedType"
264-
bundle="uct.bundle.inspection" key="inspection.displayName.ImportingDeprecatedType"
263+
shortName="ImportingDeprecatedClass"
264+
bundle="uct.bundle.inspection" key="inspection.displayName.ImportingDeprecatedClass"
265265
groupBundle="uct.bundle.inspection" groupKey="inspection.deprecation.group.name"
266266
enabledByDefault="true"
267267
level="WARNING"
268-
implementationClass="com.magento.idea.magento2uct.inspections.php.deprecation.ImportingDeprecatedType"/>
268+
implementationClass="com.magento.idea.magento2uct.inspections.php.deprecation.ImportingDeprecatedClass"/>
269+
<localInspection language="PHP" groupPath="UCT"
270+
shortName="ImportingDeprecatedInterface"
271+
bundle="uct.bundle.inspection" key="inspection.displayName.ImportingDeprecatedInterface"
272+
groupBundle="uct.bundle.inspection" groupKey="inspection.deprecation.group.name"
273+
enabledByDefault="true"
274+
level="WARNING"
275+
implementationClass="com.magento.idea.magento2uct.inspections.php.deprecation.ImportingDeprecatedInterface"/>
269276
<!-- \UCT inspection -->
270277

271278
<internalFileTemplate name="Magento Composer JSON"/>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<body>
3+
<p>[1132] Importing Adobe Commerce @deprecated class: The extended class will be removed in upcoming versions. Consider using Adobe Commerce class marked as @api instead.</p>
4+
<!-- tooltip end -->
5+
<p>Text after this comment will only be shown in the settings of the inspection.</p>
6+
</body>
7+
</html>

resources/inspectionDescriptions/ImportingDeprecatedType.html renamed to resources/inspectionDescriptions/ImportingDeprecatedInterface.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<html>
22
<body>
3-
<p>[1132] Importing Adobe Commerce @deprecated class: The extended class will be removed in upcoming versions. Consider using Adobe Commerce class marked as @api instead.</p>
43
<p>[1332] Imported Adobe Commerce @deprecated interface: The deprecated interface will be removed in upcoming versions. Consider using an interface or class marked as @api instead.</p>
54
<!-- tooltip end -->
65
<p>Text after this comment will only be shown in the settings of the inspection.</p>

resources/uct/bundle/inspection.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
inspection.deprecation.group.name=Deprecation Inspections
22
inspection.displayName.ExtendingDeprecatedClass=Extending from Adobe Commerce @deprecated class
3-
inspection.displayName.ImportingDeprecatedType=Importing Adobe Commerce @deprecated class/interface
3+
inspection.displayName.ImportingDeprecatedClass=Importing Adobe Commerce @deprecated class
4+
inspection.displayName.ImportingDeprecatedInterface=Importing Adobe Commerce @deprecated interface
45
customCode.warnings.deprecated.1131=[1131] Extending from @deprecated class ''{0}''
56
customCode.warnings.deprecated.1132=[1132] Importing @deprecated class ''{0}''
67
customCode.warnings.deprecated.1133=[1133] Loading Adobe Commerce @deprecated class {0} in {1}. The extended class will be removed in upcoming versions. Consider using Adobe Commerce class marked as @api instead.

src/com/magento/idea/magento2uct/actions/ReindexVersionedIndexesAction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
import com.intellij.psi.PsiDirectory;
1616
import com.intellij.psi.PsiFile;
1717
import com.magento.idea.magento2plugin.project.Settings;
18-
import com.magento.idea.magento2uct.versioning.IndexRegistry;
18+
import com.magento.idea.magento2uct.execution.scanner.ModuleFilesScanner;
19+
import com.magento.idea.magento2uct.execution.scanner.ModuleScanner;
20+
import com.magento.idea.magento2uct.execution.scanner.data.ComponentData;
21+
import com.magento.idea.magento2uct.packages.IndexRegistry;
1922
import com.magento.idea.magento2uct.versioning.IndexRepository;
2023
import com.magento.idea.magento2uct.versioning.processors.DeprecationIndexProcessor;
21-
import com.magento.idea.magento2uct.versioning.scanner.ModuleFilesScanner;
22-
import com.magento.idea.magento2uct.versioning.scanner.ModuleScanner;
23-
import com.magento.idea.magento2uct.versioning.scanner.data.ComponentData;
2424
import java.util.HashMap;
2525
import java.util.Map;
2626
import org.jetbrains.annotations.NotNull;

src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java

Lines changed: 86 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import com.intellij.codeInspection.InspectionManager;
99
import com.intellij.codeInspection.ProblemDescriptor;
10-
import com.intellij.codeInspection.ProblemsHolder;
1110
import com.intellij.openapi.project.Project;
1211
import com.intellij.openapi.vfs.VfsUtil;
1312
import com.intellij.openapi.vfs.VirtualFile;
@@ -23,21 +22,19 @@
2322
import com.jetbrains.php.lang.psi.elements.PhpPsiElement;
2423
import com.jetbrains.php.lang.psi.elements.PhpUseList;
2524
import com.jetbrains.php.lang.psi.resolve.types.PhpTypeAnalyserVisitor;
26-
import com.jetbrains.php.lang.psi.visitors.PhpElementVisitor;
2725
import com.magento.idea.magento2plugin.util.GetFirstClassOfFile;
2826
import com.magento.idea.magento2uct.execution.process.OutputWrapper;
27+
import com.magento.idea.magento2uct.execution.scanner.ModuleFilesScanner;
28+
import com.magento.idea.magento2uct.execution.scanner.ModuleScanner;
29+
import com.magento.idea.magento2uct.execution.scanner.data.ComponentData;
30+
import com.magento.idea.magento2uct.inspections.UctInspectionManager;
31+
import com.magento.idea.magento2uct.inspections.UctProblemsHolder;
2932
import com.magento.idea.magento2uct.inspections.php.DeprecationInspection;
33+
import com.magento.idea.magento2uct.packages.SupportedIssue;
3034
import java.io.File;
3135
import java.nio.file.Paths;
3236
import java.util.ArrayList;
3337
import java.util.List;
34-
35-
import com.magento.idea.magento2uct.inspections.php.deprecation.ExtendingDeprecatedClass;
36-
import com.magento.idea.magento2uct.inspections.php.deprecation.ImportingDeprecatedType;
37-
import com.magento.idea.magento2uct.versioning.processors.DeprecationIndexProcessor;
38-
import com.magento.idea.magento2uct.versioning.scanner.ModuleFilesScanner;
39-
import com.magento.idea.magento2uct.versioning.scanner.ModuleScanner;
40-
import com.magento.idea.magento2uct.versioning.scanner.data.ComponentData;
4138
import org.jetbrains.annotations.NotNull;
4239

4340
public class GenerateUctReportCommand {
@@ -63,6 +60,8 @@ public GenerateUctReportCommand(
6360
*/
6461
public void execute() {
6562
output.write("Upgrade compatibility tool\n\n");
63+
final UctInspectionManager inspectionManager = new UctInspectionManager(project);
64+
final UctReportOutputUtil outputUtil = new UctReportOutputUtil(output);
6665

6766
for (final ComponentData componentData : new ModuleScanner(getTargetPsiDirectory())) {
6867
boolean isModuleHeaderPrinted = false;
@@ -71,94 +70,31 @@ public void execute() {
7170
if (!(psiFile instanceof PhpFile)) {
7271
continue;
7372
}
74-
final PhpClass phpClass =
75-
GetFirstClassOfFile
76-
.getInstance()
77-
.execute((PhpFile) psiFile);
78-
79-
if (phpClass != null) {
80-
final ExtendingDeprecatedClass extendingDeprecatedClass =
81-
new ExtendingDeprecatedClass();
82-
final ProblemsHolder extendingDeprecatedClassProblemsHolder = new ProblemsHolder(
83-
InspectionManager.getInstance(project),
84-
psiFile,
85-
false
86-
);
87-
final PhpElementVisitor extendingDeprecatedClassVisitor =
88-
(PhpElementVisitor) extendingDeprecatedClass.buildVisitor(
89-
extendingDeprecatedClassProblemsHolder,
90-
false
91-
);
92-
extendingDeprecatedClassVisitor.visitPhpClass(phpClass);
93-
94-
final ImportingDeprecatedType importingDeprecatedType =
95-
new ImportingDeprecatedType();
96-
final ProblemsHolder importingDeprecatedTypeProblemsHolder = new ProblemsHolder(
97-
InspectionManager.getInstance(project),
98-
psiFile,
99-
false
100-
);
101-
final PhpElementVisitor importingDeprecatedTypeVisitor =
102-
(PhpElementVisitor) importingDeprecatedType.buildVisitor(
103-
importingDeprecatedTypeProblemsHolder,
104-
false
105-
);
106-
importingDeprecatedTypeVisitor.visitPhpClass(phpClass);
107-
108-
final PhpPsiElement scopeForUseOperator =
109-
PhpCodeInsightUtil.findScopeForUseOperator(phpClass);
110-
111-
if (scopeForUseOperator != null) {
112-
final List<PhpUseList> imports =
113-
PhpCodeInsightUtil.collectImports(scopeForUseOperator);
114-
115-
for (final PhpUseList phpUseList : imports) {
116-
importingDeprecatedTypeVisitor.visitPhpUseList(phpUseList);
117-
}
118-
}
73+
final UctProblemsHolder fileProblemsHolder = inspectionManager.run(psiFile);
11974

120-
if (extendingDeprecatedClassProblemsHolder.hasResults()
121-
|| importingDeprecatedTypeProblemsHolder.hasResults()) {
122-
if (!isModuleHeaderPrinted) {
123-
final String moduleName = "Module Name: ".concat(componentData.getName());
124-
output.print("<info>" + moduleName + "</info>\n");
125-
output.print("<info>" + "-".repeat(moduleName.length()) + "</info>\n\n");
126-
isModuleHeaderPrinted = true;
127-
}
128-
129-
final String file = "File: " + psiFile.getVirtualFile().getPath();
130-
output.print("<info>" + file + "</info>\n");
131-
output.print("<info>" + "-".repeat(file.length()) + "</info>\n\n");
132-
}
75+
if (fileProblemsHolder == null) {
76+
continue;
77+
}
13378

134-
// temporary output
135-
for (final ProblemDescriptor descriptor
136-
: extendingDeprecatedClassProblemsHolder.getResults()) {
137-
printErrorMessage(descriptor);
79+
if (fileProblemsHolder.hasResults()) {
80+
if (!isModuleHeaderPrinted) {
81+
outputUtil.printModuleName(componentData.getName());
82+
isModuleHeaderPrinted = true;
13883
}
139-
for (final ProblemDescriptor descriptor
140-
: importingDeprecatedTypeProblemsHolder.getResults()) {
141-
printErrorMessage(descriptor);
84+
outputUtil.printProblemFile(psiFile.getVirtualFile().getPath());
85+
}
86+
87+
for (final ProblemDescriptor descriptor : fileProblemsHolder.getResults()) {
88+
final Integer code = fileProblemsHolder.getErrorCodeForDescriptor(descriptor);
89+
90+
if (code != null) {
91+
outputUtil.printIssue(descriptor, code);
14292
}
14393
}
14494
}
14595
}
14696
}
14797

148-
private void printErrorMessage(final ProblemDescriptor descriptor) {
149-
final String errorCode =
150-
descriptor.getDescriptionTemplate().substring(0, 5);
151-
final String errorMessage =
152-
descriptor.getDescriptionTemplate().substring(5).trim();
153-
154-
final String outputText = " * <warning>[WARNING]</warning>"
155-
+ errorCode + " Line "
156-
+ descriptor.getLineNumber() + ": "
157-
+ errorMessage;
158-
159-
output.print(outputText + "\n");
160-
}
161-
16298
/**
16399
* Visit directory recursively.
164100
*
@@ -176,7 +112,7 @@ private void visitDirectory(final @NotNull PsiDirectory directory) {
176112
if (phpClass != null) {
177113
final DeprecationInspection deprecationInspection =
178114
new DeprecationInspection(phpClass);
179-
final ProblemsHolder problemsHolder = new ProblemsHolder(
115+
final UctProblemsHolder problemsHolder = new UctProblemsHolder(
180116
InspectionManager.getInstance(project),
181117
phpClass.getContainingFile(),
182118
false
@@ -215,7 +151,6 @@ private void visitDirectory(final @NotNull PsiDirectory directory) {
215151
visitor.visitPhpField(field);
216152
}
217153

218-
// temporary output
219154
for (final ProblemDescriptor descriptor : problemsHolder.getResults()) {
220155
output.print(descriptor.getDescriptionTemplate());
221156
}
@@ -244,4 +179,65 @@ private PsiDirectory getTargetPsiDirectory() {
244179
.getInstance(project)
245180
.findDirectory(targetDirVirtualFile);
246181
}
182+
183+
private static final class UctReportOutputUtil {
184+
185+
private static final String ISSUE_FORMAT = " * {SEVERITY}[{code}] Line {line}: {message}";
186+
private final OutputWrapper stdout;
187+
188+
/**
189+
* UCT report styled output util.
190+
*
191+
* @param output OutputWrapper
192+
*/
193+
public UctReportOutputUtil(final @NotNull OutputWrapper output) {
194+
stdout = output;
195+
}
196+
197+
/**
198+
* Print module name header.
199+
*
200+
* @param moduleName String
201+
*/
202+
public void printModuleName(final @NotNull String moduleName) {
203+
final String moduleNameLine = "Module Name: ".concat(moduleName);
204+
stdout.print(stdout.wrapInfo(moduleNameLine).concat("\n"));
205+
stdout.print(stdout.wrapInfo("-".repeat(moduleNameLine.length())).concat("\n"));
206+
}
207+
208+
/**
209+
* Print problem file header.
210+
*
211+
* @param filePath String
212+
*/
213+
public void printProblemFile(final @NotNull String filePath) {
214+
final String file = "File: ".concat(filePath);
215+
stdout.print("\n".concat(stdout.wrapInfo(file)).concat("\n"));
216+
stdout.print(stdout.wrapInfo("-".repeat(file.length())).concat("\n\n"));
217+
}
218+
219+
/**
220+
* Print issue message.
221+
*
222+
* @param descriptor ProblemDescriptor
223+
* @param code int
224+
*/
225+
public void printIssue(final @NotNull ProblemDescriptor descriptor, final int code) {
226+
final String errorMessage = descriptor.getDescriptionTemplate().substring(6).trim();
227+
final SupportedIssue issue = SupportedIssue.getByCode(code);
228+
229+
if (issue == null) {
230+
return;
231+
}
232+
233+
final String output = ISSUE_FORMAT
234+
.replace("{SEVERITY}", issue.getLevel().getFormattedLabel())
235+
.replace("{code}", Integer.toString(code))
236+
.replace("{line}", Integer.toString(descriptor.getLineNumber() + 1))
237+
.replace("{message}", errorMessage)
238+
.concat("\n");
239+
240+
stdout.print(output);
241+
}
242+
}
247243
}

src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
import com.jetbrains.php.config.interpreters.PhpInterpreter;
2929
import com.magento.idea.magento2uct.execution.filters.UctPhpFileFilter;
3030
import com.magento.idea.magento2uct.execution.filters.UctResultFileFilter;
31+
import com.magento.idea.magento2uct.packages.IssueSeverityLevel;
3132
import com.magento.idea.magento2uct.settings.UctSettingsService;
32-
import com.magento.idea.magento2uct.util.module.UctExecutableValidatorUtil;
33+
import com.magento.idea.magento2uct.util.UctExecutableValidatorUtil;
3334
import com.magento.idea.magento2uct.util.module.UctModulePathValidatorUtil;
34-
import com.magento.idea.magento2uct.versioning.IssueSeverityLevel;
3535
import org.jetbrains.annotations.NotNull;
3636
import org.jetbrains.annotations.Nullable;
3737

src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
import com.magento.idea.magento2plugin.MagentoIcons;
2121
import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData;
2222
import com.magento.idea.magento2uct.execution.DownloadUctCommand;
23+
import com.magento.idea.magento2uct.packages.IssueSeverityLevel;
24+
import com.magento.idea.magento2uct.packages.SupportedVersion;
2325
import com.magento.idea.magento2uct.settings.UctSettingsService;
24-
import com.magento.idea.magento2uct.util.module.UctExecutableValidatorUtil;
26+
import com.magento.idea.magento2uct.util.UctExecutableValidatorUtil;
2527
import com.magento.idea.magento2uct.util.module.UctModuleLocatorUtil;
26-
import com.magento.idea.magento2uct.versioning.IssueSeverityLevel;
27-
import com.magento.idea.magento2uct.versioning.SupportedVersion;
2828
import java.awt.Color;
2929
import java.awt.Container;
3030
import java.net.URI;

0 commit comments

Comments
 (0)