Why eclipse jsp editor cannot parse java block comment in sperate scriptlets?

271 views Asked by At

The Eclipse JSP editor cannot parse the Java block comment in seperate scriptlets like

<% /* %><span> blabla </span><% */ %>

Here's what it looks like in Eclipse:

screenshot

In practice, we know the code between /* */ will be commented out, but eclipse editor shows code between as normal text. That is totally confusing.

I know this case should be avoided, but I got a huge amount of such code to read.

So is there any method to enable syntax highlighting for this case?

Test case:

<TABLE>
        <TR><TD>Normal text</TD></TR>
<% /* %><TR><TD>Unparsed comment</TD></TR><% */ %>
<% /*   <TR><TD>Parsed comment</TD></TR>     */ %>
<%--    <TR><TD>Parsed comment</TD></TR>      --%>
</TABLE>
1

There are 1 answers

0
Olaf Kock On

That's a great way to write unmaintainable code. While you have a point that it might be technically a bug in the workings of the editor, I'd not rely on it to reliably work: A JSP is compiled into a servlet (turned inside out), then compiled to bytecode.

  • I consider hiding code this way - instead of using <%-- --%> - to be intentionally evil and this style wouldn't pass (my) code review.
  • Nothing prevents the JSP->Servlet compiler from generating block comments as well. Then you'd easily have nested block comments - illegal code - which would be invisible in the JSP (wouldn't happen with your example, but as soon as jsp tags are in the game, it might well be)

Take this behaviour as a hint that you should consider rewriting your code in a different way and don't rely on the JSP->Servlet compiler to always follow your current mental model. It might as well break with a future compiler-update in a year - and then you'd have to remember what you did here, why you did it. And you wouldn't have a clue why it worked all the time and suddenly stopped. You'll probably not attribute it to an update to the servlet container that someone did behind your back.