Alt-Enter in Code Completion Box

Let's say you have this class:
public class Customer {
    
    String type;
    
    public Customer() {
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

}

Now, somewhere else in your application, you need to work with the Customer object.

So, you create and initialize a new Customer, somewhere, and then later you want to call the getter on the customer. So you call up code completion (Ctrl-Space):

Now, here are three different keys that you can press when you're exactly at the place shown above in the code completion box, together with the result when you do so:

  • Enter:
    c.getType()
  • Semicolon:
    c.getType();
  • Alt-Enter:
    String type = c.getType();

The latter, Alt-Enter, is new  in the upcoming NetBeans IDE 7.1, created by NetBeans engineer Dusan Balek, based on an issue by Tom Wheeler. When you use Alt-Enter, the entire statement is generated (i.e., the method is selected and the assignment is done and the semicolon is created), while the cursor ends up on the name (e.g., "type" above) so that you can immediately change it if needed, before continuing with your coding.

Cool, isn't it?

Comments:

Cool indeed!

Don't forget
- dot (".") for:
c.getType().

Posted by guest on September 12, 2011 at 06:29 AM PDT #

this looks really good, I will remember this ,thanks to Dusan and you.

Posted by ranjan on September 12, 2011 at 05:41 PM PDT #

Another issue I filed is now implemented for NetBeans 7.1:

http://netbeans.org/bugzilla/show_bug.cgi?id=176314

This adds a transpose feature to the editor, so when you type something like this:

Person geertjan = new Preson();

You can now just put your cursor between the 'r' and 'e' in the misspelled class name and hit Ctrl-T to fix it, just like you can in emacs or the bash shell.

Thanks to Miloslav Metelka and Dusan Balek for implementing these helpful features.

Posted by Tom Wheeler on September 13, 2011 at 01:34 AM PDT #

I would like to see that as the default behaviour when you press Enter. Why not?

When you press Enter in Code Completion Box one of these should happen:
- Generate the entire statement.
or
- Complete the code and add ';' at the end.

I can't imagine a good reason not to do this by default when Enter is pressed. If you do not want to create the entire statement then you press '.', ';' or space.

Posted by Carlos Eduardo Klock on September 17, 2011 at 05:13 PM PDT #

Alt-Enter in Code Completion Box is an excelent feature. I tested now in NetBeans 7.1 Beta. It seems 7.1 is faster, but maybe is only a first impression...

Posted by guest on September 23, 2011 at 04:02 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today