Skip to content

Commit f485517

Browse files
committed
split ContainerConstantInspection into language implementations to reduce wall time calls
1 parent 92500f3 commit f485517

File tree

2 files changed

+47
-20
lines changed

2 files changed

+47
-20
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/inspection/ContainerConstantInspection.java

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,63 @@
33
import com.intellij.codeInspection.LocalInspectionTool;
44
import com.intellij.codeInspection.ProblemHighlightType;
55
import com.intellij.codeInspection.ProblemsHolder;
6-
import com.intellij.lang.Language;
7-
import com.intellij.lang.xml.XMLLanguage;
6+
import com.intellij.openapi.project.Project;
87
import com.intellij.psi.PsiElement;
98
import com.intellij.psi.PsiElementVisitor;
109
import com.intellij.psi.xml.XmlText;
10+
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
1111
import fr.adrienbrault.idea.symfony2plugin.config.xml.XmlHelper;
1212
import fr.adrienbrault.idea.symfony2plugin.dic.container.util.ServiceContainerUtil;
1313
import org.apache.commons.lang3.StringUtils;
1414
import org.jetbrains.annotations.NotNull;
15-
import org.jetbrains.yaml.YAMLLanguage;
1615
import org.jetbrains.yaml.psi.YAMLScalar;
1716

1817
/**
1918
* @author Daniel Espendiller <daniel@espendiller.net>
2019
*/
2120
public class ContainerConstantInspection extends LocalInspectionTool {
22-
2321
public static final String MESSAGE = "Symfony: constant not found";
2422

25-
@NotNull
26-
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
27-
return new PsiElementVisitor() {
28-
@Override
29-
public void visitElement(@NotNull PsiElement element) {
30-
Language language = element.getLanguage();
23+
public static class MyYamlLocalInspectionTool extends LocalInspectionTool {
24+
@Override
25+
public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
26+
Project project = holder.getProject();
27+
if (!Symfony2ProjectComponent.isEnabled(project)) {
28+
return super.buildVisitor(holder, isOnTheFly);
29+
}
3130

32-
if (language == YAMLLanguage.INSTANCE) {
31+
return new PsiElementVisitor() {
32+
@Override
33+
public void visitElement(@NotNull PsiElement element) {
3334
if (element instanceof YAMLScalar yamlScalar) {
3435
visitYamlElement(yamlScalar, holder);
3536
}
36-
} else if(language == XMLLanguage.INSTANCE) {
37-
visitXmlElement(element, holder);
37+
38+
super.visitElement(element);
3839
}
40+
};
41+
}
42+
}
3943

40-
super.visitElement(element);
44+
public static class MyXmlLocalInspectionTool extends LocalInspectionTool {
45+
@Override
46+
public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
47+
Project project = holder.getProject();
48+
if (!Symfony2ProjectComponent.isEnabled(project)) {
49+
return super.buildVisitor(holder, isOnTheFly);
4150
}
42-
};
51+
52+
return new PsiElementVisitor() {
53+
@Override
54+
public void visitElement(@NotNull PsiElement element) {
55+
visitXmlElement(element, holder);
56+
super.visitElement(element);
57+
}
58+
};
59+
}
4360
}
44-
private void visitYamlElement(@NotNull YAMLScalar psiElement, @NotNull ProblemsHolder holder) {
61+
62+
private static void visitYamlElement(@NotNull YAMLScalar psiElement, @NotNull ProblemsHolder holder) {
4563
String textValue = psiElement.getTextValue();
4664
if(textValue.startsWith("!php/const:")) {
4765
String constantName = textValue.substring(11);
@@ -51,7 +69,7 @@ private void visitYamlElement(@NotNull YAMLScalar psiElement, @NotNull ProblemsH
5169
}
5270
}
5371

54-
private void visitXmlElement(@NotNull PsiElement psiElement, @NotNull ProblemsHolder holder) {
72+
private static void visitXmlElement(@NotNull PsiElement psiElement, @NotNull ProblemsHolder holder) {
5573
if(!XmlHelper.getArgumentValueWithTypePattern("constant").accepts(psiElement)) {
5674
return;
5775
}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,19 @@
434434
language="PHP"
435435
implementationClass="fr.adrienbrault.idea.symfony2plugin.codeInspection.form.FormTypeAsClassConstantInspection"/>
436436

437-
<localInspection groupPath="Symfony" shortName="ContainerConstant" displayName="Constant not found"
437+
<localInspection groupPath="Symfony" shortName="ContainerConstantXml" displayName="Constant not found in XML definition"
438438
groupName="Service"
439-
enabledByDefault="true" level="WARNING"
440-
implementationClass="fr.adrienbrault.idea.symfony2plugin.dic.inspection.ContainerConstantInspection"/>
439+
enabledByDefault="true"
440+
level="WARNING"
441+
language="XML"
442+
implementationClass="fr.adrienbrault.idea.symfony2plugin.dic.inspection.ContainerConstantInspection$MyXmlLocalInspectionTool"/>
443+
444+
<localInspection groupPath="Symfony" shortName="ContainerConstantYaml" displayName="Constant not found in yaml definition"
445+
groupName="Service"
446+
enabledByDefault="true"
447+
level="WARNING"
448+
language="yaml"
449+
implementationClass="fr.adrienbrault.idea.symfony2plugin.dic.inspection.ContainerConstantInspection$MyYamlLocalInspectionTool"/>
441450

442451
<localInspection groupPath="Symfony" shortName="TwigTranslationDomain" displayName="Twig: Missing translation domain"
443452
groupName="Translation"

0 commit comments

Comments
 (0)