Skip to content

Commit

Permalink
Merge pull request #2256 from adrolter/feature/inspections-use-psi-refs
Browse files Browse the repository at this point in the history
Use PsiReference list to determine if "missing" inspections apply
  • Loading branch information
Haehnchen authored Dec 15, 2023
2 parents 8588227 + 03812d4 commit 7e953d1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.config.yaml.YamlElementPatternHelper;
import fr.adrienbrault.idea.symfony2plugin.dic.ServiceReference;
import fr.adrienbrault.idea.symfony2plugin.dic.container.util.ServiceContainerUtil;
import fr.adrienbrault.idea.symfony2plugin.stubs.ContainerCollectionResolver;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
Expand All @@ -19,6 +20,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.yaml.YAMLLanguage;

import java.util.Arrays;

/**
* @author Daniel Espendiller <[email protected]>
*/
Expand Down Expand Up @@ -48,7 +51,7 @@ public void visitElement(PsiElement element) {
if(element.getLanguage() == PhpLanguage.INSTANCE && element instanceof StringLiteralExpression) {
// PHP
MethodReference methodReference = PsiElementUtils.getMethodReferenceWithFirstStringParameter((StringLiteralExpression) element);
if (methodReference != null && PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, ServiceContainerUtil.SERVICE_GET_SIGNATURES)) {
if (methodReference != null && Arrays.stream(element.getReferences()).anyMatch(ref -> ref instanceof ServiceReference)) {
String serviceName = PhpElementsUtil.getFirstArgumentStringValue(methodReference);
if (StringUtils.isNotBlank(serviceName) && !hasService(serviceName)) {
holder.registerProblem(element, INSPECTION_MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.routing.PhpRouteReferenceContributor;
import fr.adrienbrault.idea.symfony2plugin.routing.Route;
import fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper;
import fr.adrienbrault.idea.symfony2plugin.util.MethodMatcher;
import fr.adrienbrault.idea.symfony2plugin.routing.RouteReference;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.Collection;

/**
Expand Down Expand Up @@ -43,16 +43,12 @@ public void visitElement(@NotNull PsiElement element) {
}

private void invoke(@NotNull String routeName, @NotNull final PsiElement element, @NotNull ProblemsHolder holder) {
MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.StringParameterMatcher(element, 0)
.withSignature(PhpRouteReferenceContributor.GENERATOR_SIGNATURES)
.match();

if(methodMatchParameter == null) {
if(Arrays.stream(element.getReferences()).noneMatch(ref -> ref instanceof RouteReference)) {
return;
}

Collection<Route> route = RouteHelper.getRoute(element.getProject(), routeName);
if(route.size() == 0) {
if(route.isEmpty()) {
holder.registerProblem(element, "Symfony: Missing Route", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new RouteGuessTypoQuickFix(routeName));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.jetbrains.php.lang.psi.elements.ParameterList;
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.config.SymfonyPhpReferenceContributor;
import fr.adrienbrault.idea.symfony2plugin.templating.inspection.TemplateCreateByNameLocalQuickFix;
import fr.adrienbrault.idea.symfony2plugin.templating.inspection.TemplateGuessTypoQuickFix;
import fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil;
Expand All @@ -21,6 +20,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;

/**
* @author Daniel Espendiller <[email protected]>
*/
Expand Down Expand Up @@ -81,7 +82,7 @@ private String getTemplateNameIfMissing(@NotNull StringLiteralExpression psiElem
return null;
}

if (!PhpElementsUtil.isMethodReferenceInstanceOf((MethodReference) methodReference, SymfonyPhpReferenceContributor.TEMPLATE_SIGNATURES)) {
if(Arrays.stream(psiElement.getReferences()).noneMatch(ref -> ref instanceof TemplateReference)) {
return null;
}

Expand Down

0 comments on commit 7e953d1

Please sign in to comment.