|
8 | 8 | import com.intellij.codeInspection.ProblemHighlightType;
|
9 | 9 | import com.intellij.codeInspection.ProblemsHolder;
|
10 | 10 | import com.intellij.openapi.project.Project;
|
11 |
| -import com.intellij.psi.PsiElement; |
12 |
| -import com.intellij.psi.PsiElementVisitor; |
13 |
| -import com.jetbrains.php.lang.inspections.PhpInspection; |
14 | 11 | import com.jetbrains.php.lang.psi.elements.ClassConstantReference;
|
| 12 | +import com.jetbrains.php.lang.psi.elements.Field; |
| 13 | +import com.jetbrains.php.lang.psi.elements.FieldReference; |
15 | 14 | import com.jetbrains.php.lang.psi.elements.PhpClass;
|
16 | 15 | import com.jetbrains.php.lang.psi.elements.impl.ClassConstImpl;
|
17 |
| -import com.jetbrains.php.lang.psi.visitors.PhpElementVisitor; |
18 | 16 | import com.magento.idea.magento2uct.inspections.UctProblemsHolder;
|
| 17 | +import com.magento.idea.magento2uct.inspections.php.UsedFieldInspection; |
| 18 | +import com.magento.idea.magento2uct.packages.IssueSeverityLevel; |
19 | 19 | import com.magento.idea.magento2uct.packages.SupportedIssue;
|
20 |
| -import com.magento.idea.magento2uct.settings.UctSettingsService; |
21 | 20 | import com.magento.idea.magento2uct.versioning.VersionStateManager;
|
22 | 21 | import org.jetbrains.annotations.NotNull;
|
23 | 22 |
|
24 |
| -public class UsingDeprecatedConstant extends PhpInspection { |
| 23 | +public class UsingDeprecatedConstant extends UsedFieldInspection { |
25 | 24 |
|
26 | 25 | @Override
|
27 |
| - public @NotNull PsiElementVisitor buildVisitor( |
| 26 | + protected void execute( |
| 27 | + final Project project, |
28 | 28 | final @NotNull ProblemsHolder problemsHolder,
|
29 |
| - final boolean isOnTheFly |
| 29 | + final Field field, |
| 30 | + final FieldReference fieldReference |
30 | 31 | ) {
|
31 |
| - return new PhpElementVisitor() { |
| 32 | + } |
32 | 33 |
|
33 |
| - @Override |
34 |
| - public void visitPhpClassConstantReference( |
35 |
| - final ClassConstantReference constantReference |
36 |
| - ) { |
37 |
| - final Project project = constantReference.getProject(); |
38 |
| - final UctSettingsService settings = UctSettingsService.getInstance(project); |
| 34 | + @Override |
| 35 | + protected void execute( |
| 36 | + final Project project, |
| 37 | + final @NotNull ProblemsHolder problemsHolder, |
| 38 | + final ClassConstImpl constant, |
| 39 | + final ClassConstantReference constantReference |
| 40 | + ) { |
| 41 | + final String constantFqn = constant.getFQN(); |
39 | 42 |
|
40 |
| - if (!settings.isEnabled() || !settings.isIssueLevelSatisfiable( |
41 |
| - SupportedIssue.USING_DEPRECATED_CONSTANT.getLevel()) |
42 |
| - ) { |
43 |
| - return; |
44 |
| - } |
45 |
| - final PsiElement element = constantReference.resolve(); |
| 43 | + if (!VersionStateManager.getInstance(project).isDeprecated(constantFqn)) { |
| 44 | + return; |
| 45 | + } |
| 46 | + final PhpClass containingClass = constant.getContainingClass(); |
46 | 47 |
|
47 |
| - if (!(element instanceof ClassConstImpl)) { |
48 |
| - return; |
49 |
| - } |
50 |
| - final String constantClass = ((ClassConstImpl) element).getFQN(); |
| 48 | + if (containingClass == null) { |
| 49 | + return; |
| 50 | + } |
51 | 51 |
|
52 |
| - if (!VersionStateManager.getInstance(project).isDeprecated(constantClass)) { |
53 |
| - return; |
54 |
| - } |
55 |
| - final PhpClass containingClass = ((ClassConstImpl) element).getContainingClass(); |
| 52 | + if (problemsHolder instanceof UctProblemsHolder) { |
| 53 | + ((UctProblemsHolder) problemsHolder).setReservedErrorCode( |
| 54 | + SupportedIssue.USING_DEPRECATED_CONSTANT.getCode() |
| 55 | + ); |
| 56 | + } |
| 57 | + problemsHolder.registerProblem( |
| 58 | + constantReference, |
| 59 | + SupportedIssue.USING_DEPRECATED_CONSTANT.getMessage( |
| 60 | + containingClass.getFQN().concat("::").concat(constant.getName()) |
| 61 | + ), |
| 62 | + ProblemHighlightType.LIKE_DEPRECATED |
| 63 | + ); |
| 64 | + } |
56 | 65 |
|
57 |
| - if (containingClass == null) { |
58 |
| - return; |
59 |
| - } |
60 |
| - if (problemsHolder instanceof UctProblemsHolder) { |
61 |
| - ((UctProblemsHolder) problemsHolder).setReservedErrorCode( |
62 |
| - SupportedIssue.USING_DEPRECATED_CONSTANT.getCode() |
63 |
| - ); |
64 |
| - } |
65 |
| - problemsHolder.registerProblem( |
66 |
| - constantReference, |
67 |
| - SupportedIssue.USING_DEPRECATED_CONSTANT.getMessage( |
68 |
| - containingClass.getFQN() |
69 |
| - .concat("::") |
70 |
| - .concat(((ClassConstImpl) element).getName()) |
71 |
| - ), |
72 |
| - ProblemHighlightType.LIKE_DEPRECATED |
73 |
| - ); |
74 |
| - } |
75 |
| - }; |
| 66 | + @Override |
| 67 | + protected IssueSeverityLevel getSeverityLevel() { |
| 68 | + return SupportedIssue.USING_DEPRECATED_CONSTANT.getLevel(); |
76 | 69 | }
|
77 | 70 | }
|
0 commit comments