Navigate to file in another module by clicking on java String
Answered
Hello, I am working on simple navigation functionality. My code looks like this.
public class TestClass extends BaseClass {
public TestClass() {
super("folder/File.txt");
}
}
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
Please sign in to leave a comment.
Hi,
Please see:
Hello again, I tried following the steps described in the links above, but I have the same issue as the guy from the https://intellij-support.jetbrains.com/hc/en-us/community/posts/360004129840-PsiFileReference-for-custom-java-literal thread.
Do I need to create something else except a class that derives from PsiReferenceContributor? I believe that I just miss something.
Hi,
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 https://github.com/DenysKisliak/PluginAA/tree/dkisliak/reference_sampe
And this is an example project https://github.com/DenysKisliak/sample
Steps to reproduce:
1. Navigate to JavaModule/src/main/java/org/example/clientOne/JavaMigrationForClientOne.java
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
Hi,
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 toJavaMigrationForClientOne.java
file and changing the code tosuper("test/mytest.lst")
. Reference will work correctly.To make it work for the case you need, I suggest extending
FileReferenceSet
and overridingcomputeDefaultContexts()
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).