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

The following examples show how to use com.jetbrains.php.lang.psi.elements.MethodReference#getSignature() . 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: 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 2
Source File: ObjectRepositoryResultTypeProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement e) {
    if (!(e instanceof MethodReference) || !Settings.getInstance(e.getProject()).pluginEnabled) {
        return null;
    }

    MethodReference methodRef = (MethodReference) e;

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

    String methodRefName = methodRef.getName();

    if(null == methodRefName || (!Arrays.asList(new String[] {"find", "findAll"}).contains(methodRefName) && !methodRefName.startsWith("findOneBy") && !methodRefName.startsWith("findBy"))) {
        return null;
    }

    // we can get the repository name from the signature calls
    // #M#?#M#?#M#C\Foo\Bar\Controller\BarController.get?doctrine.getRepository?EntityBundle:User.find
    String repositorySignature = methodRef.getSignature();

    int lastRepositoryName = repositorySignature.lastIndexOf(ObjectRepositoryTypeProvider.TRIM_KEY);
    if(lastRepositoryName == -1) {
        return null;
    }

    repositorySignature = repositorySignature.substring(lastRepositoryName);
    int nextMethodCall = repositorySignature.indexOf('.' + methodRefName);
    if(nextMethodCall == -1) {
        return null;
    }

    repositorySignature = repositorySignature.substring(1, nextMethodCall);

    return new PhpType().add("#" + this.getKey() + refSignature + TRIM_KEY + repositorySignature);
}