Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refactor EL expressions in JSPs

I have many JSP files with EL expressions of the form ${foo.bar.baz.phleem1}, ${foo.bar.baz.phleem2} etc. (the first two or three segments are equal). To reduce EL lookups I am in the process of refactoring these pages:

Source:

<c:out value="${foo.bar.baz.phleem1}" />
<c:out value="${foo.bar.baz.phleem2}" />
<c:out value="${foo.bar.baz.phleem3}" />

After refactoring:

<c:set var="baz" value="${foo.bar.baz}" />
<c:out value="${baz.phleem1}" />
<c:out value="${baz.phleem2}" />
<c:out value="${baz.phleem3}" />

I know I can do most of this with searching / replacing, but it feels unsafe as it ignores code structure.

Is there any support for this type of refactoring in either Eclipse or IntelliJ Idea?

like image 979
Sean Patrick Floyd Avatar asked Jan 26 '12 14:01

Sean Patrick Floyd


1 Answers

Maybe you can use the nxml-mode in emacs. (i don't tested it) There are some functions like nxml-up-element. I bet you can create a powerful macro. But i think its more easy to grep the code and do it manually.

like image 193
Ingolf Wagner Avatar answered Sep 28 '22 11:09

Ingolf Wagner