de.espend.idea.php.annotation.extension.parameter.PhpAnnotationReferenceProviderParameter Java Examples

The following examples show how to use de.espend.idea.php.annotation.extension.parameter.PhpAnnotationReferenceProviderParameter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigEntityTypeAnnotation.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter parameter, PhpAnnotationReferenceProviderParameter phpAnnotationReferenceProviderParameter) {
    if(!isSupported(parameter)) {
        return new PsiReference[0];
    }

    String propertyName = parameter.getPropertyName();

    if("admin_permission".equalsIgnoreCase(propertyName)) {
        String contents = getContents(parameter.getElement());
        if(StringUtils.isBlank(contents)) {
            return new PsiReference[0];
        }

        return new PsiReference[] {new ContentEntityTypeAnnotation.MyPermissionPsiPolyVariantReferenceBase(parameter.getElement(), contents)};
    }

    return new PsiReference[0];
}
 
Example #2
Source File: DoctrineAnnotationTargetEntityReferences.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter phpAnnotationReferenceProviderParameter) {

    if(!Symfony2ProjectComponent.isEnabled(annotationPropertyParameter.getProject()) || !(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];
}
 
Example #3
Source File: IsGrantedAnnotationReferences.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter phpAnnotationReferenceProviderParameter) {
    Project project = annotationPropertyParameter.getProject();
    if(!Symfony2ProjectComponent.isEnabled(project) || !(annotationPropertyParameter.getElement() instanceof StringLiteralExpression) || !PhpElementsUtil.isEqualClassName(annotationPropertyParameter.getPhpClass(), IS_GRANTED_CLASS)) {
        return new PsiReference[0];
    }

    if(annotationPropertyParameter.getType() != AnnotationPropertyParameter.Type.DEFAULT) {
        return new PsiReference[0];
    }

    return new PsiReference[] {
        new VoterReference(((StringLiteralExpression) annotationPropertyParameter.getElement()))
    };
}
 
Example #4
Source File: TemplateAnnotationReferences.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter phpAnnotationReferenceProviderParameter) {

    if(!Symfony2ProjectComponent.isEnabled(annotationPropertyParameter.getProject()) || !(annotationPropertyParameter.getElement() instanceof StringLiteralExpression) || !PhpElementsUtil.isEqualClassName(annotationPropertyParameter.getPhpClass(), TwigUtil.TEMPLATE_ANNOTATION_CLASS)) {
        return new PsiReference[0];
    }

    if(annotationPropertyParameter.getType() == AnnotationPropertyParameter.Type.DEFAULT) {
        // @Foo("template.html.twig")
        return new PsiReference[]{ new TemplateReference((StringLiteralExpression) annotationPropertyParameter.getElement()) };
    } else if(annotationPropertyParameter.getType() == AnnotationPropertyParameter.Type.PROPERTY_VALUE || "template".equals(annotationPropertyParameter.getPropertyName())) {
        // @Foo(template="template.html.twig")
        return new PsiReference[]{ new TemplateReference((StringLiteralExpression) annotationPropertyParameter.getElement()) };
    }

    return new PsiReference[0];
}
 
Example #5
Source File: ClassCompletionProviderAbstract.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter parameter, PhpAnnotationReferenceProviderParameter referencesByElementParameter) {
    if(!supports(parameter)) {
        return new PsiReference[0];
    }

    PsiElement element = parameter.getElement();
    if(!(element instanceof StringLiteralExpression) || StringUtils.isBlank(((StringLiteralExpression) element).getContents())) {
        return new PsiReference[0];
    }

    return new PsiReference[] {
        new PhpClassReference((StringLiteralExpression) element)
    };
}
 
Example #6
Source File: DoctrineAnnotationFieldTypeProvider.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter referencesByElementParameter) {

    if(annotationPropertyParameter.getType() != AnnotationPropertyParameter.Type.PROPERTY_VALUE) {
        return null;
    }

    String propertyName = annotationPropertyParameter.getPropertyName();
    if(propertyName == null || !propertyName.equals("type")) {
        return null;
    }

    String presentableFQN = annotationPropertyParameter.getPhpClass().getPresentableFQN();
    if(!presentableFQN.startsWith("\\")) {
        presentableFQN = "\\" + presentableFQN;
    }

    if(!presentableFQN.equals("\\Doctrine\\ORM\\Mapping\\Column")) {
        return null;
    }

    return new PsiReference[] {
        new DoctrineColumnTypeReference((StringLiteralExpression) annotationPropertyParameter.getElement())
    };
}
 
