Java Code Examples for com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocComment#getNextPsiSibling()

The following examples show how to use com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocComment#getNextPsiSibling() . 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: TwigUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * Get templates on "@Template()" and on method attached to given PhpDocTag
 */
@NotNull
public static Map<String, Collection<PsiElement>> getTemplateAnnotationFilesWithSiblingMethod(@NotNull PhpDocTag phpDocTag) {
    Map<String, Collection<PsiElement>> targets = new HashMap<>();

    // template on direct PhpDocTag
    Pair<String, Collection<PsiElement>> templateAnnotationFiles = TwigUtil.getTemplateAnnotationFiles(phpDocTag);
    if(templateAnnotationFiles != null) {
        targets.put(templateAnnotationFiles.getFirst(), templateAnnotationFiles.getSecond());
    }

    // templates on "Method" of PhpDocTag
    PhpDocComment phpDocComment = PsiTreeUtil.getParentOfType(phpDocTag, PhpDocComment.class);
    if(phpDocComment != null) {
        PsiElement method = phpDocComment.getNextPsiSibling();
        if(method instanceof Method) {
            for (String name : TwigUtil.getControllerMethodShortcut((Method) method)) {
                targets.put(name, new HashSet<>(getTemplatePsiElements(method.getProject(), name)));
            }
        }
    }

    return targets;
}
 
Example 2
Source File: ColumnNameCompletionProvider.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Override
public void getPropertyValueCompletions(AnnotationPropertyParameter annotationPropertyParameter, AnnotationCompletionProviderParameter completionParameter) {

    String propertyName = annotationPropertyParameter.getPropertyName();
    if(propertyName == null) {
        return;
    }

    if(propertyName.equals("name") && PhpLangUtil.equalsClassNames(annotationPropertyParameter.getPhpClass().getPresentableFQN(), "Doctrine\\ORM\\Mapping\\Column")) {
        PhpDocComment phpDocComment = PsiTreeUtil.getParentOfType(annotationPropertyParameter.getElement(), PhpDocComment.class);
        if(phpDocComment != null) {
            PhpPsiElement classField = phpDocComment.getNextPsiSibling();
            if(classField != null && classField.getNode().getElementType() == PhpElementTypes.CLASS_FIELDS) {
                Field field = PsiTreeUtil.getChildOfType(classField, Field.class);
                if(field != null) {
                    String name = field.getName();
                    if(StringUtils.isNotBlank(name)) {
                        completionParameter.getResult().addElement(LookupElementBuilder.create(underscore(name)));
                    }
                }
            }
        }
    }

}
 
Example 3
Source File: EventAnnotationStubIndex.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void visitPhpDocTag(PhpDocTag element) {
    String name = StringUtils.stripStart(element.getName(), "@");
    if(!"Event".equalsIgnoreCase(name)) {
        return;
    }

    PhpDocComment phpDocComment = ObjectUtils.tryCast(element.getParent(), PhpDocComment.class);
    if(phpDocComment == null) {
        return;
    }

    PhpPsiElement nextPsiSibling = phpDocComment.getNextPsiSibling();
    if(nextPsiSibling == null || nextPsiSibling.getNode().getElementType() != PhpElementTypes.CLASS_CONSTANTS) {
        return;
    }

    ClassConstImpl childOfAnyType = PsiTreeUtil.findChildOfAnyType(nextPsiSibling, ClassConstImpl.class);
    if(childOfAnyType == null) {
        return;
    }

    PsiElement defaultValue = childOfAnyType.getDefaultValue();
    if(!(defaultValue instanceof StringLiteralExpression)) {
        return;
    }

    String contents = ((StringLiteralExpression) defaultValue).getContents();

    String fqn = StringUtils.stripStart(childOfAnyType.getFQN(), "\\");

    map.put(contents, new DispatcherEvent(
        fqn,
        findClassInstance(phpDocComment, element))
    );
}
 
Example 4
Source File: AnnotationBackportUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
public static Method getMethodScope(@NotNull PhpDocTag phpDocTag) {
    PhpDocComment parentOfType = PsiTreeUtil.getParentOfType(phpDocTag, PhpDocComment.class);
    if(parentOfType == null) {
        return null;
    }

    PhpPsiElement method = parentOfType.getNextPsiSibling();
    if(!(method instanceof Method)) {
        return null;
    }

    return (Method) method;
}
 
Example 5
Source File: DoctrineUtil.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public static boolean repositoryClassExists(PhpDocTag phpDocTag)
{
    StringLiteralExpression repositoryClass = AnnotationUtil.getPropertyValueAsPsiElement(phpDocTag, "repositoryClass");
    if(repositoryClass == null || StringUtils.isBlank(repositoryClass.getContents())) {
        return false;
    }

    PhpClass phpClass = PhpElementsUtil.getClassInsideAnnotation(repositoryClass, repositoryClass.getContents());
    if(phpClass != null) {
        return true;
    }

    PhpDocComment phpDocComment = PsiTreeUtil.getParentOfType(repositoryClass, PhpDocComment.class);
    if(phpDocComment == null) {
        return false;
    }

    PhpPsiElement phpClassContext = phpDocComment.getNextPsiSibling();
    if(!(phpClassContext instanceof PhpClass)) {
        return false;
    }

    String ns = ((PhpClass) phpClassContext).getNamespaceName();
    String repoClass = repositoryClass.getContents();
    String targetClass;

    if(repoClass.startsWith("\\") || repoClass.startsWith(ns)) {
        targetClass = repoClass;
    } else {
        targetClass = ns + repoClass;
    }

    String classPath = PhpLangUtil.toPresentableFQN(targetClass);
    PhpClass repoPhpClass = PhpElementsUtil.getClass(phpClassContext.getProject(), classPath);

    return repoPhpClass != null;
}
 
Example 6
Source File: AnnotationUtil.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public static boolean isAnnotationPhpDocTag(PhpDocTag phpDocTag) {
    PhpDocComment phpDocComment = PsiTreeUtil.getParentOfType(phpDocTag, PhpDocComment.class);
    if(phpDocComment == null) {
        return false;
    }

    PsiElement nextPsiElement = phpDocComment.getNextPsiSibling();
    if(nextPsiElement == null || !(nextPsiElement instanceof Method || nextPsiElement instanceof PhpClass || nextPsiElement.getNode().getElementType() == PhpElementTypes.CLASS_FIELDS)) {
        return false;
    }

    return true;
}
 
Example 7
Source File: PhpElementsUtil.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@Nullable
static public AnnotationTarget findAnnotationTarget(@Nullable PhpDocComment phpDocComment) {
    if(phpDocComment == null) {
        return null;
    }

    if(phpDocComment.getNextPsiSibling() instanceof Method) {
        return AnnotationTarget.METHOD;
    }

    if(PlatformPatterns.psiElement(PhpElementTypes.CLASS_FIELDS).accepts(phpDocComment.getNextPsiSibling())) {
        return AnnotationTarget.PROPERTY;
    }

    if(phpDocComment.getNextPsiSibling() instanceof PhpClass) {
        return AnnotationTarget.CLASS;
    }

    // workaround: if file has no use statements all is wrapped inside a group
    if(phpDocComment.getNextPsiSibling() instanceof GroupStatement) {
        PsiElement groupStatement =  phpDocComment.getNextPsiSibling();
        if(groupStatement != null && groupStatement.getFirstChild() instanceof PhpClass) {
            return AnnotationTarget.CLASS;
        }
    }

    return null;
}