4125 Feedback on JSP editing

I have been heavily using IntelliJ 5.1 for web development work using JSP, Javascript, Java, JDBC.
I have been noting done issues for the past month. Following are bugs / requests for enhancement.

First some bugs which appear to be fixed in latest 4125

FIXED Paste-Reformat each line doesn't work in jsp <% %> context
FIXED 4069: In JSP context, Basic Completion cancels if you type SPACE or semi-colon


PROBLEMS (verified still existing in 4125)


- Still some slowness when editing a JSP file with 1000s of lines and/or lots
of <% %> blocks. Operations like cut/paste or delete word / navigation / paste word
sometimes sees delays; Usually only 1 second, but that is annoying when you are just
doing simple text manipulations.

- Inspections aren't active in <%! %> declaration sections.
In particular doesn't show unused variables in <%! %> sections.
And doesn't show missorted modifiers in <%! %> context.

- Cannot perform safe delete in jsp context <% %>. An Error Message says
"Cannot perform refactoring. Safe Delete is not supported in current context"


- Wierd behavior when doing introduce constant in a jsp <% %> context.
+ problem #1: If you don't have a <%! %> block in the file, IntelliJ creates one... but
it creates it at the very top of the file. Should be ahve the @page imports.
+ problem #2: It doesn't insert a newline before the new constant declaration.
So, after doing CTRLALTC a few times, I have several declarations all in one line.


- JSP Formatter needs serious work to become useful.
- The java code must be indented correctly and maintain the indent level
while spanning many <% %> blocks. Right now I am running into problems on many
files. On the sample file below, hit RETURN after the else statement. The cursor
is not set to the correct indent level. Also the end brace of the else statement
is not indented correctly.
- We really need a JSP tab to the Global Code Style options so we can configure
how we want JSPs formatted.

+ We need control over how the <% %> blocks are formatted.
- Option to always place <% and %> at column 1.
- or Option to always indent <% %> blocks according to HTML level (seems to be what it does now)
- Merge contiguous <% %> blocks, e.g.
<% if (flag) { %>
<% } else if (flag2) { %>
<% } %>
becomes
<% if (flag) {
} else if (flag2) {
} %>
- Option to control newlines before and after <% and %>
Insert new lines before: [ <%, %>]
Remove new lines before: [ <%, %>]
Insert new lines after: [ <%, %>]
Remove new lines after: [ <%, %>]

NOTE: I tried to add '%' to the Insert new line before: option in HTML formatting tab,
plus unchecked Keep line breaks, but it didn't work. Even if it did work, I don't want
to have to uncheck Keep link breaks, because I have even more problems with the HTML
formatting when this is unchecked.

- Could have special handling for oneline java statements.
Collapse oneline java statements to one line <% statement; %>

Insert new lines before: [ <%, %>]
Remove new lines before: [ ] + Create Class Refactoring within JSP context throws Exception. REQUEST - When copy&pasting code between jsp pages, it doesn't carry over the imports like it does when copy&pasting code between java files. Normally a dialog pops up showing you all the imports required for the pasted code. - HTML Formatter needs some options to beautify your HTML code. - option to lowercase all tags - option to convert to xhtml - convert all quotes to single quotes (have to be careful here, if the attribute value contains single quotes, then don't do it.) - Related to above, could have option to convert to XHTML. Most of this could be handled by the formatter, but some might have to be inspections. + Lower-case elements and attributes:

---> + Nasty Nesting ---> Nice Nesting +
--->
Slashify empty elements (always put a space before the slash) +

Paragraph --->

paragraph

Endify nonempty elements, if only

+ Quotify all attribute values:
    --->
      or
        , if only + Don't style and script elements + Don't use < or & or \]\]\> or -- in a style or script elements (but ok in 'd files) + Encode & in URL's or other attribute values:
+ No line breaks or multiple spaces in attribute values (inside the quotes) + Use name and id together (except radio buttons) "); %>

flag == false

flag == false

]]>


Attachment(s):
4125_test_jsp_after_format.png
4125_html_formatter_settings.png
22 comments

Another bug I forgot to mention. (I might have already filed Jira on this).

If I have two JSP files:

