Java源码示例:de.espend.idea.php.annotation.extension.parameter.PhpAnnotationReferenceProviderParameter

示例1
@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];
}
 
示例2
@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];
}
 
示例3
@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()))
    };
}
 
示例4
@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];
}
 
示例5
@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)
    };
}
 
示例6
@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())
    };
}
 
示例7
@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())
    };

}
 
示例8
@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())
    };

}
 
示例9
@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];
}
 
示例10
@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)
    };

}
 
示例11
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()]);
}
 
示例12
@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];
}
 
示例13
@Nullable
PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter referencesByElementParameter);