Example #7
Source File: DoctrineAnnotationTypeProvider.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter referencesByElementParameter) {

    if(annotationPropertyParameter.getType() != AnnotationPropertyParameter.Type.PROPERTY_VALUE) {
        return null;
    }

    String propertyName = annotationPropertyParameter.getPropertyName();
    if(propertyName == null || !propertyName.equals("repositoryClass")) {
        return null;
    }

    String presentableFQN = annotationPropertyParameter.getPhpClass().getPresentableFQN();
    if(!PhpLangUtil.equalsClassNames("Doctrine\\ORM\\Mapping\\Entity", presentableFQN)) {
        return null;
    }

    return new PsiReference[] {
        new DoctrineRepositoryReference((StringLiteralExpression) annotationPropertyParameter.getElement())
    };

}
 
Example #8
Source File: AnnotationClassProvider.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter referencesByElementParameter) {

    if(annotationPropertyParameter.getType() != AnnotationPropertyParameter.Type.PROPERTY_VALUE) {
        return null;
    }

    String propertyName = annotationPropertyParameter.getPropertyName();
    if(propertyName == null || !propertyName.equals("targetEntity")) {
        return null;
    }

    return new PsiReference[] {
        new PhpClassReference((StringLiteralExpression) annotationPropertyParameter.getElement())
    };

}
 
Example #9
Source File: SymfonyAnnotationReferences.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter phpAnnotationReferenceProviderParameter) {

    if(!Symfony2ProjectComponent.isEnabled(annotationPropertyParameter.getProject()) || !(annotationPropertyParameter.getElement() instanceof StringLiteralExpression)) {
        return new PsiReference[0];
    }

    if("service".equals(annotationPropertyParameter.getPropertyName()) && PhpElementsUtil.isEqualClassName(annotationPropertyParameter.getPhpClass(), "\\Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Route")) {
        return new PsiReference[]{ new ServiceReference((StringLiteralExpression) annotationPropertyParameter.getElement(), false) };
    }

    // JMSDiExtraBundle; @TODO: provide config
    if((annotationPropertyParameter.getType() == AnnotationPropertyParameter.Type.DEFAULT || "id".equals(annotationPropertyParameter.getPropertyName())) && PhpElementsUtil.isEqualClassName(annotationPropertyParameter.getPhpClass(), "\\JMS\\DiExtraBundle\\Annotation\\Service")) {
        return new PsiReference[]{ new ServiceReference((StringLiteralExpression) annotationPropertyParameter.getElement(), false) };
    }

    if((annotationPropertyParameter.getType() == AnnotationPropertyParameter.Type.DEFAULT) && PhpElementsUtil.isEqualClassName(annotationPropertyParameter.getPhpClass(), "\\JMS\\DiExtraBundle\\Annotation\\Inject")) {
        return new PsiReference[]{ new ServiceReference((StringLiteralExpression) annotationPropertyParameter.getElement(), false) };
    }

    if("class".equals(annotationPropertyParameter.getPropertyName()) && PhpElementsUtil.isEqualClassName(annotationPropertyParameter.getPhpClass(), "\\Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\ParamConverter")) {
        return new PsiReference[]{ new PhpClassReference((StringLiteralExpression) annotationPropertyParameter.getElement(), true).setUseClasses(true).setUseInterfaces(true) };
    }

    return new PsiReference[0];
}
 
Example #10
Source File: DoctrineAnnotationFieldProvider.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter referencesByElementParameter) {

    if(annotationPropertyParameter.getType() != AnnotationPropertyParameter.Type.PROPERTY_VALUE) {
        return null;
    }

    String propertyName = annotationPropertyParameter.getPropertyName();
    if(propertyName == null || !(propertyName.equals("mappedBy") || propertyName.equals("inversedBy"))) {
        return null;
    }

    PsiElement parent = annotationPropertyParameter.getElement().getParent();

    StringLiteralExpression targetEntity = PhpElementsUtil.getChildrenOnPatternMatch(parent, AnnotationPattern.getPropertyIdentifierValue("targetEntity"));
    if(targetEntity == null) {
        return null;
    }

    PhpClass phpClass = PhpElementsUtil.getClassInsideAnnotation(targetEntity);
    if(phpClass == null) {
        return null;
    }

    return new PsiReference[] {
        new DoctrinePhpClassFieldReference((StringLiteralExpression) annotationPropertyParameter.getElement(), phpClass)
    };

}
 
