com.jetbrains.php.lang.psi.elements.PhpReturn Java Examples

The following examples show how to use com.jetbrains.php.lang.psi.elements.PhpReturn. 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: ReturnArraySignatureRegistrarMatcher.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
@Override
public boolean matches(@NotNull LanguageMatcherParameter parameter) {

    PsiElement parent = parameter.getElement().getParent();
    if(!(parent instanceof StringLiteralExpression)) {
        return false;
    }

    PsiElement arrayValue = parent.getParent();
    if(arrayValue == null || arrayValue.getNode().getElementType() != PhpElementTypes.ARRAY_VALUE) {
        return false;
    }

    PsiElement arrayCreation = arrayValue.getParent();
    if(!(arrayCreation instanceof ArrayCreationExpression)) {
        return false;
    }

    PsiElement phpReturn = arrayCreation.getParent();
    if(!(phpReturn instanceof PhpReturn)) {
        return false;
    }

    return PhpMatcherUtil.isMachingReturnArray(parameter.getSignatures(), phpReturn);
}
 
Example #2
Source File: InitResourceServiceIndex.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
private void visitPhpReturn(@NotNull PhpReturn phpReturn) {
    PhpClass phpClass = method.getContainingClass();
    if (phpClass == null) {
        return;
    }

    HookSubscriberUtil.visitSubscriberEvents(phpReturn, (event, methodName, key) -> {
        SubscriberInfo subscriberInfo = SubscriberIndexUtil.getSubscriberInfo(event);
        if(subscriberInfo == null) {
            return;
        }

        ServiceResource serviceResource = new ServiceResource(event, subscriberInfo.getEvent().getText(), subscriberInfo.getService())
            .setSignature(StringUtils.strip(phpClass.getFQN(), "\\") + '.' + methodName);

        String resourceKey = subscriberInfo.getEvent().getText();
        if(!serviceMap.containsKey(resourceKey)) {
            serviceMap.put(resourceKey, new ArrayList<>());
        }

        serviceMap.get(resourceKey).add(serviceResource);
    });
}
 
Example #3
Source File: ReturnArraySignatureRegistrarMatcher.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
@Override
public boolean matches(@NotNull LanguageMatcherParameter parameter) {

    PsiElement parent = parameter.getElement().getParent();
    if(!(parent instanceof StringLiteralExpression)) {
        return false;
    }

    PsiElement arrayValue = parent.getParent();
    if(arrayValue == null || arrayValue.getNode().getElementType() != PhpElementTypes.ARRAY_VALUE) {
        return false;
    }

    PsiElement arrayCreation = arrayValue.getParent();
    if(!(arrayCreation instanceof ArrayCreationExpression)) {
        return false;
    }

    PsiElement phpReturn = arrayCreation.getParent();
    if(!(phpReturn instanceof PhpReturn)) {
        return false;
    }

    return PhpMatcherUtil.isMachingReturnArray(parameter.getSignatures(), phpReturn);
}
 
Example #4
Source File: ReturnStringSignatureRegistrarMatcher.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Override
public boolean matches(@NotNull LanguageMatcherParameter parameter) {

    PsiElement parent = parameter.getElement().getParent();
    if(!(parent instanceof StringLiteralExpression)) {
        return false;
    }

    PsiElement phpReturn = parent.getParent();
    if(!(phpReturn instanceof PhpReturn)) {
        return false;
    }

    return PhpMatcherUtil.isMachingReturnArray(parameter.getSignatures(), phpReturn);
}
 
Example #5
Source File: ArrayReturnPsiRecursiveVisitor.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
@Override
public void visitElement(PsiElement element) {

    if(element instanceof PhpReturn) {
        visitPhpReturn((PhpReturn) element);
    }

    super.visitElement(element);
}
 
Example #6
Source File: InitResourceServiceIndex.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@Override
public void visitElement(PsiElement element) {
    if(element instanceof PhpReturn) {
        visitPhpReturn((PhpReturn) element);
    }

    super.visitElement(element);
}
 
Example #7
Source File: ShopwareBoostrapInspection.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    PsiFile psiFile = holder.getFile();
    if(!ShopwareProjectComponent.isValidForProject(psiFile)) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    if(!"Bootstrap.php".equals(psiFile.getName())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new PsiElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if(element instanceof Method) {
                String methodName = ((Method) element).getName();
                if(INSTALL_METHODS.contains(((Method) element).getName())) {
                    if(PsiTreeUtil.collectElementsOfType(element, PhpReturn.class).size() == 0) {
                        PsiElement psiElement = PsiElementUtils.getChildrenOfType(element, PlatformPatterns.psiElement(PhpTokenTypes.IDENTIFIER).withText(methodName));
                        if(psiElement != null) {
                            holder.registerProblem(psiElement, "Shopware need return statement", ProblemHighlightType.GENERIC_ERROR);
                        }
                    }
                }

            }

            super.visitElement(element);
        }
    };
}
 
