Java Code Examples for de.espend.idea.php.annotation.util.AnnotationUtil#getPhpDocAnnotationContainer()

The following examples show how to use de.espend.idea.php.annotation.util.AnnotationUtil#getPhpDocAnnotationContainer() . 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: DoctrineOrmRepositoryIntention.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
/**
 * Scope resolve for PhpClass:
 * "@ORM\Entity" or inside PhpClass
 */
@Nullable
private PhpClass getScopedPhpClass(PsiElement element) {

    // inside "@ORM\Entity"
    PsiElement parent = element.getParent();

    // inside "@ORM\Entity(<caret>)"
    if(parent.getNode().getElementType() == PhpDocElementTypes.phpDocAttributeList) {
        parent = parent.getParent();
    }

    if(parent instanceof PhpDocTag) {
        PhpDocTagAnnotation phpDocAnnotationContainer = AnnotationUtil.getPhpDocAnnotationContainer((PhpDocTag) parent);

        if(phpDocAnnotationContainer != null) {
            PhpClass phpClass = phpDocAnnotationContainer.getPhpClass();
            if("Doctrine\\ORM\\Mapping\\Entity".equals(phpClass.getPresentableFQN())) {
                PsiElement docTag = parent.getParent();
                if(docTag instanceof PhpDocComment) {
                    PhpPsiElement nextPsiSibling = ((PhpDocComment) docTag).getNextPsiSibling();
                    if(nextPsiSibling instanceof PhpClass) {
                        return (PhpClass) nextPsiSibling;
                    }
                }
            }
        }

        return null;
    }

    // and finally check PhpClass class scope
    return PsiTreeUtil.getParentOfType(element, PhpClass.class);
}
 
Example 2
Source File: PhpAnnotationDocTagAnnotatorParameter.java    From idea-php-annotation-plugin with MIT License 4 votes vote down vote up
@Nullable
public PhpDocTagAnnotation getAnnotationDocTag() {
    return AnnotationUtil.getPhpDocAnnotationContainer(this.phpDocTag);
}
 
Example 3
Source File: AnnotationDocTagGotoHandlerParameter.java    From idea-php-annotation-plugin with MIT License 4 votes vote down vote up
@Nullable
public PhpDocTagAnnotation getAnnotationDocTag() {
    return AnnotationUtil.getPhpDocAnnotationContainer(this.phpDocTag);
}
 
Example 4
Source File: DoctrineTypeDeprecatedInspection.java    From idea-php-annotation-plugin with MIT License 4 votes vote down vote up
@Override
public void visitElement(PsiElement element) {
    if (!(element instanceof StringLiteralExpression) || element.getNode().getElementType() != PhpDocElementTypes.phpDocString) {
        super.visitElement(element);
        return;
    }

    String contents = ((StringLiteralExpression) element).getContents();
    if (StringUtils.isBlank(contents)) {
        super.visitElement(element);
        return;
    }

    PhpDocTag phpDocTag = PsiTreeUtil.getParentOfType(element, PhpDocTag.class);
    if (phpDocTag == null) {
        super.visitElement(element);
        return;
    }

    PsiElement propertyName = PhpElementsUtil.getPrevSiblingOfPatternMatch(element, PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER));
    if(propertyName == null) {
        super.visitElement(element);
        return;
    }

    String text = propertyName.getText();
    if ("type".equalsIgnoreCase(text)) {
        PhpDocTagAnnotation phpDocAnnotationContainer = AnnotationUtil.getPhpDocAnnotationContainer(phpDocTag);
        if (phpDocAnnotationContainer != null) {
            PhpClass tagPhpClass = phpDocAnnotationContainer.getPhpClass();
            if (PhpLangUtil.equalsClassNames(tagPhpClass.getPresentableFQN(), "Doctrine\\ORM\\Mapping\\Column")) {
                for (PhpClass columnPhpClass : DoctrineUtil.getColumnTypesTargets(holder.getProject(), contents)) {
                    if (!columnPhpClass.isDeprecated()) {
                        continue;
                    }

                    String deprecationMessage = PhpElementsUtil.getClassDeprecatedMessage(columnPhpClass);

                    holder.registerProblem(
                        element,
                        "[Annotations] " + (deprecationMessage != null ? deprecationMessage : String.format("Field '%s' is deprecated", text)),
                        ProblemHighlightType.LIKE_DEPRECATED
                    );

                    break;
                }
            }
        }
    }

    super.visitElement(element);
}