package com.daveme.intellij.chocolatecakephp;

import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.HashSet;

public class TemplateGotoDeclarationHandler implements GotoDeclarationHandler {

    @Nullable
    @Override
    public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
        Project project = psiElement.getProject();
        if (project == null) {
            return new PsiElement[0];
        }
        Collection<VirtualFile> files = new HashSet<>();
        System.out.println("text: "+psiElement.getText());
        if (!psiElement.getText().equals("view")) {
            return new PsiElement[0];
        }
        VirtualFile relativeFile = VfsUtil.findRelativeFile(project.getBaseDir(), "goto-test/view.php".split("/"));
        System.out.println("baseDir: "+project.getBaseDir().getCanonicalPath());
        System.out.println("relativeFile: "+relativeFile);
        if (relativeFile != null) {
            files.add(relativeFile);
            return PsiUtil.convertVirtualFilesToPsiFiles(project, files).toArray(new PsiElement[files.size()]);
        }
        System.out.println("TemplateGotoDeclarationHandler");
        return new PsiElement[0];
    }

    @Nullable
    @Override
    public String getActionText(DataContext dataContext) {
        return null;
    }
}


@@ -750,87 +750,8 @@
 ();%0A
-        if (project == null) %7B%0A            return new PsiElement%5B0%5D;%0A        %7D%0A
     

Remove unnecessary null check