Why can't eclipse jsp editor parse java block comment in sperate scripts?

Eclipse JSP editor cannot parse Java block comment in separate scripts like

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

      

This is how it looks in Eclipse:

screenshot

In practice, we know the code in between /* */

will be commented out, but the eclipse editor shows the code in between the normal text. This is completely confusing.

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

So, is there a way 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>

      

+3


source to share


1 answer


This is a great way to write hard code. While you have a point that this could be a technical bug in the editor, I would not rely on it to work reliably: the JSP is compiled into a servlet (turned inside out) and then compiled into bytecode.

  • I view hidden code in this way - instead of using <%-- --%>

    - to be intentionally evil, and that style would not have passed (my) code review.
  • Nothing prevents the JSP-> Servlet compiler from generating block comments. Then it will be easy for you to have nested block comments - illegal code - which will be invisible in the JSP (won't happen with your example, but once the jsp tags are in play, it is quite possible)


Take this behavior as a hint that you should rewrite your code in a different way and not rely on the JSP-> Servlet compiler to always follow your current mental model. It may also break with a future compiler update in a year - in which case you will need to remember what you did here, why you did it. And you wouldn't understand why it was running all the time and suddenly stopped. You probably won't tie it to a servlet container update someone did behind your back.

0


source







All Articles