Test1.jsp
-


<%!
int myVar;
static int myStaticVar;
%>

<%
int calculation = myVar + myStaticVar;
%>

Test2.jsp
-


<%!
int myVar;
static int myStaticVar;
%>

<%
int calculation = myVar + myStaticVar;
%>

For this simple exmaple they are identical, but in my workspace I have many JSP files which declare variables with the same name in their local <%! %> scope, but they are used differently and in fact have nothing to do with each other. The java code in Test1 <% %> can't access myVar and myStaticVar in Test2, and vice versa.

But if I do a find usages on myVar or myStaticVar, IntelliJ will show me usages of them in both Test1.jsp and Test2.jsp

A slightly different scenario which has the same problem is when I am trying to find usages within a JSP file of a variable which is declared in an included JSP fragment which is shared amoung many JSP files. The find usages should show me the usages only within the JSP file I am in, not in all the JSP files. For example, I have a file Global.jspf which defines some common variables like platform, user, etc. When I am editing A.jsp which includes Global.jspf, if I do find usages on platform, I should only see the usages in A.jsp and Global.jspf.



Attachment(s):
4125_usages_of_myVar.png
4125_usages_of_myStaticVar.png
0

I had forgotten I had already posteda about this problem:

4069 JSP: find usages handles declaration context <%! %> incorrectly
http://www.intellij.net/forums/thread.jsp?forum=22&thread=181927

http://www.jetbrains.net/jira/browse/IDEA-6069

0

My biggest beef with the JSP support is the formatter. It's unusable to edit
legacy JSPs that have a very "custom" formatting, barely usable for editing JSPs
that are more complex than hello-world.jsp and it cannot deal with JSPs that
produce X(HT)ML.

Wrong auto-indent after pressing ]]> in JSPs
http://www.jetbrains.net/jira/browse/IDEA-6412

Bad code formatting in JSPs that declare content-type "application/xhtml+xml"
http://www.jetbrains.net/jira/browse/IDEADEV-2873

JSP-Reformat should (allow to) indent HTML according to code-blocks
http://www.jetbrains.net/jira/browse/IDEABKL-3268

Being able to edit JSPs just like plain text would be so much better sometimes.
I realize it's not gonna happen, but mentioning the desire to turn it off can't
hurt anyway ;)

Ability to disable JSP formatting
http://www.jetbrains.net/jira/browse/IDEA-3955

And of course there's the issue that IDEA thinks to know how I should code my
webapps/JSPs. Please make this an inspection with configurable highlighting, the
hardcoded warning for legal code is a bad compromise and not very IDEA-like.

IntelliJ IDEA produces "Unhandled Exception"-Warnings in JSPs
http://www.jetbrains.net/jira/browse/IDEA-5297


Sascha

0

Yes, the formatter and line indent when hitting RETURN at end of line is the most annoying problem.

In large, complicated files, I can't trust the formatter to do the right thing since it is usually confused and gets the indent levels wrong.

IntelliJ should be calculating indent levels of the java code without regard to indent level of '<%' or '%>' or the indent level of the the html tags. Actually, I suppose someone might like it to indent starting at '<%', but that only works if the formatter can place the each '<%' at the right level.

It looks like IntelliJ newline indent algorithm is just looking at the enclosing indent level of the '<%' rather than backing up to the last line of java code.

For example,
<%
int a;
%>

If I move '<%' 10 spaces in, and then reindent "int a;", it will be indented starting at position of the '<%', rather than the previous last java line, or in this case, the outer class level which should be indent level 1.

<%
int a;
%>

I would rather IntelliJ ignore the position of '<%', and do
<%
int a;
%>

I guess this may be personal preference, but I think of all the code within the <% %> blocks as being part of one big method, so I want them all indented at the same level, irregardless of the position of '<%' '%>' tags and the html tags.

0

Here is another example where JSP indenter doesn't work the same as the java indenter:
]]>
Both the test() method and the <% %> block are works in progress. If I was in midstream of writing test() method and hit RETURN after the if statement, it is indented to the proper level. But if I hit RETURN after the if statement in the <% %> context, it is indented level with the if keyword, which is wrong.

0

