Refactor -> Extract Include File buggy or just limited / fragile?

I had the perfect job for the new Refactor->Extract Include
File: I have a very long JSP file which I wanted to break
up into multiple smaller JSP files.

I selected a portion of the file. The selection starts in
an HTML block and ends in an HTML block with many JSP blocks in between. When I invoked Refactor->Extract Include File, it just says "Cannot extract: selection does not form a fragment for extraction. OK HELP". (BTW the Help button gives an error.) I looked into the documentation and the explanation for this is very sparse. It says: "The Extract include... refactoring is used to extract HTML, JSP/JSPX, JavaScript or CSS pieces into separate include files. Select code block and press Refactor | Extract include...." It doesn't list any limitations. I imagine it would have a problem because the JSP code in the selected lines of code refers to some variables defined earlier in the JSP file. I was thinking "Extract Include" would handle this like Extract Method does. I guess it is more difficult with JSP fragments because you would have to pass these external variables as parameters and that wouldn' t work if they couldn't be converted to/from Strings? For example: I then tried to extract some smaller blocks of JSP code which only referred to standard variables like "out" and " request" which are always defined for JSPs so shouldn't have to be passed. This worked but it was kind of tempermental. Take simple example: "); %> If I highlight just the "String s..." line or the "String s..." to the "out.println.." lines, the Extract Include would fail with the same message: "Cannot extract: selection does not form a fragment for extraction. OK HELP". But if I hilight all four lines including the , then it works! Now, if I take a slightly more complicated example: this is a test

"); %>

this is a test

If I highlight all of the above lines, then Extract Include will work. But if I highlight from to ]]>, then
Extract Include won't work. It appears that it barfs if
you have unmatched HTML tags! I don't think Extract
Include should really care if my HTML tags match up or not.
I can see this making complicated, real-world usage more

To make this useable (with current limitations), the Error
Message needs to say what the specific problem is, e.g. line
number, unmatched tag/symbol?, etc. With the current
generic error message, it is easier for me to split up the
file by hand than to try to figure out what Extract Include
is complaining about.

Also, it would be nice if the Help button works and the Help
documented what the limitations are.

Please sign in to leave a comment.