Bug 222337 - Code formatting not working
Code formatting not working
Status: RESOLVED FIXED
Product: editor
Classification: Unclassified
Component: Actions/Menu/Toolbar
7.3
All All
: P2 (vote)
: 7.3
Assigned To: Miloslav Metelka
issues@editor
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-11-18 15:39 UTC by shiretu
Modified: 2012-11-24 13:09 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
:


Attachments
IDE log (42.45 KB, text/plain)
2012-11-19 14:52 UTC, Alexander Simon
Details
IDE log line (286 bytes, text/plain)
2012-11-19 15:06 UTC, shiretu
Details
ScreenShoot (570.04 KB, image/png)
2012-11-19 15:07 UTC, shiretu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description shiretu 2012-11-18 15:39:12 UTC
No code formatting is happening anywhere: C or C++ source or header file

I have tried to format via keyboard shortcut and with the context-menu.
Comment 1 Alexander Simon 2012-11-19 08:03:42 UTC
Investigation:
Method org.netbeans.editor.BaseAction.actionPerformed(final ActionEvent evt) detect wrong target component.
Code:
-------------------8<----------------------
    public final void actionPerformed(final ActionEvent evt) {
        final JTextComponent target = getTextComponent(evt);

        // #146657 - Only perform the action if the document is BaseDocument's instance
        // #147899 - NPE
        if (target == null || !(target.getDocument() instanceof BaseDocument)) {
            return;
        }
-------------------8<----------------------
Target is:
org.openide.awt.QuickSearch$SearchTextField[,26,2,84x19,invalid,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@1782656,flags=296,maximumSize=java.awt.Dimension[width=84,height=19],minimumSize=,preferredSize=,caretColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=10,columnWidth=8,command=,horizontalAlignment=LEADING]
As result the action is not performed.

Stack:
org.netbeans.editor.BaseAction.actionPerformed(BaseAction.java:297)
org.netbeans.spi.editor.AbstractEditorAction.actionPerformed(AbstractEditorAction.java:444)
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
javax.swing.AbstractButton.doClick(AbstractButton.java:357)
javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:809)
javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:850)
java.awt.Component.processMouseEvent(Component.java:6297)
javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
java.awt.Component.processEvent(Component.java:6062)
java.awt.Container.processEvent(Container.java:2039)
java.awt.Component.dispatchEventImpl(Component.java:4660)
java.awt.Container.dispatchEventImpl(Container.java:2097)
java.awt.Component.dispatchEvent(Component.java:4488)
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575)
java.awt.LightweightDispatcher.processMouseEvent(Container.java:4236)
java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166)
java.awt.Container.dispatchEventImpl(Container.java:2083)
java.awt.Window.dispatchEventImpl(Window.java:2489)
java.awt.Component.dispatchEvent(Component.java:4488)
java.awt.EventQueue.dispatchEventImpl(EventQueue.java:668)
java.awt.EventQueue.access$400(EventQueue.java:81)
java.awt.EventQueue$2.run(EventQueue.java:627)
java.awt.EventQueue$2.run(EventQueue.java:625)
java.security.AccessController.doPrivileged(AccessController.java)
java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
java.awt.EventQueue$3.run(EventQueue.java:641)
java.awt.EventQueue$3.run(EventQueue.java:639)
java.security.AccessController.doPrivileged(AccessController.java)
java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
java.awt.EventQueue.dispatchEvent(EventQueue.java:638)
org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:158)
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Reassign to evaluation.
Comment 2 shiretu 2012-11-19 11:27:18 UTC
I just found out that it actually working for some other files. But I have a file on which it simply refuses to do any formatting.

Since you mentioned, yes, there is a bug when the cursor is positioned on the quick search edit box and you try to do Cmd+Click on a symbol. Is not going to the declaration/definition. You have to hide the quick search and than do the cmd+click

