Relational EL Expressions in JSP

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 the EL search, I am refactoring these pages:

A 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 that I can do most of this with search / replace, but it feels unsafe as it ignores the code structure.

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

+6
source share
2 answers

Yes. You can use placeholders in Eclipse with regular expressions and modify accordingly.

provide the following url for regular expressions in eclipse http://www.eclipse.org/tptp/home/downloads/installguide/gla_42/ref/rregexp.html

Press "Search" [Ctrl + H], check the box "Regular expression" and "File" in jsp.

enter image description here

Press Ctrl + Spacebar to support the content.

enter image description here

Click on match matching, replace to replace the entire line with agreement at a time. You can use regex groups to replace content

enter image description here

enter image description here

enter image description here

0
source

Perhaps you can use nxml-mode in emacs. (I did not test it) There are some functions, such as nxml-up-element. I bet you can create a powerful macro. But I think it’s easier to smooth out the code and do it manually.

+1
source

Source: https://habr.com/ru/post/906942/


All Articles