Search for Java class referenced in specific xml files
I'm still new to index/stubs so maybe this is super easy but I have not found the right methods to call.
I have implemented a new test framework to run specific tests. The way these classes are declared to the underlying test framework is to create a xml file with a specific name (lets call this tests.xml) at the root of the java module. This file will then have a list of xml tags which reference the java fully qualified name.
This so far I have figured out how to solve (I'm using PsiSearchHelper.processUsagesInNonJavaFiles and use a scope to restrict to only tests.xml). However there is one slight issue. These xml files can also import other xml files which can include more import statements and more test declarations. This is the part I'm not too sure how to handle efficiently.
Does anyone have a suggested method to handle this? Do I need a new index to handle this inheritance?
Thanks in advance!
Please sign in to leave a comment.
Well I'm sure there is a better way. I am currently searching for references (using PsiSearchHelper.processUsagesInNonJavaFiles) in all .xml files. From there, I am recursively calling PsiSearchHelper.processElementsWithWord to search for usages in xml files referring to the previous file name. It works, but I know its not performant.
If anyone has a better idea, let me know.
There might be ways to optimize your existing solution, but it should be profiled carefully.
If the need for adding index is verified, it could indeed be helpful to speedup collecting information.
To give more specific help, please provide some sample XML. Do you use DOM API in your tests.xml already? (http://www.jetbrains.org/intellij/sdk/docs/reference_guide/frameworks_and_external_apis/xml_dom_api.html)
Hey Yann,
Thanks for the pointer, I have not created a DOM API, that's a good idea to extend the plugin.
Here is a generic view of the test file
There is nothing stopping multiple inheritance when importing from other files and there is the ability to have nested cartegorys.
It sounds like if I setup the dom api, I could have the import statements refer to another VirtualFile and make traversal a bit easier. I could, for indexing, find all files in a project with the root file name (lets call it tests.xml). I could find all tests.xml and try to fan out from there indexing all the test classes along the way and store it in the index.
Yes, also employ @Stubbed for <import> tag to avoid building PSI while walking all files/imports. I'd try to avoid building an index first and see if using DOM/stubbed DOM is fast enough.
Thanks Yann for all the help!
This weekend I implemented the XML DOM API which made making the index so much easier! I created an index mapping all the classes which did improve lookup times quite a bit.
Appreciate the help.