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 132787 - CodeTemplate: formatting is incorrect (extra CR)
Summary: CodeTemplate: formatting is incorrect (extra CR)
Status: VERIFIED FIXED
Alias: None
Product: javafx
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: All Windows XP
: P3 blocker (vote)
Assignee: David Strupl
URL: http://openjfx.java.sun.com/jira/brow...
Keywords:
Depends on: 132764 133460
Blocks:
  Show dependency tree
 
Reported: 2008-04-14 16:24 UTC by Lark Fitzgerald
Modified: 2008-07-09 19:38 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
exception text (3.78 KB, text/plain)
2008-06-20 18:50 UTC, Lark Fitzgerald
Details
The incomming text in AST for this. (11.52 KB, text/plain)
2008-06-27 10:31 UTC, Rastislav Komara
Details
Reatached as image :), sorry (11.52 KB, image/png)
2008-07-09 10:19 UTC, Rastislav Komara
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lark Fitzgerald 2008-04-14 16:24:42 UTC
Product Version: NetBeans IDE Dev (Build 200804091204)
Java: 1.6.0_10-beta; Java HotSpot(TM) Client VM 11.0-b11
System: Windows Vista version 6.0 running on x86; Cp1252; en_US (nb)
Plugin: CB#385 (2008-04-14_13-59-24.zip)

1. goto editor and type:
el
2. press the tab key.  I get:

    else {
        

        }

The template shows as:
else {
   ${selection line}${cursor}
}

I was expecting only one CR between the { }
Comment 1 Lark Fitzgerald 2008-04-14 16:32:58 UTC
I also see the extra CR with:
eli
for
if
ife
tr
wh
Comment 2 Rastislav Komara 2008-04-15 10:05:41 UTC
I think this issues belongs to you. Indentation issues will be fixed with
finishing issue #130588
Comment 3 Victor Vasilyev 2008-04-15 14:12:23 UTC
OK 
It seems a problem with the file format. 
The current version of the javafx.editor\src\org\netbeans\modules\javafx\dataloader\DefaultAbbrevs.xml file contains
Windows-like End Of Lines (CR LF) instead of Unix-like EOL (LF).

That is strange for me, why a Mercurial hook doesn't fix it automatically.

It will be fixed manually. 
Comment 4 Victor Vasilyev 2008-04-17 14:54:14 UTC
It seems the problem is here:
org.netbeans.modules.javafx.editor.JFXIndentTask.reformat(JFXIndentTask.java:260)
org.netbeans.modules.editor.indent.TaskHandler$MimeItem.runTask(TaskHandler.java:504)
org.netbeans.modules.editor.indent.TaskHandler.runTasks(TaskHandler.java:271)
org.netbeans.modules.editor.indent.IndentImpl.reformat(IndentImpl.java:293)
org.netbeans.modules.editor.indent.FormatterImpl.reformat(FormatterImpl.java:161)
org.netbeans.lib.editor.codetemplates.CodeTemplateInsertHandler.insertTemplate(CodeTemplateInsertHandler.java:298)
org.netbeans.lib.editor.codetemplates.CodeTemplateInsertHandler.processTemplate(CodeTemplateInsertHandler.java:220)
org.netbeans.lib.editor.codetemplates.CodeTemplateManagerOperation.insert(CodeTemplateManagerOperation.java:238)
org.netbeans.lib.editor.codetemplates.api.CodeTemplate.insert(CodeTemplate.java:104)
org.netbeans.lib.editor.codetemplates.AbbrevDetection.expand(AbbrevDetection.java:404)
org.netbeans.lib.editor.codetemplates.AbbrevDetection.expand(AbbrevDetection.java:360)
org.netbeans.lib.editor.codetemplates.AbbrevDetection.checkExpansionKeystroke(AbbrevDetection.java:264)
org.netbeans.lib.editor.codetemplates.AbbrevDetection.keyPressed(AbbrevDetection.java:224)
...

