PreviousNextTracker indexSee it online !

(82/243) 3388 - BeanShell snippet replace doesn't accept multiple statements

Any BeanShell snippet with a semicolon will not parse. Such snippets are useful for including for loops or multiple statements. This is due to the surrounding text sent to the BeanShell interpreter (SearchAndReplace.java):

replaceMethod = BeanShell.cacheBlock("replace", "return (" + replace + ");",true);

It would be preferable if the snippet were handled in the same way as statements on the BeanShell console (from the Console plugin), which will accept multiple statements on a line and print the return value. At the very least, the documentation should be updated to clarify the existing behavior.

There is a workaround in that one can surround multiple statements with eval(""), but this is not practical as the snippets often contain many quotes that would need to be escaped.

Example snippet with multiple statements:
a=""; for(i=0;i<4;i++) { a+=i;} a
Displays 0123 in the BeanShell console, but does not parse in the replace dialog.

Submitted pumbor - 2010-02-03 22:24:18 Assigned
Priority 5 Labels search and replace
Status open Group normal bug
Resolution None

Comments