Unable to specify method name in capture for PsiReferenceContributor (PhpStorm)

I've implemented a plugin that allows us to "Go to definition" on some strings in PHP.
However, my PsiReferenceContributor isn't specific enough.

I want to be able to capture "The first string parameter of a call to a method called 'prepareTable' ".

What I have so far (which works) is as follows:

PsiElementPattern.Capture<StringLiteralExpression> psiElementCapture =
            PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(
                PlatformPatterns.psiElement(ParameterList.class).withParent(
                    PlatformPatterns.psiElement(MethodReference.class)
                )
            )
        ;

As far as I understand it, this will get me any string that is a parameter of a method call. As you can see, this isn't really specific enough.

What I've tried to do to is the following:

PsiElementPattern.Capture<StringLiteralExpression> psiElementCapture =
            PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(
                PlatformPatterns.psiElement(ParameterList.class).withParent(
                    PlatformPatterns.psiElement(MethodReference.class).withName("prepareTable")
                )
            )
        ;

But that doesn't seem to work. The PsiViewer tells me that the "name" property of the MethodReference node is indeed prepareTable, but I'm not sure how to specify that in the capture pattern above, as what I've tried doesn't work.

What am I missing? Can somebody help me out?

1 comment

I've solved my problem by adding the check for method reference's name in the psiReferenceProvider instead. However, this feels "clunky" and inefficient.


Is there a way to do what I've proposed above?

0

Please sign in to leave a comment.