This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 116022 - Scriptlet formatting doesn't work
Summary: Scriptlet formatting doesn't work
Alias: None
Product: javaee
Classification: Unclassified
Component: JSP (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Tomasz Slota
: 118380 (view as bug list)
Depends on:
Blocks: 118615
  Show dependency tree
Reported: 2007-09-19 15:40 UTC by Tomasz Slota
Modified: 2009-02-22 18:49 UTC (History)
8 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:

attaching stacktrace of ArrayIndexOutOfBoundsException (2.76 KB, text/plain)
2007-10-18 10:59 UTC, Jindrich Sedek
jsp file to reproduce easily (922 bytes, text/plain)
2007-10-18 11:01 UTC, Jindrich Sedek

Note You need to log in before you can comment on or make changes to this bug.
Description Tomasz Slota 2007-09-19 15:40:54 UTC
Scriptlet formatting doesn't work due to the fact that java formatter is not receiving information of which parts of the file should be formatted. Milo please 
reassign the issue to Dusan after providing the enhancements we discussed (in the formatting framework).
Comment 1 Petr Jiricka 2007-10-01 10:44:12 UTC
Assigning to the editor component.
Comment 2 Miloslav Metelka 2007-10-13 00:52:09 UTC
The requierements should be addressed but I would like to add some more tests before reassigning to Dusan.
Checking in indent/src/org/netbeans/api/editor/indent/;
/cvs/editor/indent/src/org/netbeans/api/editor/indent/,v  <--
new revision: 1.4; previous revision: 1.3
Checking in indent/src/org/netbeans/api/editor/indent/;
/cvs/editor/indent/src/org/netbeans/api/editor/indent/,v  <--
new revision: 1.4; previous revision: 1.3
Checking in src/org/netbeans/modules/editor/;
/cvs/editor/src/org/netbeans/modules/editor/,v  <--
new revision: 1.44; previous revision: 1.43
Checking in indent/apichanges.xml;
/cvs/editor/indent/apichanges.xml,v  <--  apichanges.xml
new revision: 1.5; previous revision: 1.4
Checking in indent/src/org/netbeans/modules/editor/indent/;
/cvs/editor/indent/src/org/netbeans/modules/editor/indent/,v  <--
new revision: 1.4; previous revision: 1.3
Checking in indent/src/org/netbeans/modules/editor/indent/;
/cvs/editor/indent/src/org/netbeans/modules/editor/indent/,v  <--
new revision: 1.12; previous revision: 1.11
Checking in indent/src/org/netbeans/modules/editor/indent/;
/cvs/editor/indent/src/org/netbeans/modules/editor/indent/,v  <--
new revision: 1.14; previous revision: 1.13
Checking in indent/src/org/netbeans/modules/editor/indent/;
/cvs/editor/indent/src/org/netbeans/modules/editor/indent/,v  <--
new revision: 1.10; previous revision: 1.9
Checking in indent/src/org/netbeans/modules/editor/indent/;
/cvs/editor/indent/src/org/netbeans/modules/editor/indent/,v  <--
new revision: 1.6; previous revision: 1.5
Checking in lib/nbproject/;
/cvs/editor/lib/nbproject/,v  <--
new revision: 1.24; previous revision: 1.23
Checking in indent/src/org/netbeans/spi/editor/indent/;
/cvs/editor/indent/src/org/netbeans/spi/editor/indent/,v  <--
new revision: 1.6; previous revision: 1.5
Checking in libsrc/org/netbeans/editor/;
/cvs/editor/libsrc/org/netbeans/editor/,v  <--
new revision: 1.150; previous revision: 1.149
Checking in indent/nbproject/;
/cvs/editor/indent/nbproject/,v  <--
new revision: 1.5; previous revision: 1.4
Checking in indent/test/unit/src/org/netbeans/api/editor/indent/;
/cvs/editor/indent/test/unit/src/org/netbeans/api/editor/indent/,v  <--
new revision: 1.7; previous revision: 1.6
Checking in lib/apichanges.xml;
/cvs/editor/lib/apichanges.xml,v  <--  apichanges.xml
new revision: 1.12; previous revision: 1.11
Comment 3 Jan Pokorsky 2007-10-15 12:51:21 UTC
*** Issue 118380 has been marked as a duplicate of this issue. ***
Comment 4 Vitezslav Stejskal 2007-10-16 09:03:08 UTC
Passing to Dusan...
Comment 5 Miloslav Metelka 2007-10-16 16:43:11 UTC
Additional fix for giving indent regions' bounds always within bounds of global bounds.
/cvs/editor/indent/src/org/netbeans/modules/editor/indent/,v  <--
new revision: 1.13; previous revision: 1.12
Comment 6 Dusan Balek 2007-10-17 08:40:03 UTC

Checking in;
/cvs/java/source/src/org/netbeans/modules/java/source/save/,v  <--
new revision: 1.20; previous revision: 1.19
Comment 7 Miloslav Metelka 2007-10-17 13:34:06 UTC
So it should now be fixed completely. Since this is beta2fix I would like to first ask tslota to confirm that the fix
eliminates the problem and then QE whether I can integrate into beta2 branch. Only the two last fixed files need to be
integrated (the previous complex fix is already in beta2).
Comment 8 Jindrich Sedek 2007-10-17 17:02:53 UTC
I'm affraid this issue is not ready to be integrated into beta2. After invoking reformat code over jsp file containing 
this scriptlet code:
int i = 1;
if (i < 50) {i++;
ArrayIndexOutOfBoundsException is thrown and JAVA code is reformated, but not indented - it seems to be reformated, but 
than "reindented" by html formatter -> reassigning to tslota
Comment 9 Tomasz Slota 2007-10-17 18:57:23 UTC
I have some changes in my build, which may (but are unlikely to, except perhaps the new line indent) influence the behavior. Anyways, on my machine:

- I cannot reproduce the ArrayIndexOutOfBoundsException problem, Jindro can you please attach the stack trace?
- new line indentation doesn't work at all
- formatting Jindra's sample produces the following result:

            application.getAttribute("ATTRIB"); // indent base is one step too big
            int i = 1;
            if (i < 50) {
} // closing bracket not indented at all

Jindro, the Java formatter is called after the JSP and HTML formatters. 

Current (as of beta2 and hopefully final) implementation of the JSP/HTML formatting does the following to blocks of embedded 3rd languages (such as Java 
or CSS):

- the first line is indented according to HTML/JSP rules
- indentation of the following lines is shifted by the difference with the first line - in other words the whole block of embedded code is shifted but 
formatting within it is preserved. Embedded language formatter should keep the indentation of the first line of the embedded block unchanged and format 
the other lines accordingly.

- the expected behavior of new line indentation is that HTML/JSP formatter will not adjust the indent at all if the cursor is placed inside embedded block

It looks like the ball is on Dusan's side, anyways, let's discuss it tomorrow
Comment 10 Jindrich Sedek 2007-10-18 10:59:08 UTC
Created attachment 51201 [details]
attaching stacktrace of ArrayIndexOutOfBoundsException
Comment 11 Jindrich Sedek 2007-10-18 11:01:25 UTC
Created attachment 51202 [details]
jsp file to reproduce easily
Comment 12 Miloslav Metelka 2007-10-19 13:16:59 UTC
I guess that me and Dusan can fix the 

} // closing bracket not indented at all

but the last AIOOBE is entirely inside 
which (although it seems that's an editor stuff :) ) was entirely created and maintained by the web team.
So unfortunately IMHO we can't fix this into beta2.
Comment 13 Tomasz Slota 2007-10-23 15:32:05 UTC
Marek volunteered to coordinate this one.
Comment 14 Marek Fukala 2007-10-24 15:39:15 UTC
fixed indentation in java scriptlet, that is the part I promised to fix. Reassigning back to Tomasz for reevaluation
since I am not sure if I can close the issue as fixed.

Checking in;
/cvs/web/jspsyntax/src/org/netbeans/modules/web/core/syntax/formatting/,v  <--
new revision: 1.3; previous revision: 1.2
Checking in;
/cvs/web/jspsyntax/src/org/netbeans/modules/web/core/syntax/formatting/,v  <--
new revision: 1.8; previous revision: 1.7
Comment 15 Tomasz Slota 2007-10-29 15:19:20 UTC
formatting part fixe.

/cvs/editor/indent/src/org/netbeans/modules/editor/indent/,v  <--
new revision: 1.15; previous revision: 1.14
Comment 16 martin_zmrhal 2008-11-05 11:51:31 UTC

Product Version: NetBeans IDE Dev (Build 200811050201)
Java: 1.6.0_10; Java HotSpot(TM) Client VM 11.0-b15
System: Linux version 2.6.27-7-generic running on i386; UTF-8; en_US
Comment 17 David Konecny 2009-02-10 00:56:35 UTC
I have a question about change which was done to resolve this issue. Do I
understand it right that it was a short term hotfix but it never got fixed properly?

What I do not like is that Java formatting is hardcoded in JSP formatter whenever enter is pressed on a Java token.

For now I locally rewrote it so that there is IndentTask.Factory registered in web.core.syntax module for mime
text/x-jsp/text/x-java which returnes IndentTask doing:
  new JspJavaFormatter(JavaKit.class).reformat(context.document(), context.startOffset(), context.endOffset(), true);

That seems to me better than current state, but still half-way solution. Why Java module does not register IndentTask
similarly as it registers ReformatTask?
Comment 18 Marek Fukala 2009-02-10 09:25:00 UTC
Yes, just workaround as stated in the code.
Comment 19 David Konecny 2009-02-17 21:14:06 UTC
Dusan, why Java module does not register IndentTask similarly as it registers ReformatTask? I removed (just locally for
now) original hotfix and now indentation in Java scriptlet does not work. I tried to solve it properly by using (see my previous comment) but that does not work either as JavaFormatter does
not do any checks if tokens being formatted are actually from JavaTokenContext or not - it blindly reindents everything
(eg. HTML tags). What solution do you suggest?
Comment 20 Miloslav Metelka 2009-02-20 13:26:34 UTC
I would like to rewrite the JavaFormatter (still JavaSyntax based) to a regular lexer-based IndentTask. I could possibly make it into 6.7 M3.
However additional changes in the Indent API should be discussed as well but that will require a longer discussion.
Comment 21 David Konecny 2009-02-22 18:49:48 UTC
Thanks Mila. Migrating from old API sounds like good idea. Re "Indent API" - agreed. I have some small API changes done
locally but at this stage it is just for experimentation sake. I will see what comes out of it and will talk to you and