Example #8
Source File: ReturnStringSignatureRegistrarMatcher.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Override
public boolean matches(@NotNull LanguageMatcherParameter parameter) {

    PsiElement parent = parameter.getElement().getParent();
    if(!(parent instanceof StringLiteralExpression)) {
        return false;
    }

    PsiElement phpReturn = parent.getParent();
    if(!(phpReturn instanceof PhpReturn)) {
        return false;
    }

    return PhpMatcherUtil.isMachingReturnArray(parameter.getSignatures(), phpReturn);
}
 
Example #9
Source File: EventMethodCallInspection.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
public void visitElement(PsiElement element) {
    super.visitElement(element);

    if(!(element instanceof StringLiteralExpression)) {
        return;
    }

    PsiElement arrayValue = element.getParent();
    if(arrayValue != null && arrayValue.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE) {
        PhpReturn phpReturn = PsiTreeUtil.getParentOfType(arrayValue, PhpReturn.class);
        if(phpReturn != null) {
            Method method = PsiTreeUtil.getParentOfType(arrayValue, Method.class);
            if(method != null) {
                String name = method.getName();
                if("getSubscribedEvents".equals(name)) {
                    PhpClass containingClass = method.getContainingClass();
                    if(containingClass != null && PhpElementsUtil.isInstanceOf(containingClass, "\\Symfony\\Component\\EventDispatcher\\EventSubscriberInterface")) {
                        String contents = ((StringLiteralExpression) element).getContents();
                        if(StringUtils.isNotBlank(contents) && containingClass.findMethodByName(contents) == null) {
                            registerMethodProblem(element, holder, containingClass);
                        }
                    }
                }
            }
        }
    }
}
 
Example #10
Source File: PhpEventDispatcherGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 *
 * \Symfony\Component\EventDispatcher\EventSubscriberInterface::getSubscribedEvents
 *
 * return array(
 *  'pre.foo' => array('preFoo', 10),
 *  'post.foo' => array('postFoo'),
 * ');
 *
 */
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {

    registrar.register(PlatformPatterns.psiElement().withParent(StringLiteralExpression.class).withLanguage(PhpLanguage.INSTANCE), psiElement -> {
        PsiElement parent = psiElement.getParent();
        if(!(parent instanceof StringLiteralExpression)) {
            return null;
        }

        PsiElement arrayValue = parent.getParent();
        if(arrayValue != null && arrayValue.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE) {
            PhpReturn phpReturn = PsiTreeUtil.getParentOfType(arrayValue, PhpReturn.class);
            if(phpReturn != null) {
                Method method = PsiTreeUtil.getParentOfType(arrayValue, Method.class);
                if(method != null) {
                    String name = method.getName();
                    if("getSubscribedEvents".equals(name)) {
                        PhpClass containingClass = method.getContainingClass();
                        if(containingClass != null && PhpElementsUtil.isInstanceOf(containingClass, "\\Symfony\\Component\\EventDispatcher\\EventSubscriberInterface")) {
                            return new PhpClassPublicMethodProvider(containingClass);
                        }
                    }
                }
            }
        }

        return null;
    });

}
 
Example #11
Source File: ArrayReturnPsiRecursiveVisitor.java    From Thinkphp5-Plugin with MIT License 4 votes vote down vote up
public void visitPhpReturn(PhpReturn phpReturn) {
    PsiElement arrayCreation = phpReturn.getFirstPsiChild();
    if (arrayCreation instanceof ArrayCreationExpression) {
        collectConfigKeys((ArrayCreationExpression) arrayCreation, this.arrayKeyVisitor, fileNameWithoutExtension);
    }
}
 
Example #12
Source File: ArrayReturnPsiRecursiveVisitor.java    From idea-php-laravel-plugin with MIT License 4 votes vote down vote up
public void visitPhpReturn(PhpReturn phpReturn) {
    PsiElement arrayCreation = phpReturn.getFirstPsiChild();
    if(arrayCreation instanceof ArrayCreationExpression) {
        collectConfigKeys((ArrayCreationExpression) arrayCreation, this.arrayKeyVisitor, fileNameWithoutExtension);
    }
}