Java Code Examples for fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils#getCurrentParameterIndex()

The following examples show how to use fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils#getCurrentParameterIndex() . 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: FormOptionGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public GotoCompletionProvider getProvider(@NotNull PsiElement psiElement) {
    if (!Symfony2ProjectComponent.isEnabled(psiElement)) {
        return null;
    }

    ArrayCreationExpression arrayCreationExpression = PhpElementsUtil.getCompletableArrayCreationElement(psiElement.getParent());
    if(arrayCreationExpression != null) {
        PsiElement parameterList = arrayCreationExpression.getParent();
        if (parameterList instanceof ParameterList) {
            PsiElement context = parameterList.getContext();
            if(context instanceof MethodReference) {
                ParameterBag currentIndex = PsiElementUtils.getCurrentParameterIndex(arrayCreationExpression);
                if(currentIndex != null && currentIndex.getIndex() == 2) {
                    if (PhpElementsUtil.isMethodReferenceInstanceOf((MethodReference) context, FormUtil.PHP_FORM_BUILDER_SIGNATURES)) {
                        return getMatchingOption((ParameterList) parameterList, psiElement);
                    }
                }
            }
        }
    }

    return null;
}
 
Example 2
Source File: PhpTemplateMissingInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
private String getTemplateNameIfMissing(@NotNull PsiElement psiElement) {
    MethodReference methodReference = PsiElementUtils.getMethodReferenceWithFirstStringParameter(psiElement);
    if (methodReference == null || !PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, SymfonyPhpReferenceContributor.TEMPLATE_SIGNATURES)) {
        return null;
    }

    ParameterBag parameterBag = PsiElementUtils.getCurrentParameterIndex(psiElement.getParent());
    if(parameterBag == null || parameterBag.getIndex() != 0) {
        return null;
    }

    String templateName = PhpElementsUtil.getFirstArgumentStringValue(methodReference);
    if(templateName == null || StringUtils.isBlank(templateName)) {
        return null;
    }

    if(TwigUtil.getTemplateFiles(psiElement.getProject(), templateName).size() > 0) {
        return null;
    }

    return templateName;
}
 
Example 3
Source File: PhpTranslationDomainInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private void invoke(@NotNull ProblemsHolder holder, @NotNull PsiElement psiElement) {
    if (!(psiElement instanceof StringLiteralExpression) || !(psiElement.getContext() instanceof ParameterList)) {
        return;
    }

    ParameterList parameterList = (ParameterList) psiElement.getContext();

    PsiElement methodReference = parameterList.getContext();
    if (!(methodReference instanceof MethodReference)) {
        return;
    }

    if (!PhpElementsUtil.isMethodReferenceInstanceOf((MethodReference) methodReference, TranslationUtil.PHP_TRANSLATION_SIGNATURES)) {
        return;
    }

    int domainParameter = 2;
    if("transChoice".equals(((MethodReference) methodReference).getName())) {
        domainParameter = 3;
    }

    ParameterBag currentIndex = PsiElementUtils.getCurrentParameterIndex(psiElement);
    if(currentIndex != null && currentIndex.getIndex() == domainParameter) {
        annotateTranslationDomain((StringLiteralExpression) psiElement, holder);
    }
}
 
Example 4
Source File: PhpTranslationKeyInspection.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
private void invoke(@NotNull ProblemsHolder holder, @NotNull PsiElement psiElement) {
    if (!(psiElement instanceof StringLiteralExpression) || !(psiElement.getContext() instanceof ParameterList)) {
        return;
    }

    ParameterList parameterList = (ParameterList) psiElement.getContext();
    PsiElement methodReference = parameterList.getContext();
    if (!(methodReference instanceof MethodReference)) {
        return;
    }

    if (!PhpElementsUtil.isMethodReferenceInstanceOf((MethodReference) methodReference, TranslationUtil.PHP_TRANSLATION_SIGNATURES)) {
        return;
    }

    ParameterBag currentIndex = PsiElementUtils.getCurrentParameterIndex(psiElement);
    if(currentIndex == null || currentIndex.getIndex() != 0) {
        return;
    }

    int domainParameter = 2;
    if("transChoice".equals(((MethodReference) methodReference).getName())) {
        domainParameter = 3;
    }

    PsiElement domainElement = PsiElementUtils.getMethodParameterPsiElementAt(parameterList, domainParameter);

    if(domainElement == null) {
        // no domain found; fallback to default domain
        annotateTranslationKey((StringLiteralExpression) psiElement, "messages", holder);
    } else {
        // resolve string in parameter
        PsiElement[] parameters = parameterList.getParameters();
        if(parameters.length >= domainParameter) {
            String domain = PhpElementsUtil.getStringValue(parameters[domainParameter]);
            if(domain != null) {
                annotateTranslationKey((StringLiteralExpression) psiElement, domain, holder);
            }
        }
    }
}