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.
User problem: ----------------------------------- -- User need: ----------------------------------- The user often wants to surround certain piece of code with if, for, try/catch, synchronized, etc. statement. This is awkward since he has to jump to the beginning, position the cursor right, type the code, jump to the end, position cursor, write a code. The IDE can automate this. Product requirement: ----------------------------------- Surround selected code with if, for, try/catch etc. statements.
Added URL of Gabo's UI spec. Gabo: The spec misses one thing (which is a bit more tricky): Once you wrap something into runnable, all the local variables that are used from inside the wrapped block have to be re-declared as final (or new final local variables if the original ones are written to later) Example: private void dummy(String s) { comp.setText(s); } -> private void dummy(final String s) { Runnable runnable = new Runnable() { public void run() { comp.setText(s); } }; } One more note: most of the time you're just passing the runnable somewhere and rarely store the Runnable, so it may be better to provide pass-as-runnable action instead: private void dummy(final String s) { |(new Runnable() { public void run() { comp.setText(s); } }); }
For your information, work on surround by try/catch has been started. Honzo, have you see the UI spec?
*** Issue 50065 has been marked as a duplicate of this issue. ***
*** Issue 28971 has been marked as a duplicate of this issue. ***
Honzo L., are you going to implement it for NB 4.2? If not please reassign this issue to me. Thanks.
Started - new branch created "private_surround_with_try_catch" Checking in editor/src/org/netbeans/modules/editor/java/Bundle.properties; /cvs/java/editor/src/org/netbeans/modules/editor/java/Bundle.properties,v <-- Bundle.properties new revision: 1.8.18.1; previous revision: 1.8 done Checking in editor/src/org/netbeans/modules/editor/java/JavaKit.java; /cvs/java/editor/src/org/netbeans/modules/editor/java/JavaKit.java,v <-- JavaKit.java new revision: 1.10.2.1; previous revision: 1.10 done Checking in editor/src/org/netbeans/modules/editor/java/NbJavaSettingsInitializer.java; /cvs/java/editor/src/org/netbeans/modules/editor/java/NbJavaSettingsInitializer.java,v <-- NbJavaSettingsInitializer.java new revision: 1.2.28.1; previous revision: 1.2 done Checking in editor/src/org/netbeans/modules/java/editor/resources/DefaultKeyBindings.xml; /cvs/java/editor/src/org/netbeans/modules/java/editor/resources/DefaultKeyBindings.xml,v <-- DefaultKeyBindings.xml new revision: 1.2.28.1; previous revision: 1.2 done Checking in editor/src/org/netbeans/modules/java/editor/resources/layer.xml; /cvs/java/editor/src/org/netbeans/modules/java/editor/resources/layer.xml,v <-- layer.xml new revision: 1.4.16.1; previous revision: 1.4 done Checking in javacore/src/org/netbeans/modules/javacore/TryWrapper.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/TryWrapper.java,v <-- TryWrapper.java new revision: 1.7.16.1; previous revision: 1.7 done
Basic version of surround with try catch implemented: Checking in java/editor/src/org/netbeans/modules/editor/java/Bundle.properties; /cvs/java/editor/src/org/netbeans/modules/editor/java/Bundle.properties,v <-- Bundle.properties new revision: 1.10; previous revision: 1.9 done Checking in java/editor/src/org/netbeans/modules/editor/java/JavaKit.java; /cvs/java/editor/src/org/netbeans/modules/editor/java/JavaKit.java,v <-- JavaKit.java new revision: 1.12; previous revision: 1.11 done Checking in java/editor/src/org/netbeans/modules/editor/java/NbJavaSettingsInitializer.java; /cvs/java/editor/src/org/netbeans/modules/editor/java/NbJavaSettingsInitializer.java,v <-- NbJavaSettingsInitializer.java new revision: 1.3; previous revision: 1.2 done Checking in java/editor/src/org/netbeans/modules/java/editor/resources/DefaultKeyBindings.xml; /cvs/java/editor/src/org/netbeans/modules/java/editor/resources/DefaultKeyBindings.xml,v <-- DefaultKeyBindings.xml new revision: 1.3; previous revision: 1.2 done Checking in java/editor/src/org/netbeans/modules/java/editor/resources/layer.xml; /cvs/java/editor/src/org/netbeans/modules/java/editor/resources/layer.xml,v <-- layer.xml new revision: 1.6; previous revision: 1.5 done Checking in java/javacore/src/org/netbeans/modules/javacore/TryWrapper.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/TryWrapper.java,v <-- TryWrapper.java new revision: 1.8; previous revision: 1.7 done Checking in java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/ElementFinder.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/ElementFinder.java,v <-- ElementFinder.java new revision: 1.4; previous revision: 1.3 done
*** Issue 60420 has been marked as a duplicate of this issue. ***
Any status update on this? Also will the try-catch be intelligent and look at the exceptions thrown, or just catch "Exception" as shown in the UI Doc?
Surround with try-catch is fully functional in the NB 5.0 and it is "smart" in terms of what exceptions are being catched.
Thank you for the heads up You mind if I run through IZ and close all the surround with requests?
I don't mind. Actually I appreciate that :) But please close only "surround with try-catch" issues. For instance this issue covers also surround with if | for | while statement etc. That is why the issue is still open. Thanks!
Implemented in 6.0
Already fixed.