Java Code Examples for com.jetbrains.php.lang.psi.elements.MethodReference#getParameters()

The following examples show how to use com.jetbrains.php.lang.psi.elements.MethodReference#getParameters() . 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: ContextTypeProvider.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement psiElement) {
    if (DumbService.getInstance(psiElement.getProject()).isDumb() || !TYPO3CMSProjectSettings.isEnabled(psiElement)) {
        return null;
    }

    if (!(psiElement instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(psiElement, "getAspect")) {
        return null;
    }

    MethodReference methodReference = (MethodReference) psiElement;
    if (methodReference.getParameters().length == 0) {
        return null;
    }

    PsiElement firstParam = methodReference.getParameters()[0];
    if (firstParam instanceof StringLiteralExpression) {
        StringLiteralExpression contextAlias = (StringLiteralExpression) firstParam;
        if (!contextAlias.getContents().isEmpty()) {
            return new PhpType().add("#" + this.getKey() + contextAlias.getContents());
        }
    }

    return null;
}
 
Example 2
Source File: BladeCustomDirectivesVisitor.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
private void visitMethodReference(MethodReference methodReference) {

        if (!"directive".equals(methodReference.getName())) {
            return;
        }

        PsiElement[] parameters = methodReference.getParameters();

        if (parameters.length == 0) {
            return;
        }

        if (!(parameters[0] instanceof StringLiteralExpression)) {
            return;
        }

        checkClassName(methodReference, ((StringLiteralExpression) parameters[0]).getContents());
    }
 
Example 3
Source File: TemplateUtil.java    From Thinkphp5-Plugin with MIT License 5 votes vote down vote up
private void visitMethodReference(MethodReference methodReference) {

            String methodName = methodReference.getName();
            if (!RENDER_METHODS.contains(methodName)) {
                return;
            }

            PsiElement classReference = methodReference.getFirstChild();
            if (!(classReference instanceof ClassReference)) {
                return;
            }

            if (!"View".equals(((ClassReference) classReference).getName())) {
                return;
            }

            PsiElement[] parameters = methodReference.getParameters();
            if (parameters.length == 0 || !(parameters[0] instanceof StringLiteralExpression)) {
                return;
            }

            String contents = ((StringLiteralExpression) parameters[0]).getContents();
            if (StringUtils.isBlank(contents)) {
                return;
            }

            views.add(Pair.create(contents, parameters[0]));
        }
 
Example 4
Source File: Symfony2InterfacesUtil.java    From Thinkphp5-Plugin with MIT License 5 votes vote down vote up
@Deprecated
@Nullable
public static String getFirstArgumentStringValue(MethodReference e) {
    String stringValue = null;

    PsiElement[] parameters = e.getParameters();
    if (parameters.length > 0 && parameters[0] instanceof StringLiteralExpression) {
        stringValue = ((StringLiteralExpression) parameters[0]).getContents();
    }

    return stringValue;
}
 
Example 5
Source File: GeneralUtilityServiceTypeProvider.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement psiElement) {
    if (DumbService.getInstance(psiElement.getProject()).isDumb() || !TYPO3CMSProjectSettings.isEnabled(psiElement)) {
        return null;
    }

    if (!(psiElement instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(psiElement, "makeInstanceService")) {
        return null;
    }

    MethodReference methodReference = (MethodReference) psiElement;
    if (methodReference.getParameters().length == 0) {
        return null;
    }

    PsiElement firstParam = methodReference.getParameters()[0];

    if (firstParam instanceof StringLiteralExpression) {
        StringLiteralExpression ref = (StringLiteralExpression) firstParam;
        String serviceId = ref.getContents();

        return new PhpType().add("#" + this.getKey() + serviceId);
    }

    return null;
}
 
Example 6
Source File: PhpDiTypeProvider.java    From phpstorm-phpdi with MIT License 5 votes vote down vote up
@Nullable
@Override
public String getType(PsiElement psiElement) {
    if (DumbService.getInstance(psiElement.getProject()).isDumb()) {
        return null;
    }

    if (!(psiElement instanceof MethodReference)) {
        return null;
    }

    MethodReference methodRef = ((MethodReference) psiElement);

    if (!("get".equals(methodRef.getName()) || "make".equals(methodRef.getName()))) {
        return null;
    }

    if (methodRef.getParameters().length == 0) {
        return null;
    }

    PsiElement firstParam = methodRef.getParameters()[0];

    if (firstParam instanceof PhpReference) {
        PhpReference ref = (PhpReference)firstParam;
        if (ref.getText().toLowerCase().contains("::class")) {
            return methodRef.getSignature() + "%" + ref.getSignature();
        }
    }

    return null;
}
 
Example 7
Source File: Symfony2InterfacesUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Deprecated
@Nullable
public static String getFirstArgumentStringValue(MethodReference e) {
    String stringValue = null;

    PsiElement[] parameters = e.getParameters();
    if (parameters.length > 0 && parameters[0] instanceof StringLiteralExpression) {
        stringValue = ((StringLiteralExpression) parameters[0]).getContents();
    }

    return stringValue;
}
 
Example 8
Source File: BladeTemplateUtil.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
private void visitMethodReference(MethodReference methodReference) {

            String methodName = methodReference.getName();
            if(!RENDER_METHODS.contains(methodName)) {
                return;
            }

            PsiElement classReference = methodReference.getFirstChild();
            if(!(classReference instanceof ClassReference)) {
                return;
            }

            if(!"View".equals(((ClassReference) classReference).getName())) {
                return;
            }

            PsiElement[] parameters = methodReference.getParameters();
            if(parameters.length == 0 || !(parameters[0] instanceof StringLiteralExpression)) {
                return;
            }

            String contents = ((StringLiteralExpression) parameters[0]).getContents();
            if(StringUtils.isBlank(contents)) {
                return;
            }

            views.add(Pair.create(contents, parameters[0]));
        }
 
Example 9
Source File: Symfony2InterfacesUtil.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
@Deprecated
@Nullable
public static String getFirstArgumentStringValue(MethodReference e) {
    String stringValue = null;

    PsiElement[] parameters = e.getParameters();
    if (parameters.length > 0 && parameters[0] instanceof StringLiteralExpression) {
        stringValue = ((StringLiteralExpression) parameters[0]).getContents();
    }

    return stringValue;
}
 
Example 10
Source File: Symfony2InterfacesUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Deprecated
@Nullable
public static String getFirstArgumentStringValue(MethodReference e) {
    String stringValue = null;

    PsiElement[] parameters = e.getParameters();
    if (parameters.length > 0 && parameters[0] instanceof StringLiteralExpression) {
        stringValue = ((StringLiteralExpression) parameters[0]).getContents();
    }

    return stringValue;
}