Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split ContainerConstantInspection into language implementations to reduce wall time calls #2362

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,63 @@
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.lang.Language;
import com.intellij.lang.xml.XMLLanguage;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.xml.XmlText;
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.config.xml.XmlHelper;
import fr.adrienbrault.idea.symfony2plugin.dic.container.util.ServiceContainerUtil;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.yaml.YAMLLanguage;
import org.jetbrains.yaml.psi.YAMLScalar;

/**
* @author Daniel Espendiller <[email protected]>
*/
public class ContainerConstantInspection extends LocalInspectionTool {

public static final String MESSAGE = "Symfony: constant not found";

@NotNull
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
return new PsiElementVisitor() {
@Override
public void visitElement(@NotNull PsiElement element) {
Language language = element.getLanguage();
public static class MyYamlLocalInspectionTool extends LocalInspectionTool {
@Override
public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
Project project = holder.getProject();
if (!Symfony2ProjectComponent.isEnabled(project)) {
return super.buildVisitor(holder, isOnTheFly);
}

if (language == YAMLLanguage.INSTANCE) {
return new PsiElementVisitor() {
@Override
public void visitElement(@NotNull PsiElement element) {
if (element instanceof YAMLScalar yamlScalar) {
visitYamlElement(yamlScalar, holder);
}
} else if(language == XMLLanguage.INSTANCE) {
visitXmlElement(element, holder);

super.visitElement(element);
}
};
}
}

super.visitElement(element);
public static class MyXmlLocalInspectionTool extends LocalInspectionTool {
@Override
public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
Project project = holder.getProject();
if (!Symfony2ProjectComponent.isEnabled(project)) {
return super.buildVisitor(holder, isOnTheFly);
}
};

return new PsiElementVisitor() {
@Override
public void visitElement(@NotNull PsiElement element) {
visitXmlElement(element, holder);
super.visitElement(element);
}
};
}
}
private void visitYamlElement(@NotNull YAMLScalar psiElement, @NotNull ProblemsHolder holder) {

private static void visitYamlElement(@NotNull YAMLScalar psiElement, @NotNull ProblemsHolder holder) {
String textValue = psiElement.getTextValue();
if(textValue.startsWith("!php/const:")) {
String constantName = textValue.substring(11);
Expand All @@ -51,7 +69,7 @@ private void visitYamlElement(@NotNull YAMLScalar psiElement, @NotNull ProblemsH
}
}

private void visitXmlElement(@NotNull PsiElement psiElement, @NotNull ProblemsHolder holder) {
private static void visitXmlElement(@NotNull PsiElement psiElement, @NotNull ProblemsHolder holder) {
if(!XmlHelper.getArgumentValueWithTypePattern("constant").accepts(psiElement)) {
return;
}
Expand Down
15 changes: 12 additions & 3 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,19 @@
language="PHP"
implementationClass="fr.adrienbrault.idea.symfony2plugin.codeInspection.form.FormTypeAsClassConstantInspection"/>

<localInspection groupPath="Symfony" shortName="ContainerConstant" displayName="Constant not found"
<localInspection groupPath="Symfony" shortName="ContainerConstantXml" displayName="Constant not found in XML definition"
groupName="Service"
enabledByDefault="true" level="WARNING"
implementationClass="fr.adrienbrault.idea.symfony2plugin.dic.inspection.ContainerConstantInspection"/>
enabledByDefault="true"
level="WARNING"
language="XML"
implementationClass="fr.adrienbrault.idea.symfony2plugin.dic.inspection.ContainerConstantInspection$MyXmlLocalInspectionTool"/>

<localInspection groupPath="Symfony" shortName="ContainerConstantYaml" displayName="Constant not found in yaml definition"
groupName="Service"
enabledByDefault="true"
level="WARNING"
language="yaml"
implementationClass="fr.adrienbrault.idea.symfony2plugin.dic.inspection.ContainerConstantInspection$MyYamlLocalInspectionTool"/>

<localInspection groupPath="Symfony" shortName="TwigTranslationDomain" displayName="Twig: Missing translation domain"
groupName="Translation"
Expand Down
Loading