All mentioned code templates have the same format of definitions as in modules for other languages, including a code
template for the "fi" abbreviation.
Windows EOLs are not an issue (it is fixed now).
Comment 5 Rastislav Komara 2008-04-22 17:02:15 UTC
update schedule.
Comment 6 Lark Fitzgerald 2008-06-19 16:46:29 UTC
1. If I type:
var exp : Boolean = true;
2. then type:
wh
3. then press TAB

I get:
while (exp) {
    }

The spacing is wrong but the AST is not empty.  The same is true for tr, ife, if, or for.  I do however get the empty 
AST for el and eli but this looks like it happens because the if part of the statement is missing.  In Java, this 
gives a very helpful error: else without if.  Will log jira for this case.

tested using build:
Product Version: NetBeans IDE 6.1 (Build 200804211638)
Java: 1.6.0_10-beta; Java HotSpot(TM) Client VM 11.0-b11
System: Windows Vista version 6.0 running on x86; Cp1252; en_US (nb)
fx NB61 nighly plugin: 269
Comment 7 Lark Fitzgerald 2008-06-19 16:52:41 UTC
Logged jira for el and eli
http://openjfx.java.sun.com/jira/browse/JFXC-1389

The spacing issues still need to be resolved separately since the AST does not appear to affect them.
Comment 8 Rastislav Komara 2008-06-20 10:55:16 UTC
Fixed. If AST is OK the spacing works corrctly.
Comment 9 Lark Fitzgerald 2008-06-20 18:49:21 UTC
el + TAB not throws an exception:
javax.swing.text.BadLocationException: offset=-1 < 0
	at org.netbeans.modules.editor.indent.IndentImpl.checkOffsetInDocument(IndentImpl.java:322)

Full exception attached.
Comment 10 Lark Fitzgerald 2008-06-20 18:50:37 UTC
Created attachment 63178 [details]
exception text
Comment 11 Lark Fitzgerald 2008-06-20 18:51:24 UTC
Tested using:
Product Version: NetBeans IDE 6.1 (Build 200804211638)
Java: 1.6.0_10-beta; Java HotSpot(TM) Client VM 11.0-b11
System: Windows Vista version 6.0 running on x86; Cp1252; en_US (nb)
fx NB61 nighly plugin: 271
Comment 12 Rastislav Komara 2008-06-23 10:53:57 UTC
The issue with bad position fixed.
Comment 13 Alexandr Scherbatiy 2008-06-25 14:38:19 UTC
- Type if
- Press the tab key
 The result is 
-------------------------
if (exp) {
   

}
--------------------------

It contains extra cr:
if (exp) {
   
   // extra cr
}
Comment 14 Rastislav Komara 2008-06-27 10:30:04 UTC
This is not an issue for reformat. I already get this with 2 new lines. See attachment. Lark, please try to find correct
assignee for this issue.
Comment 15 Rastislav Komara 2008-06-27 10:31:07 UTC
Created attachment 63585 [details]
The incomming text in AST for this.
Comment 16 Lark Fitzgerald 2008-07-08 20:52:27 UTC
Assigning to david, Possibly related to the templates themselves?
Comment 17 David Strupl 2008-07-09 08:10:32 UTC
Rasto, please don't attach images as text/plain.

I think the problem is in the templates --- Victor what do you think?
Comment 18 Rastislav Komara 2008-07-09 10:19:48 UTC
Created attachment 64150 [details]
Reatached as image :), sorry
Comment 19 David Strupl 2008-07-09 10:32:30 UTC
In the FX templates there is
${selection line}${cursor}
while in java there is
${selection}${cursor}
Could that be the problem?
Comment 20 David Strupl 2008-07-09 13:42:40 UTC
Fixed by fixing the templates in 
847:a2d7040e9f70
Comment 21 Lark Fitzgerald 2008-07-09 19:38:04 UTC
Verified using cb333.