Java Code Examples for fr.adrienbrault.idea.symfony2plugin.util.PhpTypeProviderUtil#getReferenceSignatureByFirstParameter()

The following examples show how to use fr.adrienbrault.idea.symfony2plugin.util.PhpTypeProviderUtil#getReferenceSignatureByFirstParameter() . 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: ObjectRepositoryTypeProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement e) {
    if (!Settings.getInstance(e.getProject()).pluginEnabled) {
        return null;
    }

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


    String refSignature = ((MethodReference)e).getSignature();
    if(StringUtil.isEmpty(refSignature)) {
        return null;
    }

    String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter((MethodReference) e, TRIM_KEY);
    return signature == null ? null : new PhpType().add("#" + this.getKey() + signature);
}
 
Example 2
Source File: ShopwareApiResourcesTypeProvider.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement e) {
    if (!Settings.getInstance(e.getProject()).pluginEnabled) {
        return null;
    }

    // container calls are only on "get" methods
    if(!(e instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "getResource")) {
        return null;
    }

    String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter((MethodReference) e, TRIM_KEY);
    return signature == null ? null : new PhpType().add("#" + this.getKey() + signature);
}
 
Example 3
Source File: ObjectManagerFindTypeProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement e) {
    if (!Settings.getInstance(e.getProject()).pluginEnabled) {
        return null;
    }

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

    String refSignature = ((MethodReference)e).getSignature();
    if(StringUtil.isEmpty(refSignature)) {
        return null;
    }

    // we need the param key on getBySignature(), since we are already in the resolved method there attach it to signature
    // param can have dotted values split with \
    PsiElement[] parameters = ((MethodReference)e).getParameters();
    if (parameters.length >= 2) {
        String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter((MethodReference) e, TRIM_KEY);
        if(signature != null) {
            return new PhpType().add("#" + this.getKey() + signature);
        }
    }

    return null;
}
 
Example 4
Source File: SymfonyContainerTypeProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement e) {
    if (!Settings.getInstance(e.getProject()).pluginEnabled) {
        return null;
    }

    // container calls are only on "get" methods
    if(!(e instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "get")) {
        return null;
    }

    String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter((MethodReference) e, TRIM_KEY);
    return signature == null ? null : new PhpType().add("#" + this.getKey() + signature);
}
 
Example 5
Source File: MethodSignatureTypeProvider.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement e) {
    if (!Settings.getInstance(e.getProject()).pluginEnabled || !(e instanceof MethodReference)) {
        return null;
    }

    Collection<MethodSignatureSetting> signatures = getSignatureSettings(e);
    if(signatures.size() == 0) {
        return null;
    }

    MethodReference methodReference = (MethodReference) e;
    Collection<MethodSignatureSetting> matchedSignatures = getSignatureSetting(methodReference.getName(), signatures);
    if(matchedSignatures.size() == 0) {
        return null;
    }

    String refSignature = ((MethodReference)e).getSignature();
    if(StringUtil.isEmpty(refSignature)) {
        return null;
    }

    // we need the param key on getBySignature(), since we are already in the resolved method there attach it to signature
    // param can have dotted values split with \
    PsiElement[] parameters = ((MethodReference)e).getParameters();
    for(MethodSignatureSetting methodSignature: matchedSignatures) {
        if (parameters.length - 1 >= methodSignature.getIndexParameter()) {
            PsiElement parameter = parameters[methodSignature.getIndexParameter()];
            if ((parameter instanceof StringLiteralExpression)) {
                String param = ((StringLiteralExpression)parameter).getContents();
                if (StringUtil.isNotEmpty(param)) {
                    return new PhpType().add("#" + this.getKey() + refSignature + TRIM_KEY + param);
                }
            }

            String parameterSignature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter(methodReference, TRIM_KEY);
            if(parameterSignature != null) {
                return new PhpType().add("#" + this.getKey() + parameterSignature);
            }
        }
    }

    return null;
}