Here's a wierd quirk with the Narrow Scope insepction.
]]>
It says that variable b could have it's scope narrowed, but if I invoke the intention all it does is:
]]>
And it still says that the scope is too broad, but invoking narrow scope further does nothing.



Attachment(s):
4125_scope_too_broad_false_positive.png
4125_scope_too_broad_false_positive_after_narrow_scope.png
0


Another reason for IntelliJ to have JSP code style
settings for "Newline before [ <% %>]" and
"Newline after [ <% %>]" is that the refactorings and intentions don't know what to do.

In my JSP code, I usually put the <% and %> on separate
lines,e.g.
<%
int a;
%>

When I invoke a refactoring like Introduce Constant, Introduce Variable, or an intention like Narrow Scope what it is doing is putting the %> at the end of the line like this:
<%
int a;%>

It would be nice to have this configurable in a JSP tab in Code Style settings and then have refactorings and intentions use that.

0

Another request I had forget to mention was for IntelliJ to be smarter about copying text from HTML context to java <% %> context and vice versa.

For example,

If I paste a <% block %> inside a <% %> block, it should strip out the <% %>.... Often times I will copy or cut a a few lines of code enclosed by <% %> and move them into
another <% %> block.

]]>
If I cut the <% if () { ... } %> text which includes a java block <% %>, an html block, and a java block <% %>, and then paste it into the upper <% %> block, I want IDEA to automatically do this:

]]>


Similarly, if I copy the text '> from an HTML block, and then paste it into a string "" in a java block or even a regular java class, IDEA should convert the ]]> to quotes with plus signs, i.e. "<a href='"url"'>"label"</a>";

The opposite should also work, so if I highlight an expression which evaluates to a String, I should be able to paste it into an HTML block and any java varaiables will be wrapped in <%=variable%> blocks.

That would be very handy.

I can think of even more helpful things along these lines, but it starts getting complicated.

One really useful thing if possible, would be to let me transform some java code which looks like this:
out.println("<blah blah=\""variable"\">");
into this:
">]]>

I have had situations where I had a ton of servlet java code which I wanted to convert to JSP code, and the ability to transform the text would have been very useful.

0

Simple jsp page

case 1

case 2.1

case 2.2

case 3

0

Inspections aren't active in <%! %> declaration sections.
In particular doesn't show unused variables in <%! %> sections.


To me unused private members are shown. Nonprivate members are not highlighted even in java.

And doesn't show missorted modifiers in <%! %> context.


Fixed.

- Cannot perform safe delete in jsp context <% %>. An Error Message says


Safe delete local variables is really not supported. This has nothing to do with jsp.

0

JSP BUGS STILL PRESENT IN 4125

I slogged through a bunch of the JSP Jira requests, and came up with the following outstanding issues which have reproducible examples which I verified as still broken as of 4125. Most have to do with JSP formatter, auto-indenter, editing, syntax highlighting.

Wrong auto-indent after pressing in JSPs http://www.jetbrains.net/jira/browse/IDEA-6412 JSP : The Java Indenter and Formatter are completely wrong when is enclosed by a tag. http://www.jetbrains.net/jira/browse/IDEA-6109 Surround With in JSP causes Exception and produces broken code http://www.jetbrains.net/jira/browse/IDEA-5097 Pasting code into a JSP code block doesn't use Settings->Editor->Paste->Reformat: Indent Each Line http://www.jetbrains.net/jira/browse/IDEA-5352 Identation in JSP http://www.jetbrains.net/jira/browse/IDEABKL-1738 Moving lines in jsp do some mistakes http://www.jetbrains.net/jira/browse/IDEABKL-2986 Jsp Includes. Recognize the opposite way. http://www.jetbrains.net/jira/browse/IDEABKL-3003 Need a way to reference JSP dynamic include pages. http://www.jetbrains.net/jira/browse/IDEABKL-224 http://www.jetbrains.net/jira/browse/IDEABKL-3072 Unscramble Stacktrace should resolve jsps JSP-Reformat should (allow to) indent HTML according to code-blocks http://www.jetbrains.net/jira/browse/IDEABKL-3268 JSP imports layout ->]]></span> Prefer one import statement per page directive selected has no effect.<br/>http://www.jetbrains.net/jira/browse/IDEA-2940<br/> <br/>Inspection Results incorreclty says JSP file is Read-only<br/>http://www.jetbrains.net/jira/browse/IDEADEV-2507<br/><br/>JSP highlights one-line JSP blocks as comments<br/>http://www.jetbrains.net/jira/browse/IDEADEV-2486</p>

