Skip to content

Commit

Permalink
Merge pull request #2360 from Haehnchen/feature/route-deprecated-insp…
Browse files Browse the repository at this point in the history
…ection-language

split RouteControllerDeprecatedInspection into language implentations to reduce wall time calls
  • Loading branch information
Haehnchen authored Apr 27, 2024
2 parents cd5cfef + 99ea14f commit ce718b8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,59 @@
/**
* @author Daniel Espendiller <[email protected]>
*/
public class RouteControllerDeprecatedInspection extends LocalInspectionTool {
public class RouteControllerDeprecatedInspection {
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) {
if (XmlHelper.getRouteControllerPattern().accepts(element)) {
PsiElement parent = element.getParent();
if (parent != null) {
String text = RouteXmlReferenceContributor.getControllerText(parent);
if(text != null) {
extracted(project, element, text, holder);
}
}
}

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

return new PsiElementVisitor() {
@Override
public void visitElement(@NotNull PsiElement element) {
if (XmlHelper.getRouteControllerPattern().accepts(element)) {
PsiElement parent = element.getParent();
if (parent != null) {
String text = RouteXmlReferenceContributor.getControllerText(parent);
if(text != null) {
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);
}

return new PsiElementVisitor() {
@Override
public void visitElement(@NotNull PsiElement element) {
if(YamlElementPatternHelper.getSingleLineScalarKey("_controller", "controller").accepts(element)) {
String text = PsiElementUtils.trimQuote(element.getText());
if (StringUtils.isNotBlank(text)) {
extracted(project, element, text, holder);
}
}
} else if(YamlElementPatternHelper.getSingleLineScalarKey("_controller", "controller").accepts(element)) {
String text = PsiElementUtils.trimQuote(element.getText());
if (StringUtils.isNotBlank(text)) {
extracted(project, element, text, holder);
}
}

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

private void extracted(@NotNull Project project, @NotNull PsiElement element, String text, @NotNull ProblemsHolder holder) {
private static void extracted(@NotNull Project project, @NotNull PsiElement element, String text, @NotNull ProblemsHolder holder) {
for (PsiElement psiElement : RouteHelper.getMethodsOnControllerShortcut(project, text)) {
if (!(psiElement instanceof PhpNamedElement)) {
continue;
Expand Down
12 changes: 10 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,19 @@
language="PHP"
implementationClass="fr.adrienbrault.idea.symfony2plugin.templating.inspection.TemplateExistsAnnotationPhpAttributeLocalInspection"/>

<localInspection groupPath="Symfony" shortName="RouteControllerDeprecatedInspection" displayName="Deprecated Action"
<localInspection groupPath="Symfony" shortName="RouteControllerDeprecatedInspectionXml" displayName="Deprecated Action in XML Definition"
groupName="Route"
enabledByDefault="true"
level="WARNING"
implementationClass="fr.adrienbrault.idea.symfony2plugin.routing.RouteControllerDeprecatedInspection"/>
language="XML"
implementationClass="fr.adrienbrault.idea.symfony2plugin.routing.RouteControllerDeprecatedInspection$MyXmlLocalInspectionTool"/>

<localInspection groupPath="Symfony" shortName="RouteControllerDeprecatedInspectionYaml" displayName="Deprecated Action in yaml definition"
groupName="Route"
enabledByDefault="true"
language="yaml"
level="WARNING"
implementationClass="fr.adrienbrault.idea.symfony2plugin.routing.RouteControllerDeprecatedInspection$MyYamlLocalInspectionTool"/>

<localInspection groupPath="Symfony" shortName="ServiceNamedArgumentExistsInspection" displayName="Symfony: Argument does not exists"
groupName="Service"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<!-- tooltip end -->
</body>
</html>

0 comments on commit ce718b8

Please sign in to comment.