Best regards,
Andrei
Comment 3 Alexander Simon 2012-11-19 12:10:24 UTC
(In reply to comment #2)
> I just found out that it actually working for some other files. But I have a
> file on which it simply refuses to do any formatting.
Does IDE log contain errors?
Comment 4 shiretu 2012-11-19 12:15:16 UTC
Where are those IDE logs?
Comment 5 Alexander Simon 2012-11-19 12:21:44 UTC
(In reply to comment #4)
> Where are those IDE logs?
View->IDE log
Comment 6 shiretu 2012-11-19 12:26:15 UTC
Here is the log:


Reformatting failed. Reformatter try to delete important symbol: "// Treat no TERM key as an "OPEN" type license"
	 in changeset:""
Reformatting failed. Reformatter try to delete important symbol: "// Treat no TERM key as an "OPEN" type license"
	 in changeset:""


and the code to reproduce it:

	if(0){
		int a=0;
	}//sample comment
	else
		int b = 1;

For that, I get:
Reformatting failed. Reformatter try to delete important symbol: "//sample comment"
	 in changeset:""
Comment 7 shiretu 2012-11-19 12:33:56 UTC
I have to agree, the sample code that I gave you and the situation that I had in my file were in the gray zone for code "correctness". However, a message with the line number where the problem is would be nice.

After properly positioned the comments, the file was formatted just fine
Comment 8 shiretu 2012-11-19 12:44:56 UTC
Having this "IDE logs" trick is not always working. The IDE logs window is not updating when I try to reformat. The reformat simply fails with no messages o that window. I have to close the IDE logs than open it again to force the IDE to flush the messages on the window
Comment 9 Miloslav Metelka 2012-11-19 14:04:58 UTC
Sorry, I'm confused. What is actually wrong? If you have a focus inside search field then the Reformat action would reformat the field which likely does nothing (it's as designed). If the focus is inside the editor then the reformat works fine for me at least in C and java files.
Comment 10 shiretu 2012-11-19 14:13:02 UTC
I'm sorry, I kind of highjacked the original issue (code formatting) with a new report of a new bug (code navigation not working with focus is on the search box)

To summarise, here are the 2 distinct problems:

1. formatting is not happening when we have that special code situation (I already gave a small piece of C/C++ code to reproduce it)

2. A completely different problem (nothing to do with formatting) which I put it in here just because I saw your stack trace and I just remembered another bug which is search box related (org.openide.awt.QuickSearch$SearchTextField): when the focus is on the quick search edit box, cmd+click is not working. IMO, it should because I'm clicking in a different place and the focus should change and the operation performed. The operation is navigating to the declaration/definition of the symbol that we just cmd+clicked. It should not matter that the cursor is on the quick search box
Comment 11 Miloslav Metelka 2012-11-19 14:39:35 UTC
ad 2)
Tested daily build 20121119 on Ubuntu 12.04 64bit + JDK1.6.0_30 and it works for me in C++ and java. I do Cmd+Click inside the code editor (focus is inside quick search field) and the cursor jumps to the declaration place and the code editor gets focused. Could you attach the messages.log of the IDE to this issue?

ad 1)
Reassigning back to cnd for evaluation. Thanks.
Comment 12 Alexander Simon 2012-11-19 14:47:43 UTC
(In reply to comment #11)
> ad 2)
> Tested daily build 20121119 on Ubuntu 12.04 64bit + JDK1.6.0_30 and it works
> for me in C++ and java. I do Cmd+Click inside the code editor (focus is inside
> quick search field) and the cursor jumps to the declaration place and the code
> editor gets focused. Could you attach the messages.log of the IDE to this
> issue?
> 
> ad 1)
> Reassigning back to cnd for evaluation. Thanks.
Extracted separate bug #222396

reassign buck to editor
Comment 13 Alexander Simon 2012-11-19 14:52:38 UTC
Created attachment 128066 [details]
IDE log
Comment 14 Alexander Simon 2012-11-19 15:06:46 UTC
Steps to reproduce:
- create Fractal C/C++ sample
- open fractal.cc file
- put cursor on 52 line
- select in project tree "Source Files" folder
- Tools->Options->Formatting->C++
- Select another style (for example "OpenSolaris")
- OK
- right click on line 52 and select format
Expected behavior:
- format action is performed
Actual behavior:
- format action is not performed

