Skip to content

Commit 24f534a

Browse files
authored
Merge pull request #2366 from Haehnchen/feature/inspection-language
provide inspection language attributes for deprecated class and controller method inspections
2 parents c28c265 + 6c7f156 commit 24f534a

File tree

9 files changed

+256
-176
lines changed

9 files changed

+256
-176
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/codeInspection/service/ServiceDeprecatedClassesInspection.java

Lines changed: 137 additions & 102 deletions
Large diffs are not rendered by default.

src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/inspection/ControllerMethodInspection.java

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import com.intellij.codeInspection.LocalInspectionTool;
44
import com.intellij.codeInspection.ProblemsHolder;
5-
import com.intellij.lang.Language;
6-
import com.intellij.lang.xml.XMLLanguage;
75
import com.intellij.psi.PsiElement;
86
import com.intellij.psi.PsiElementVisitor;
97
import com.intellij.psi.util.PsiTreeUtil;
@@ -18,90 +16,90 @@
1816
import org.apache.commons.lang3.StringUtils;
1917
import org.jetbrains.annotations.NotNull;
2018
import org.jetbrains.annotations.Nullable;
21-
import org.jetbrains.yaml.YAMLLanguage;
2219
import org.jetbrains.yaml.psi.YAMLKeyValue;
2320

2421
/**
2522
* @author Daniel Espendiller <daniel@espendiller.net>
2623
*/
27-
public class ControllerMethodInspection extends LocalInspectionTool {
28-
29-
@NotNull
30-
@Override
31-
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
32-
if(!Symfony2ProjectComponent.isEnabled(holder.getProject())) {
33-
return super.buildVisitor(holder, isOnTheFly);
34-
}
24+
public class ControllerMethodInspection {
25+
public static class ControllerMethodInspectionYaml extends LocalInspectionTool {
26+
public @NotNull PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
27+
if (!Symfony2ProjectComponent.isEnabled(holder.getProject())) {
28+
return super.buildVisitor(holder, isOnTheFly);
29+
}
3530

36-
return new PsiElementVisitor() {
37-
@Override
38-
public void visitElement(@NotNull PsiElement element) {
39-
Language language = element.getLanguage();
31+
return new PsiElementVisitor() {
32+
@Override
33+
public void visitElement(@NotNull PsiElement element) {
34+
if (YamlElementPatternHelper.getSingleLineScalarKey("_controller", "controller").accepts(element)) {
35+
String text = PsiElementUtils.trimQuote(element.getText());
36+
if (StringUtils.isNotBlank(text)) {
37+
InspectionUtil.inspectController(element, text, holder, new YamlLazyRouteName(element));
38+
}
39+
}
4040

41-
if (language == YAMLLanguage.INSTANCE) {
42-
visitYamlElement(element, holder);
43-
} else if(language == XMLLanguage.INSTANCE) {
44-
visitXmlElement(element, holder);
41+
super.visitElement(element);
4542
}
46-
47-
super.visitElement(element);
48-
}
49-
};
50-
}
51-
52-
private void visitYamlElement(@NotNull PsiElement element, @NotNull ProblemsHolder holder) {
53-
if (YamlElementPatternHelper.getSingleLineScalarKey("_controller", "controller").accepts(element)) {
54-
String text = PsiElementUtils.trimQuote(element.getText());
55-
if (StringUtils.isNotBlank(text)) {
56-
InspectionUtil.inspectController(element, text, holder, new YamlLazyRouteName(element));
57-
}
43+
};
5844
}
5945
}
6046

61-
public void visitXmlElement(@NotNull PsiElement element, @NotNull ProblemsHolder holder) {
62-
if(XmlHelper.getRouteControllerPattern().accepts(element)) {
63-
String text = PsiElementUtils.trimQuote(element.getText());
64-
if(StringUtils.isNotBlank(text)) {
65-
InspectionUtil.inspectController(element, text, holder, new XmlLazyRouteName(element));
47+
public static class ControllerMethodInspectionXml extends LocalInspectionTool {
48+
public @NotNull PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
49+
if (!Symfony2ProjectComponent.isEnabled(holder.getProject())) {
50+
return super.buildVisitor(holder, isOnTheFly);
6651
}
52+
53+
return new PsiElementVisitor() {
54+
@Override
55+
public void visitElement(@NotNull PsiElement element) {
56+
if(XmlHelper.getRouteControllerPattern().accepts(element)) {
57+
String text = PsiElementUtils.trimQuote(element.getText());
58+
if(StringUtils.isNotBlank(text)) {
59+
InspectionUtil.inspectController(element, text, holder, new XmlLazyRouteName(element));
60+
}
61+
}
62+
63+
super.visitElement(element);
64+
}
65+
};
6766
}
6867
}
6968

7069
private record YamlLazyRouteName(@NotNull PsiElement psiElement) implements InspectionUtil.LazyControllerNameResolve {
7170
@Nullable
72-
@Override
73-
public String getRouteName() {
74-
YAMLKeyValue defaultKeyValue = PsiTreeUtil.getParentOfType(this.psiElement.getParent(), YAMLKeyValue.class);
75-
if (defaultKeyValue == null) {
76-
return null;
77-
}
78-
79-
YAMLKeyValue def = PsiTreeUtil.getParentOfType(defaultKeyValue, YAMLKeyValue.class);
80-
if (def == null) {
81-
return null;
82-
}
71+
@Override
72+
public String getRouteName() {
73+
YAMLKeyValue defaultKeyValue = PsiTreeUtil.getParentOfType(this.psiElement.getParent(), YAMLKeyValue.class);
74+
if (defaultKeyValue == null) {
75+
return null;
76+
}
8377

84-
return YamlHelper.getYamlKeyName(def);
78+
YAMLKeyValue def = PsiTreeUtil.getParentOfType(defaultKeyValue, YAMLKeyValue.class);
79+
if (def == null) {
80+
return null;
8581
}
82+
83+
return YamlHelper.getYamlKeyName(def);
8684
}
85+
}
8786

8887
private record XmlLazyRouteName(@NotNull PsiElement psiElement) implements InspectionUtil.LazyControllerNameResolve {
89-
9088
@Nullable
91-
@Override
92-
public String getRouteName() {
93-
XmlTag defaultTag = PsiTreeUtil.getParentOfType(this.psiElement, XmlTag.class);
94-
if (defaultTag != null) {
95-
XmlTag routeTag = PsiTreeUtil.getParentOfType(defaultTag, XmlTag.class);
96-
if (routeTag != null) {
97-
XmlAttribute id = routeTag.getAttribute("id");
98-
if (id != null) {
99-
return id.getValue();
100-
}
89+
@Override
90+
public String getRouteName() {
91+
XmlTag defaultTag = PsiTreeUtil.getParentOfType(this.psiElement, XmlTag.class);
92+
if (defaultTag != null) {
93+
XmlTag routeTag = PsiTreeUtil.getParentOfType(defaultTag, XmlTag.class);
94+
if (routeTag != null) {
95+
XmlAttribute id = routeTag.getAttribute("id");
96+
if (id != null) {
97+
return id.getValue();
10198
}
10299
}
103-
104-
return null;
105100
}
101+
102+
return null;
106103
}
104+
}
107105
}

src/main/resources/META-INF/plugin.xml

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,19 +355,47 @@
355355
implementationClass="fr.adrienbrault.idea.symfony2plugin.config.xml.inspection.XmlDuplicateParameterKeyInspection"/>
356356

357357

358-
<localInspection groupPath="Symfony" shortName="YamlControllerMethod" displayName="Missing Controller Action"
358+
<localInspection groupPath="Symfony" shortName="ControllerMethodYaml" displayName="Missing Controller Action in Yaml"
359359
groupName="Route"
360-
enabledByDefault="true" level="WARNING"
361-
implementationClass="fr.adrienbrault.idea.symfony2plugin.routing.inspection.ControllerMethodInspection"/>
360+
enabledByDefault="true"
361+
level="WARNING"
362+
language="yaml"
363+
implementationClass="fr.adrienbrault.idea.symfony2plugin.routing.inspection.ControllerMethodInspection$ControllerMethodInspectionYaml"/>
364+
365+
<localInspection groupPath="Symfony" shortName="ControllerMethodXml" displayName="Missing Controller Action in XML"
366+
groupName="Route"
367+
enabledByDefault="true"
368+
level="WARNING"
369+
language="XML"
370+
implementationClass="fr.adrienbrault.idea.symfony2plugin.routing.inspection.ControllerMethodInspection$ControllerMethodInspectionXml"/>
362371

363-
<localInspection groupPath="Symfony" shortName="YamlDeprecatedClasses" displayName="Deprecated Class"
372+
373+
<localInspection groupPath="Symfony" shortName="DeprecatedClassesYaml" displayName="Deprecated Class in Yaml"
364374
groupName="Service"
365-
enabledByDefault="true" level="WARNING"
366-
implementationClass="fr.adrienbrault.idea.symfony2plugin.codeInspection.service.ServiceDeprecatedClassesInspection"/>
375+
enabledByDefault="true"
376+
level="WARNING"
377+
language="yaml"
378+
implementationClass="fr.adrienbrault.idea.symfony2plugin.codeInspection.service.ServiceDeprecatedClassesInspection$ServiceDeprecatedClassesInspectionYaml"/>
379+
380+
<localInspection groupPath="Symfony" shortName="DeprecatedClassesXml" displayName="Deprecated Class in XML"
381+
groupName="Service"
382+
enabledByDefault="true"
383+
level="WARNING"
384+
language="XML"
385+
implementationClass="fr.adrienbrault.idea.symfony2plugin.codeInspection.service.ServiceDeprecatedClassesInspection$ServiceDeprecatedClassesInspectionXml"/>
386+
387+
<localInspection groupPath="Symfony" shortName="DeprecatedClassesPhp" displayName="Deprecated Class in PHP"
388+
groupName="Service"
389+
enabledByDefault="true"
390+
level="WARNING"
391+
language="PHP"
392+
implementationClass="fr.adrienbrault.idea.symfony2plugin.codeInspection.service.ServiceDeprecatedClassesInspection$ServiceDeprecatedClassesInspectionPhp"/>
393+
367394

368395
<localInspection groupPath="Symfony" shortName="TaggedExtendsInterfaceClass" displayName="Missing Tag extends/interface statement"
369396
groupName="Service"
370-
enabledByDefault="true" level="WARNING"
397+
enabledByDefault="true"
398+
level="WARNING"
371399
implementationClass="fr.adrienbrault.idea.symfony2plugin.codeInspection.service.TaggedExtendsInterfaceClassInspection"/>
372400

373401
<localInspection groupPath="Symfony" shortName="EventMethodCall" displayName="Create Method"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
<!-- tooltip end -->
4+
</body>
5+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
<!-- tooltip end -->
4+
</body>
5+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
<!-- tooltip end -->
4+
</body>
5+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
<!-- tooltip end -->
4+
</body>
5+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
<!-- tooltip end -->
4+
</body>
5+
</html>

src/main/resources/inspectionDescriptions/YamlDeprecatedClasses.html

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)