Example #11
Source File: AnnotationPropertyValueReferenceContributor.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
private PsiReference[] addPsiReferences(PsiElement psiElement, ProcessingContext processingContext, AnnotationPropertyParameter annotationPropertyParameter) {
    ArrayList<PsiReference> psiReferences = new ArrayList<>();

    PhpAnnotationReferenceProviderParameter referencesByElementParameter = new PhpAnnotationReferenceProviderParameter(psiElement, processingContext);

    for(PhpAnnotationReferenceProvider phpAnnotationExtension : AnnotationUtil.EXTENSION_POINT_REFERENCES.getExtensions()) {
        PsiReference[] references = phpAnnotationExtension.getPropertyReferences(annotationPropertyParameter, referencesByElementParameter);
        if(references != null && references.length > 0) {
            psiReferences.addAll(Arrays.asList(references));
        }
    }

    return psiReferences.toArray(new PsiReference[psiReferences.size()]);
}
 
Example #12
Source File: DoctrineAnnotationReferencedColumnReferences.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter phpAnnotationReferenceProviderParameter) {

    PsiElement element = annotationPropertyParameter.getElement();
    if(!Symfony2ProjectComponent.isEnabled(annotationPropertyParameter.getProject()) ||
        !(element instanceof StringLiteralExpression) ||
        !PhpElementsUtil.isEqualClassName(annotationPropertyParameter.getPhpClass(), "\\Doctrine\\ORM\\Mapping\\JoinColumn")
        )
    {
        return new PsiReference[0];
    }

    // @Foo(targetEntity="Foo\Class")
    if(annotationPropertyParameter.getType() == AnnotationPropertyParameter.Type.PROPERTY_VALUE && "referencedColumnName".equals(annotationPropertyParameter.getPropertyName())) {

        PhpDocComment phpDocComment = PsiTreeUtil.getParentOfType(element, PhpDocComment.class);
        if(phpDocComment != null) {
            PhpDocCommentAnnotation phpDocCommentAnnotationContainer = AnnotationUtil.getPhpDocCommentAnnotationContainer(phpDocComment);

            if(phpDocCommentAnnotationContainer != null) {

                PhpDocTagAnnotation phpDocTagAnnotation = phpDocCommentAnnotationContainer.getFirstPhpDocBlock(
                    "\\Doctrine\\ORM\\Mapping\\ManyToOne",
                    "\\Doctrine\\ORM\\Mapping\\ManyToMany",
                    "\\Doctrine\\ORM\\Mapping\\OneToOne",
                    "\\Doctrine\\ORM\\Mapping\\OneToMany"
                );

                if(phpDocTagAnnotation != null) {

                    PhpPsiElement phpDocAttrList = phpDocTagAnnotation.getPhpDocTag().getFirstPsiChild();

                    // @TODO: remove nested on Annotation plugin update
                    if(phpDocAttrList != null) {
                        if(phpDocAttrList.getNode().getElementType() == PhpDocElementTypes.phpDocAttributeList) {
                            PhpPsiElement phpPsiElement = phpDocAttrList.getFirstPsiChild();
                            if(phpPsiElement instanceof StringLiteralExpression) {
                                PhpClass phpClass = de.espend.idea.php.annotation.util.PhpElementsUtil.getClassInsideAnnotation(((StringLiteralExpression) phpPsiElement));
                                if(phpClass != null) {
                                    Collection<DoctrineModelField> lists = EntityHelper.getModelFields(phpClass);
                                    if(lists.size() > 0) {
                                        return new PsiReference[] {
                                            new EntityReference((StringLiteralExpression) element, lists)
                                        };
                                    }
                                }
                            }
                        }
                    }


                }

            }

        }

    }

    return new PsiReference[0];
}
 
Example #13
Source File: PhpAnnotationReferenceProvider.java    From idea-php-annotation-plugin with MIT License 4 votes vote down vote up
@Nullable
PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter referencesByElementParameter);