few questions - phpstorm plugin - open api


I am working right now on new phpstorm plugin with will provide better behat integration, and right now I stuck with few things, maybe someone will help me with those:

  1. It is possible (and if it - how) to find all method calls in given class, for example we have TestClass::testMethod() and I would like to find all calls like $this->testMethod() in TestClass and any subclassess, also if this is possible to find all calls from outside of class scope

  2. How can I get phpClass by name in given scope, for example I have a PhpFile instance and class named: 'TestClass' which belongs to TestNamespace which is used in this file, and TestClass which belongs to OtherNamespace - how to resolve / check which TestClass is used? Also how to handle use .... as ...; ?

  3. Is there any way of finding childrens of given object on any level? Something like findChildrenOfType() from PsiTreeUtil but which will got recursively to end of tree

  4. I am implemention StepDefinitionCreator from Cucumber plugin and I need to change new step form - how can I do that?

  5. I am implementing PsiReferenceProvider what should I return from this method if I would like to make a reference to php.lang.psi.elements.Method - i tried with MethodReference but it looks like this is wrong way

Thanks for any help.

1 comment
Comment actions Permalink

1. Nothing specific to PHP here - TestClass::testMethod() is a PsiNamedElement, just use ReferencesSearch utility methods to find all references in given scope.

2. PhpIndex at your service to find entities by name or FQN if you need that. And if you have our ClassReference - just calling a multiresolve() on it will give you all proper candidates with full regard of namespaces and imports.

3. Well basically you should avoid that, it a "smell" that your approach is wrong, you will definitely create performance problems. But.. all PsiElements have method "accept" and we have a bunch of suitable Visitor implementations for each language that can used to achieve that in some approved circumstances.
4. no idea yet, but it looks like something what we should do.. but, AFAIS JavaStepDefinitionCreator is opensource @ https://github.com/JetBrains/intellij-plugins Looks like there is a couple of full cucumber implementations that you can use as a boilerplate.

5. Nope, you should just return your references. Are you sure your code is called? You need to register those providers with PsiReferenceContributor. There should be plenty of examples in that plugin repo above and the core IDEA repo https://github.com/JetBrains/intellij-community.


Please sign in to leave a comment.