-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2362 from Haehnchen/feature/constant-inspection-l…
…anguage split ContainerConstantInspection into language implementations to reduce wall time calls
- Loading branch information
Showing
2 changed files
with
47 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters