package fr.adrienbrault.idea.symfony2plugin.doctrine;

import com.intellij.psi.PsiReference;
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
import de.espend.idea.php.annotation.extension.PhpAnnotationReferenceProvider;
import de.espend.idea.php.annotation.extension.parameter.AnnotationPropertyParameter;
import de.espend.idea.php.annotation.extension.parameter.PhpAnnotationReferenceProviderParameter;
import fr.adrienbrault.idea.symfony2plugin.doctrine.EntityReference;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import org.jetbrains.annotations.Nullable;

public class DoctrineAnnotationTargetEntityReferences implements PhpAnnotationReferenceProvider {
    @Nullable
    @Override
    public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter phpAnnotationReferenceProviderParameter) {


        if(!(annotationPropertyParameter.getElement() instanceof StringLiteralExpression) || !PhpElementsUtil.isEqualClassName(annotationPropertyParameter.getPhpClass(),
            "\\Doctrine\\ORM\\Mapping\\ManyToOne",
            "\\Doctrine\\ORM\\Mapping\\ManyToMany",
            "\\Doctrine\\ORM\\Mapping\\OneToOne",
            "\\Doctrine\\ORM\\Mapping\\OneToMany")
            )
        {
            return new PsiReference[0];
        }


        if(!(annotationPropertyParameter.getElement() instanceof StringLiteralExpression) || !PhpElementsUtil.isEqualClassName(annotationPropertyParameter.getPhpClass(),
            "\\Doctrine\\ORM\\Mapping\\ManyToOne",
            "\\Doctrine\\ORM\\Mapping\\ManyToMany",
            "\\Doctrine\\ORM\\Mapping\\OneToOne",
            "\\Doctrine\\ORM\\Mapping\\OneToMany")
            )
        {
            return new PsiReference[0];
        }

        // @Foo(targetEntity="Foo\Class")
        if(annotationPropertyParameter.getType() == AnnotationPropertyParameter.Type.PROPERTY_VALUE || "targetEntity".equals(annotationPropertyParameter.getPropertyName())) {
            return new PsiReference[]{ new EntityReference((StringLiteralExpression) annotationPropertyParameter.getElement(), true) };
        }

        return new PsiReference[0];
    }

}

@@ -914,459 +914,8 @@
  %7B%0A%0A
-%0A        if(!(annotationPropertyParameter.getElement() instanceof StringLiteralExpression) %7C%7C !PhpElementsUtil.isEqualClassName(annotationPropertyParameter.getPhpClass(),%0A            %22%5C%5CDoctrine%5C%5CORM%5C%5CMapping%5C%5CManyToOne%22,%0A            %22%5C%5CDoctrine%5C%5CORM%5C%5CMapping%5C%5CManyToMany%22,%0A            %22%5C%5CDoctrine%5C%5CORM%5C%5CMapping%5C%5COneToOne%22,%0A            %22%5C%5CDoctrine%5C%5CORM%5C%5CMapping%5C%5COneToMany%22)%0A            )%0A        %7B%0A            return new PsiReference%5B0%5D;%0A        %7D%0A%0A%0A
     

remove duplicate code