Navigate to file in another module by clicking on java String


Hello, I am working on simple navigation functionality. My code looks like this.

public class TestClass extends BaseClass {
public TestClass() {

I have this type of java file that extends BaseClass. In the constructor, I have a String that basically a path to a txt file in another module. I want to add a reference to this String, so after clicking Ctrl+Click, I will navigate to the txt file


Hello again, I tried following the steps described in the links above, but I have the same issue as the guy from the thread. 

Do I need to create something else except a class that derives from PsiReferenceContributor? I believe that I just miss something.

public class ControlFileReferenceContributor extends PsiReferenceContributor {
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {

new PsiReferenceProvider() {
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
@NotNull ProcessingContext
context) {
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
String value = literalExpression.getValue() instanceof String ?
(String) literalExpression.getValue() : null;
if (value != null && value.endsWith(".lst")) {
return new FileReferenceSet(value, element, ElementManipulators.getOffsetInElement(element), this, false).getAllReferences();
return PsiReference.EMPTY_ARRAY;


I don't see what the issue can be. Could you please share the code and steps to reproduce+test project?


Hi, this is a plugin code

And this is an example project 

Steps to reproduce:

1. Navigate to JavaModule/src/main/java/org/example/clientOne/

2. Ctrl + R Click on "clientOne/ControlFilesWithAllArtifacts.lst" string in the constructor

3. User should be navigated to ArtifactsModule/src/main/resources/schema/clientOne/ControlFilesWithAllArtifacts.lst

Other errors that may occur because the structure of the sample file differs from the target project, please ignore them



FileReferenceSet works by finding files in the same directory as the Java file containing the reference. You can verify it by adding e.g., test/mytest.lst file next to file and changing the code to super("test/mytest.lst"). Reference will work correctly.

To make it work for the case you need, I suggest extending FileReferenceSet and overriding computeDefaultContexts() to return directories you expect your references in (e.g. .../sample/test project/ArtifactsModule/src/main/resources/schema if I understand your project structure correctly).


Please sign in to leave a comment.