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.
According to the doc: "... indent only but does not do any other code beautification." To reproduce using jVi (starting with clean userdir) Do Tools > Options > JavaCode > Formatting Category: Alignment and Braces Tab: Braces Placement for both ClassDeclaration and MethodDeclaration select "New Line". Leave Other as "Same Line". Then reindent a method and notice that braces get moved around. More peculiar is that "if" braces gets moved around. Of course no braces should be moved around, but its moving more braces than even a reformat would not move. Here's a specific example, in jVi put the cursor on the line 'void foo', and enter the three character command "6==" to reindent 6 lines. Expect nothing to happen after reindent, since indentation is correct. Notice that brace after Method decl and brace after "if" are both moved. Then select the method with mouse and do Alt-Shft-F and the "if" brace gets moved back up. void foo() { bar(1,2); if(sl.isEmpty()) { System.err.println("hello"); } } ===== after reindent ===== void foo() { bar(1,2); if(sl.isEmpty()) { System.err.println("hello"); } } ===== after reformat ===== void foo() { bar(1, 2); if (sl.isEmpty()) { System.err.println("hello"); } } Product Version: NetBeans IDE Dev (Build 200807101204) Java: 1.6.0_03; Java HotSpot(TM) Client VM 1.6.0_03-b05 System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb) Userdir: C:\Documents and Settings\erra\.netbeans\dev
> Here's a specific example, in jVi put the cursor on the line 'void foo', and enter the three character command "6==" > to reindent 6 lines. How exactly is this implemented in jVi? > Expect nothing to happen after reindent, since indentation is correct. Depending on the above question this statement may not be true. If this is done by reformatting the 6 lines area the action will apply all formatting rules. If jVi invokes Indent.reindent(startOffset, endOffset) than the statement is correct and something's broken on our side. > Notice that brace after Method decl and brace after "if" are both moved. Then select the method with mouse > and do Alt-Shft-F and the "if" brace gets moved back up. This is definitely weird.
It uses Indent.reindent. BTW, before filing the bug I verified that this is the code that is being invoked, since I couldn't believe it either. I just checked, things work fine on 6.1. > How exactly is this implemented in jVi? @Override public void reindent(int line, int count) { if(getDoc() instanceof BaseDocument) { BaseDocument doc = (BaseDocument)getDoc(); boolean keepAtomicLock = doc.isAtomicLock(); if(keepAtomicLock) doc.atomicUnlock(); Indent indent = Indent.get(doc); indent.lock(); try { doc.atomicLock(); try { indent.reindent(getLineStartOffset(line), getLineEndOffset(line + count - 1)); } catch (BadLocationException ex) { ex.printStackTrace(); } finally { if(!keepAtomicLock) doc.atomicUnlock(); } } finally { indent.unlock(); } } else { Util.vim_beep(); } }
It is not P2 imo.
This is working now. I'll close it.
Reopening. Following directions from a clean userdir still creates the problem. (now get there by: Tools > Options > Editor > Formatting; Lang: Java, Category: Braces) BTW, I initially filed against editor component. But does this implementation come under a "java" component? Product Version: NetBeans IDE Dev (Build 200807251401)
Part of the problem's explanation is that in createTask, see backtrace excerpt below, there is Lookup lookup = MimeLookup.getLookup(mimePath); ... IndentTask.Factory factory = lookup.lookup(IndentTask.Factory.class); and factory is null when the mimePath is "MimePath[text/x-java]: RT: null". So later, since there are no tasks, at org.netbeans.modules.editor.indent.IndentImpl.reindent(IndentImpl.java:198) it can't indent, so it decides to use the formatter. org.netbeans.modules.editor.indent.TaskHandler$MimeItem.createTask(TaskHandler.java:482) org.netbeans.modules.editor.indent.TaskHandler.addItem(TaskHandler.java:277) org.netbeans.modules.editor.indent.TaskHandler.collectTasks(TaskHandler.java:150) org.netbeans.modules.editor.indent.IndentImpl.indentLock(IndentImpl.java:131) org.netbeans.modules.editor.indent.api.Indent.lock(Indent.java:113) org.netbeans.modules.jvi.NbBuffer.reindent(NbBuffer.java:182) Any hints on where to look for IndentTask for text/x-java? And then how to add it to the mime's lookup? Ironically, I deleted the old, pre 6.5, source trees off of my system yesterday. Looking in there might have helped. I couldn't find any IndentTask in editor.* or java.* in the 6.5 source.
Marek, these are yours now ...
In Comment #6 I discuss that this problem exists because there is no IndentTask registered for text/java; so the editor infrastructure is defaulting to using the format task. Reindent is a common command in jVi/vim; there is a separate command for format. (I keep getting jVi bug reports about this problem). Note that this used to work in 6.1. I vaguely remember that there was some infrastructure re-org that happened in 6.5, and I wonder if the problem is simply that indent was never hooked up for java when porting to the new infrastructure. Reassigning to java editor, since that is probably where the issue is. If someone can point to where the indent code lives in the java editor (or say that the feature is no longer supported) I can take a look at it; a pointer to where the format is registered would also be helpful.
(In reply to comment #8) > Note that this used to work in 6.1. I vaguely remember that there was some > infrastructure re-org that happened in 6.5, and I wonder if the problem is > simply that indent was never hooked up for java when porting to the new > infrastructure. Oh yes :-). > Reassigning to java editor, since that is probably where the issue is. If > someone can point to where the indent code lives in the java editor (or say > that the feature is no longer supported) I can take a look at it; a pointer to > where the format is registered would also be helpful. Somewhere around JavaFormatSupport and JavaFormatter in java.editor.lib module. AFAIK this is still using the old Syntax and should be converted to use lexer tokens and registered as IndentTask. Be warned though, it's ugly and a few people already declared war to it, but then withdrew.
IndentTask for text/x-java implemented. See http://hg.netbeans.org/jet-main/rev/62d7737905e6 So hopefully this issue gets fixed.
Hooray.