PsiReference to PsiFile


I'm implementing a reference contributor for a custom XML we have:

<myElement location="yourFile.png"/>

I want "location" to be a reference to a file in your source roots. I already have the VirtualFile and PsiFile for 'location', but I don't know how to get a PsiReference for it. Is there a way to do it?

Thanks in advance!


If you're using DOM you can use  GenericAttributeValue<PathReference> getLocation(), eventually using a custom @Converter if you need to extend resolve logic.
If you're using "plain" references in XML PSI, com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet or its subclasses will help you.


Thank you very much, that was it :)



Could you elaborate on the approach you took?

I am facing the same problem. I am not sure how to create FileReferenceSet for the text in my attribute

To be more specific, I have something like

<myElement myLocation="myFile.push()">

I need to get the reference to myFile.xml file

Any idea how to create a FileReferenceSet and the corresponding reference to the xml file

I will really appreciate it


One sample would be org.jetbrains.idea.devkit.dom.DependencyConfigFileConverter from DevKit plugin


Any sample if not using DOM API?


You can use "plain" PsiReferenceProvider and return references from FileReferenceSet or just delegate to com.intellij.openapi.paths.PathReferenceProvider#createReferences


Hi Yann


Thank you for your help

I made good progress. Thanks


Please sign in to leave a comment.