package fr.adrienbrault.idea.symfony2plugin.routing;

import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiReferenceBase;
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Adrien Brault <adrien.brault@gmail.com>
 */
public class RouteReference extends PsiReferenceBase<PsiElement> implements PsiReference {

    private String routeName;

    public RouteReference(@NotNull StringLiteralExpression element) {
        super(element);

        routeName = element.getText().substring(
            element.getValueRange().getStartOffset(),
            element.getValueRange().getEndOffset()
        ); // Remove quotes
    }

    @Nullable
    @Override
    public PsiElement resolve() {
        return null;
    }

    @NotNull
    @Override
    public Object[] getVariants() {
        Symfony2ProjectComponent symfony2ProjectComponent = getElement().getProject().getComponent(Symfony2ProjectComponent.class);
        Map<String,Route> routes = symfony2ProjectComponent.getRoutes();

        List<LookupElement> lookupElements = new ArrayList<LookupElement>();
        for (Route route : routes.values()) {
            lookupElements.add(new RouteLookupElement(route));
        }

        return lookupElements.toArray();
    }
}

@@ -129,98 +129,9 @@
 psi.
-PsiElement;%0Aimport com.intellij.psi.PsiReference;%0Aimport com.intellij.psi.PsiReferenceBase
+*
 ;%0Aim
@@ -559,24 +559,35 @@
 plements Psi
+PolyVariant
 Reference %7B%0A
@@ -712,25 +712,24 @@
 ement);%0A
-%0A
         
 routeNam
@@ -720,16 +720,21 @@
         
+this.
 routeNam
@@ -752,158 +752,445 @@
 .get
-Text().substring(%0A            element.getValueRange().getStartOffset(),%0A            element.getValueRange().getEndOffset()%0A        ); // Remove quotes
+Contents();%0A    %7D%0A%0A    @NotNull%0A    @Override%0A    public ResolveResult%5B%5D multiResolve(boolean incompleteCode) %7B%0A        List%3CResolveResult%3E results = new ArrayList%3CResolveResult%3E();%0A%0A        for (PsiElement psiElement : RouteHelper.getMethods(this.getElement().getProject(), this.routeName)) %7B%0A            results.add(new PsiElementResolveResult(psiElement));%0A        %7D%0A%0A        return results.toArray(new ResolveResult%5Bresults.size()%5D);
 %0A   

implement multiResolve for RouteReference