6

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?

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588

2 Answers2

1

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.

0

Yes. You can Use place holders in Eclipse using regular expressions and change accordingly.

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

Click Search [ Ctrl+H ], Check Regular expression option and filepattern to jsp.

enter image description here

Press Ctrl+space for content assist.

enter image description here

Click search for matching, Replace to replace all matched string's in one single go. You can use Regex groups for replacing content

enter image description here

enter image description here

enter image description here

Ratna Dinakar
  • 1,573
  • 13
  • 16
  • 1
    OP is well aware of this: *"I know I can do most of this with searching / replacing, but it feels unsafe as it ignores code structure."* OP was more looking for the same refactoring functionality as in normal Java source code by Alt+Shift+L. – BalusC Jan 26 '12 at 14:55
  • 1
    This answer doesn't really say how to do what the OP is asking, just what he can use to cobble together his own solution, which likely won't be equivalent to an "extract variable" operation. – millimoose Jan 26 '12 at 14:56
  • I Have used the same to achieve package renaming for about.. 350 java files in single shot :) ! I felt it might help using regular expression groups :) – Ratna Dinakar Jan 26 '12 at 14:56
  • @BalusC exactly. Still: +1 to the poster for his efforts – Sean Patrick Floyd Jan 26 '12 at 14:57
  • 1
    @Ratna: package/class/method/variable renaming in Java source files can in Eclipse just be done by Alt+Shift+R. Search&Replace is not reliable enough. Even more, package renaming can also be done by pressing just F2 on package in Eclipse project explorer. – BalusC Jan 26 '12 at 15:00
  • @BalusC I had a requirement to add extend other class too to the class declaration !! – Ratna Dinakar Jan 26 '12 at 15:02