DEV Community

Maksim
Maksim

Posted on • Originally published at maksimrv.Medium on

JavaScript in IDE scripting console

Official script example written in JavaScript

function main() { let sum = 0; let arr = "35907 77134 453661 175096 23673 29350".split(" "); arr.forEach((it) => sum += it.length); com.intellij.openapi.ui.Messages.showInfoMessage((sum / arr.length).toString(), "test"); } main(); 
Enter fullscreen mode Exit fullscreen mode

IDEA uses GraalJS to run the script. So you can use interop between JavaScript and Java to access Java objects.

JavaScript runtime also has a global variable IDE which reference an instance of com.intellij.ide.script.IDE

IDE.print("Hello World!") 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)