IntelliJ with command completion, syntax check/highlighting for IIQ rules (beanshell)

If you want to code beanshell within XML with the same functionality of java (command completion, syntax check, syntax highlighting, etc):

Use language injection in IntelliJ.

Follow these steps if you are using SSB/SSD and have the WEB-INF/lib dir added as module library to your module:

Inject JScript Language

  • Open the XML (a Rule or alike with include beanshell code) in IntelliJ
  • Right Click anywhere in the beanshell code
  • Click: Show Context Actions
  • Click: Inject language or reference
    image
  • Search and click: JShell Snippet
    image

Update the Injection settings:

  • Again Right Click anywhere in the beanshell code

  • Click: Show Context Actions

  • Click: Language Injection Settings

  • Add prefix:
    import org.apache.log4j.Logger; import org.apache.log4j.Level; import sailpoint.object.SailPointContext; import sailpoint.object.Identity; SailPointContext context; Identity identity; Logger log;

    image

  • Click OK

Proof of the pudding is in the eating

  • Go back to the rule in the editor.
  • You can test by typing something like: identity.to and you should see the command completion subwindow:

image

Enjoy this (hopefully) helpful tip! :wink:

– Remold

5 Likes

Thanks for sharing this… Though does not have all the awesome features (especially code folding) of IntelliJ while editing a java file, this still is very helpful.

I just wanted to share few of my observations -

  1. How about using “JShell Snippet” option instead of “Java” under “Inject language or reference”? With this option, there is no need to add prefix or suffix and you can keep the import statements inside the Source tag itself.

  2. If you choose to use “Java”, instead of Going to File>Settings>… you may simply right click on the beanshell code area and click on “Show Context Actions” again and select “Language Injection Settings” to insert the prefix and suffix

Thanks again for sharing this info

Thanks @iamnithesh I will adjust this Show&Tell to incorporate your observations :slight_smile:

We have been using the injection of Java before Java9 was released. JShell is indeed a better option. For instance the imports will not show up as Unexpected tokens.

BTW I have Code Folding, but it seems only to be enabled after I reformat the code (Ctrl-Shift-L). Also an awesome feature when using Java/SHell injection :stuck_out_tongue_winking_eye:

– Remold

3 Likes

@Remold thank you for your post :slight_smile:
I have a question i follow up your steps when I refers to the methods it autocomplete with the package and class name,eg

and if i remove the package (line 19)because its in the top does not open later the class java reference (ctrl +b) pops up the message “it cannot find reference” so I have fully the qualify name again to get the java class compile

Hi Sara,

What do you mean with compile the java class?
These instructions are only for BeanShell within SailPoint XML files, not java classes files.

BTW I tested with the information in you screenshots and I see:
image
So command completion is working for me.

– Remold

when you do ctrl + B then the Filter.class method eq opens, but in my intellij dont fine the methods like you are showing in your picture.

Only works if i add the entire package in the line code, beside i add the import in the top
sailpoint.object.Filter.eq

Its a rule, so its sailpoint xml file

Then if I remove the package search for the method it find it but autocomplete the entire packaged again -->sailpoint.object.Filter.eq

Below are some quick checks you can do

  1. Invalidate Caches and Restart: The issue might be due to corrupted caches. You can invalidate them and restart IntelliJ IDEA by going to File -> Invalidate Caches / Restart -> Invalidate and Restart.
  2. Re-import the Project: Sometimes, IntelliJ IDEA’s project metadata can get out of sync with the actual project state. This can be fixed by re-importing the project.
  3. Check the Project SDK and Classpath: Ensure that the correct SDK is set up for the project (File -> Project Structure -> Project -> Project SDK), and that the necessary libraries are included in the classpath (File -> Project Structure -> Libraries).
  4. Enable Auto-Import: Ensure that auto-import is enabled for your project. This can be done by going to File -> Settings -> Auto Import (or IntelliJ IDEA -> Preferences -> Auto Import for macOS), and checking the options for optimizing imports on the fly

Note - I took the help from chatGPT here based on the issue you mentioned.

Hi Sara,

Can you right-click around there area you’re editing and select Show Context Actions’
image
’
Then click 'Edit JShell Snippet Fragment`
image

A new sub-window will open with the full JShell script (including the Prefix configured).
Maybe there are some syntax error in the top of this fragment, like some extra characters, which prevents the correct import of the sailpoint.object.Filter.

– Remold

Hi @Remold, thank you for your answer,

I dont see any errors

this is what show after the autocomplete


Using the IntelliJ hack is not 100% fail-safe.
Indeed I see the same when I press <ctrl><space>.

Intellij does not know the Object type of Filter when someone directly types Filter, so it extends it to sailpoint.object.Filter :frowning: This has something to do with code-styling. However I don’t know how to ‘fix’ this issue :frowning:

There is a thread on the JetBrains Forum regarding the same,I tried all solutions provided, but got no luck :frowning:

Maybe someone else in our community knows a solution.

– Remold

@Remold thank you for you answer, at least you were able to replicate the issue, so we are in the same page :slight_smile:

1 Like

Did you test it? because it did not work