package com.github.letsdrink.intellijplugin;

import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReferenceContributor;
import com.intellij.psi.PsiReferenceRegistrar;
import com.jetbrains.php.lang.psi.elements.Method;
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
import org.jetbrains.annotations.NotNull;

public class ControllerPsiReferenceContributor extends PsiReferenceContributor {
    @Override
    public void registerReferenceProviders(@NotNull PsiReferenceRegistrar psiReferenceRegistrar) {
        psiReferenceRegistrar.registerReferenceProvider(PlatformPatterns.psiElement(StringLiteralExpression.class), new ControllerActionReferenceProvider() {
            @Override
            protected boolean isApplicable(PsiElement psiElement) {
                Method resourceMethod = OuzoUtils.getRouteResourceMethod(psiElement.getProject());
                Method getMethod = OuzoUtils.getRouteGetMethod(psiElement.getProject());
                Method postMethod = OuzoUtils.getRoutePostMethod(psiElement.getProject());
                Method deleteMethod = OuzoUtils.getRouteDeleteMethod(psiElement.getProject());
                Method putMethod = OuzoUtils.getRoutePutMethod(psiElement.getProject());

                return OuzoUtils.isExpectedFile(psiElement, "routes.php") &&
                        (PsiUtils.isElementTheFirstParameterInMethodCall(psiElement, resourceMethod) ||
                        PsiUtils.isElementTheNthParameterInMethodCall(psiElement, getMethod, 1) ||
                        PsiUtils.isElementTheNthParameterInMethodCall(psiElement, postMethod, 1) ||
                        PsiUtils.isElementTheNthParameterInMethodCall(psiElement, deleteMethod, 1) ||
                        PsiUtils.isElementTheNthParameterInMethodCall(psiElement, putMethod, 1));
            }
        });
    }
}
@@ -818,24 +818,152 @@
 iElement) %7B%0A
+                if (!OuzoUtils.isExpectedFile(psiElement, %22routes.php%22)) %7B%0A                    return false;%0A                %7D%0A%0A
             
@@ -1041,32 +1041,32 @@
 .getProject());%0A
-
                 
@@ -1441,87 +1441,8 @@
 urn 
-OuzoUtils.isExpectedFile(psiElement, %22routes.php%22) &&%0A                        (
 PsiU
@@ -1809,32 +1809,32 @@
 teMethod, 1) %7C%7C%0A
+
                 
@@ -1912,17 +1912,16 @@
 thod, 1)
-)
 ;%0A      

Check is correct file before checking routes.