简体   繁体   English

Java中嵌入的Javascript-如何进行声明? (Ctrl + B)(Nashorn)(IntelliJ)

[英]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. 在纯Java或纯JavaScript中,我可以使用Ctrl + B跳转到声明。 But when I'm invoking Java from within a JavaScript file, IntelliJ cannot resolve my Java references. 但是,当我从JavaScript文件中调用Java时,IntelliJ无法解析我的Java引用。

These 3 lines execute no problem, but I cannot press "Ctrl+B" on the "out" or "println" parts of these lines. 这3行没有问题,但是我不能在这些行的“ out”或“ println”部分上按“ Ctrl + B”。 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. 我希望Ctrl + B像我在Java文件中进行操作时一样,跳到编辑器中的java.lang.System类。

// 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: 我使用以下Java调用脚本:

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? 在这种情况下,有人知道如何使Ctrl + B(转到声明)与IntelliJ一起使用吗?

Out of the box, IntelliJ IDEA has no support for resolving references between JavaScript and Java. 现成的IntelliJ IDEA不支持解析JavaScript和Java之间的引用。 Someone from the community was working on a plugin which supported that, but as far as I know the plugin wasn't released. 来自社区的某人正在开发一个支持该功能的插件 ,但据我所知该插件尚未发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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