0

JSP BUGS FIXED (as tested in 4125)

During my long hard slog through 109 jsp bugs,
I found that the following bugs were fixed.

P.S. The Jira database is already a mess, with lots of stale bugs.

Duplication of methods inside JSP-pages leads to an endless exception-loop
http://www.jetbrains.net/jira/browse/IDEABKL-2195

Completion inside tag (JSP) doesn't works
http://www.jetbrains.net/jira/browse/IDEABKL-2162

Problem with <%= %> expression in page attribute of jsp:forward
http://www.jetbrains.net/jira/browse/IDEA-6446

Rename-Refactoring seriously broken inside JSP with IDEA 5.0.1
http://www.jetbrains.net/jira/browse/IDEA-4739

syntaxcheck for jsp pages don't search in include files
http://www.jetbrains.net/jira/browse/IDEABKL-324

wrong caret position after typing in jsp import
http://www.jetbrains.net/jira/browse/IDEA-1889

Reformatted standard JSP template indents wrong
http://www.jetbrains.net/jira/browse/IDEA-2127

JSP imports are positioned at line 1 instead
http://www.jetbrains.net/jira/browse/IDEA-3679

Codestyle issue in JSP with placing catch on new line
http://www.jetbrains.net/jira/browse/IDEA-3680

Imported class code checks not working correctly with <jsp:include> tags
http://www.jetbrains.net/jira/browse/IDEABKL-2121

0

Here are some requests for advanced refactoring specific to JSP pages.

JSP: refactor java code to jsp mixed java/html code
http://www.jetbrains.net/jira/browse/IDEABKL-2531

Extract tag from JSP refactoring
http://www.jetbrains.net/jira/browse/IDEABKL-3141

Extract Tag from jsp refactoring
http://www.jetbrains.net/jira/browse/IDEABKL-2064

Extract bean from jsp code refactoring
http://www.jetbrains.net/jira/browse/IDEABKL-2065

0

FIXED Paste-Reformat each line doesn't work in jsp <% %> context


Actually, this isn't fixed. It works if you copy/cut a single line and paste it at a different indent level. But if you copy/cut multiple line block of code and paste it, it still ignores you Editor->Paste->Reformat: Indent Each Line
setting.

Pasting code into a JSP code block doesn't use Settings->Editor->Paste->Reformat: Indent Each Line
http://www.jetbrains.net/jira/browse/IDEA-5352

0

Ok, I understand that safe delete local variables is really not supported.

But the real problem is that JSP includes really breaks alot of assumptions. Better to think of JSP files as scraps of java code which can be combined together to form different combinations of java classes.

public, protected, package private, private doesn't mean anything. The scope of the variable is the JSP file(s) that contain the variable declaration. I'm not an expert on the JSP specification; Is there some way a JSP file can access a variable declared in another JSP without including it?

For example, the "unused private variable" will fail in the following example.

-


test.jsp----


%>

0

I just wanted to say thank you for doing this as I do a lot of JSP editing
and all these bugs have been driving me nuts!

Thanks,
Grant


"Alex" <no_mail@jetbrains.com> wrote in message
news:19260264.1138173833679.JavaMail.itn@is.intellij.net...
>> FIXED Paste-Reformat each line doesn't work in jsp <% %> context
>

Actually, this isn't fixed. It works if you copy/cut a single line and
paste it at a different indent level. But if you copy/cut multiple line
block of code and paste it, it still ignores you Editor->Paste->Reformat:
Indent Each Line
setting.

>

Pasting code into a JSP code block doesn't use
Settings->Editor->Paste->Reformat: Indent Each Line
http://www.jetbrains.net/jira/browse/IDEA-5352



0

OK. I filed new requests for the items mentioned above which didn't have existing Jira requests. Please vote and/or comment if you like.

JSP -- Refactor->Introduce Constant and Refactor->Introduce Field issues
http://www.jetbrains.net/jira/browse/IDEA-6495

JSP: Global Code Style Settings needs a JSP tab for JSP-specific constructs like <%! %> and <% %> blocks
http://www.jetbrains.net/jira/browse/IDEA-6496

JSP - When copy&pasting a large block of code between jsp pages, it doesn't carry over the imports as it does with Java files
http://www.jetbrains.net/jira/browse/IDEA-6497

JSP - Autoindent places at wrong indent level
http://www.jetbrains.net/jira/browse/IDEA-6498

JSP - false positive with Scope Too Broad Inspection
http://www.jetbrains.net/jira/browse/IDEA-6499

JSP - Quickfix 'Simplify' for Constant If Condition and Intetion Invert If Condition throw Exceptions and mangle code
http://www.jetbrains.net/jira/browse/IDEA-6500

IntelliJ should automatically convert between <%=expression%> and expression constructs when copy&pasting between HTML and java code
http://www.jetbrains.net/jira/browse/IDEA-6501

JSP - Private field 'unused' false positive when included JSP fragments use the field.
http://www.jetbrains.net/jira/browse/IDEA-6502

0

I wanted to highlight one of the requests I filed. Please comment if you have any ideas.

JSP: Global Code Style Settings needs a JSP tab for JSP-specific constructs like <%! %> and <% %> blocks
http://www.jetbrains.net/jira/browse/IDEA-6496

I think the JSP formatter really needs some customizable settings in order to be useful. For example, there is no control over how <%! %> and <% %> code blocks are formatted.

Currently, IDEA appears to indent code based on the indent level of the most recent <% tag.
For example, the java line below is indted from the spot of the <% tag.

<%
int a;
%>

I think of all the code within the <% %> blocks as being part of one big method, so I want them all indented at the same level, irregardless of the position of '<%' '%>' tags and the html tags.

I also would like all the <% and %> tags to be placed at column 1. For example:

The other big issue is there is no control of newlines before and after the <% and %> tags..

The following options would be great in a JSP tab.

  • Option to always place <% and <%! and %> at column X (default 1).

Otherewise, the <%, <%!, and %> will be placed according to the HTML indent level.

  • Option to indent java code based on overall indent level, i.e. the indent level each line would

be at if you removed all HTML from the file and combined all the java code in all <% %> blocks
together. The formatter will ignore the position of the <% and <%! tags. Note that this would
require that the <% , and <%! tags have a newline after them, and the %> tag have a newline before them.
Otherwise, the java code will be indented relatively to the indent level of each <% tag

  • Option to control newlines before and after <% and %>

Insert new lines before: [ <%, %>]
Remove new lines before: [ <%, %>]
Insert new lines after: [ <%, %>]
Remove new lines after: [ <%, %>]
I would like to keep or don't keep the linebreaks around the <% and %> tags independantly of
the HTML Keep Linke Breaks option. I guess a format similar to the HTML code settings would be:
Keep line breaks around <%, <%!, and %> tags
Insert new lines before: [ <%, %>]
Insert new lines after: [ <%, %>]

  • Merge contiguous <% %> blocks, e.g.

<% if (flag) { %>
<% } else if (flag2) { %>
<% } %>
becomes
<% if (flag) {
} else if (flag2) {
} %>

  • Could have special handling for oneline java statements.

Collapse oneline java statements to one line <% statement; %>

0

JSP - auto indent needs to be more robust. It shouldn't fail because of missing %> tag or because of HTML syntax errors that are downstream.
http://www.jetbrains.net/jira/browse/IDEA-6503

0

One simple thing that should be done is IDEA should emit a matching %> tag whenever you type ]]>.

If we have JSP code style settings I want (see above), then IDEA could also automatically format and position the cursor also.

So, if I type

I should see
]]>

This will help out on the poor auto-indenter because it gets really confused if you don't have a matching %> tag.

JSP - IDEA should output a matching %> tag whenever you type ]]>
http://www.jetbrains.net/jira/browse/IDEA-6504

0

Please sign in to leave a comment.