I can reproduce this behavior on Ubuntu and Solaris.
We have a lot of customer complains that format action does not work on the first attempt.
Comment 15 shiretu 2012-11-19 15:06:55 UTC
Created attachment 128069 [details]
IDE log line
Comment 16 shiretu 2012-11-19 15:07:52 UTC
Created attachment 128070 [details]
ScreenShoot
Comment 17 shiretu 2012-11-19 15:08:34 UTC
OS: Mac OS X 1.8.2 (Mountain Lion)

NetBeans:
Product Version: NetBeans IDE 7.3 Beta 2 (Build 201211062253)
Java: 1.6.0_37; Java HotSpot(TM) 64-Bit Server VM 20.12-b01-434
Runtime: Java(TM) SE Runtime Environment 1.6.0_37-b06-434-11M3909
System: Mac OS X version 10.8.2 running on x86_64; MacRoman; en_US (nb)
User directory: /Users/shiretu/Library/Application Support/NetBeans/7.3beta2
Cache directory: /Users/shiretu/Library/Caches/NetBeans/7.3beta2
Comment 18 Miloslav Metelka 2012-11-19 16:49:07 UTC
I cannot reproduce on my machine but I'll consult with our QE whether they can reproduce with the given steps.
Btw is the step "- select in project tree "Source Files" folder" crucial or it would fail without it as well? Thanks.
Comment 19 Alexander Simon 2012-11-19 17:15:02 UTC
(In reply to comment #18)
> I cannot reproduce on my machine but I'll consult with our QE whether they can
> reproduce with the given steps.
> Btw is the step "- select in project tree "Source Files" folder" crucial or it
> would fail without it as well? Thanks.
No. Bug can be reproduced without "select in project tree "Source Files" folder".
Comment 20 Miloslav Metelka 2012-11-22 12:45:11 UTC
(In reply to comment #19)
> No. Bug can be reproduced without "select in project tree "Source Files"
> folder".

Well I still don't understand why the active text component is a Quick search text field when you've never interacted that component during the steps-to-reproduce.
 Do you have any special focus policy e.g. focus-follows-mouse or don't you know about any hint that would possibly clarify this? Thanks.
Comment 21 Alexander Simon 2012-11-22 13:12:23 UTC
(In reply to comment #20)
> Well I still don't understand why the active text component is a Quick search
> text field when you've never interacted that component during the
> steps-to-reproduce.
>  Do you have any special focus policy e.g. focus-follows-mouse or don't you
> know about any hint that would possibly clarify this? Thanks.
I do not exactly understand what you mean.
Platform:

#uname -a
SunOS asimon 5.10 Generic_127112-10 i86pc i386 i86pc

Desktop system: GNOME

I do not change focus policy. As I said, the bug is reproduced on Ubuntu 12.4.
Comment 22 David Strupl 2012-11-22 14:30:22 UTC
Mila was referring to the fact that the target component of your format action was QuickSearch$SearchTextField which is something outside of the (big) editor.
Comment 23 Alexander Simon 2012-11-22 15:28:45 UTC
(In reply to comment #22)
> Mila was referring to the fact that the target component of your format action
> was QuickSearch$SearchTextField which is something outside of the (big) editor.
Yes it is a problem. Why target component is QuickSearch$SearchTextField while 
popup menu is invoked inside editor?
Comment 24 Miloslav Metelka 2012-11-22 16:10:49 UTC
I've added a focus request for the editor component in case there's a context menu invoked for it. Hopefully that will resolve the problem. If not please reopen the issue.
http://hg.netbeans.org/jet-main/rev/a1d96b192098
Comment 25 Quality Engineering 2012-11-24 13:09:02 UTC
Integrated into 'main-golden', will be available in build *201211240959* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/a1d96b192098
User: Miloslav Metelka <mmetelka@netbeans.org>
Log: #222337 - Code formatting not working.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo