Ctrl+click completion for file paths
Answered
Is there a way to get Ctrl+click to navigate to a file referenced in a Java constant?
For example if I have:
private static final String SOME_SQL = readSqlFromFile("sql/query.sql");
I'd like to be able to Ctrl+click on "sql/query.sql" and have IntelliJ open up the query.sql file.
Please sign in to leave a comment.
Hello,
It should work for any files out of the box, provided that the file is located under the module's content root in the directory specified as source/resource root type.
If it does not work please provide a screenshot of your project structure where these files would be seen (e.g. in Project tool window) or a sample project.
Thanks for your reply!
I see the problem now. The .sql file is under src/main/resources, and that folder is marked as a resource folder. One thing I omitted though is that readFromSqlFile also takes a Class, and looks for the specified file in the same package as that class. So for example:
If MyDaoClass were in package a.b.c, it would look for the file in a/b/c/sql/query.sql, located in the source tree at src/main/resources/a/b/c/sql/query.sql.
If the constant refers to the full file path (in which case specifying the DAO class is redundant):
then yes, Ctrl+click does work.
I wish there was a way to get the Ctrl+click to work with partial filenames... otherwise I have two options:
1. Leave the SQL files where they are, and always include the full package name ("a/b/c/sql/query.sql") in the paths - a shame, since there are 18 paths in one of my DAOs and I don't want the full (long) package name repeated 18 times
2. Shorten the name of the package containing the SQL files (e.g. "sql/query.sql") - I'm not keen on having such a generic package name, though
Thanks for detailed explanation of your case.
Unfortunately, there is no way to do so because IDE won’t able to know that the path to SQL file depends on a package of the class from the first method parameter.