简体   繁体   中英

Javascript embedded in Java - How can I go-to-declaration? (Ctrl+B) (Nashorn) (IntelliJ)

In pure Java or pure JavaScript I am able to use Ctrl+B to jump to a declaration. But when I'm invoking Java from within a JavaScript file, IntelliJ cannot resolve my Java references.

These 3 lines execute no problem, but I cannot press "Ctrl+B" on the "out" or "println" parts of these lines. I want Ctrl+B to jump to the java.lang.System class in my editor like it does when I do the same in a Java file.

// test.js
Java.type("java.lang.System").out.println("howdy");
Packages.java.lang.System.out.println("doody");
java.lang.System.out.println("mister");

I use the following Java to invoke my script:

ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
FileReader myScript = new FileReader("test.js");
engine.eval(myScript);

And the output is:

howdy
doody
mister

Does anyone know how to get Ctrl+B (Go To Declaration) to work with IntelliJ in this context?

Out of the box, IntelliJ IDEA has no support for resolving references between JavaScript and Java. Someone from the community was working on a plugin which supported that, but as far as I know the plugin wasn't released.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM