Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 186419 - improve Autosuggest, Code completion for class instantiation, repetitive usage and local variables
improve Autosuggest, Code completion for class instantiation, repetitive usag...
Status: RESOLVED FIXED
Product: java
Classification: Unclassified
Component: Editor
6.x
PC Windows 7 x64
: P2 (vote)
: 7.4
Assigned To: Dusan Balek
issues@java
: USABILITY
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-05-20 08:54 UTC by ssteiner
Modified: 2013-04-17 11:52 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ssteiner 2010-05-20 08:54:59 UTC
This always bugs me when I switch between Visual Studio and Netbeans:

Assume I'm working in a package structured as follows:

com.mycompany.package1 (containing classes Pack1Class1, Pack1Class2, Pack1Class3)
com.mycompany.package2 (containing classes Pack2Class1, Pack2Class2, Pack2Class3)
com.mycompany.package3 (containing classes Pack3Class1, Pack3Class2, Pack3Class3)

Now, I'm coding and I need to initialize a new class in one of the packages.

private test myTestMethod()
{
String cLocalVar = new String("hello world");
}

Now, after declaring cLocalVar, I need to instantiate a Pack1Class. So, inside the curly brackets I start typing:

c

At that point, Visual Studio would already suggest 

cLocalVar
com

(in that order since alphabetically sorted)

Netbeans just sits there doing nothing. It would greatly help if its autosuggest were as forthcoming.

Now let's go on.. so after typing com., autosuggest finally kicks in, so I can select mycompany, then package1, then Pack1Class1. Then I define the variable name, add the equal sign and type new. So now we have this line: 

com.mycompany.package1.Pack1Class1 localVar = new 

As I press space after the "new" keyword, Visual Studio's code completion automatically suggests "com.mycompany.package1.Pack1Class1". In Netbeans, I end up having to type "com." then press tab 3 more times until I'm there (and if I wanted it to be package2.Pack2Class3 then I'd have to work even more).

I'd like to propose that Netbeans suggest "com.mycompany.package1.Pack1Class1" after typing new - Java is after all statically typed so I do have to type that anyway (or cast a derived class - but even there the suggested line would be helpful as it is what has to be put in the cast brackets).

And since I mentioned instantiating package2.Pack2Class3 let's stick with that for a moment.

Assume that I have just typed

com.mycompany.package3.Pack1Class3 localVar2 = new com.mycompany.package3.Pack1Class3();
com.mycompany.

At that point, in the autosuggest, Netbeans will give me package1 (of course followed by package2 and package3) when I press tab. Visual Studio will preselect package3 (because that's what I last used) After selecting package3 from the autosuggest, Netbeans will suggest Pack3Class1 (followed of course by Pack3Class2 and Pack3Class3), whereas Visual Studio will have Pack3Class3 preselected from the autosuggested values (once again because that's what I last used). So, with visual studio, repetitive usages (and we all don't like the pure typing work, do we?), can be performed more effectively and I'd propose that Netbeans emulate this behavior. 

While I made the example with packages and classes, it of course should also apply to local and global variables as well as methods.
Comment 1 ssteiner 2010-05-20 09:02:40 UTC
And I almost forgot

Suppose I have an enum declared in com.mycompany.package1:

public enum Pack1Enum {Value1, Value2, Value3};

and a method:

private com.mycompany.package1.Pack1Enum testMethod()
{

return new com.mycompany.package2.Pack2Class1()
}

now when I call that method

this.testMethod
Comment 2 ssteiner 2010-05-20 09:06:52 UTC
And I almost forgot

Suppose I have an enum declared in com.mycompany.package1:

public enum Pack1Enum {Value1, Value2, Value3};

and a method:

public static com.mycompany.package1.Pack1Enum testMethod()
{
return Pack1Enum.Value1;
}

So in my code using those packages, if I type

if (com.mycompany.package1.testMethod() == 

Then Visual Studio would realize that what I get back is com.mycompany.package1.Pack1Enum and would suggest

com.mycompany.package1.Pack1Enum

thus sparing me from typing "com." until the autosuggest kicks in, then press tab two more times then select Pack1Enum from the list until I'm at the same point. And, it would be even more work if the return value of testMethod were com.mycompany.package2.Pack2Enum...
Comment 3 ssteiner 2010-05-20 09:47:05 UTC
And I got one more.

Suppose Pack3Class2 has one constructor:

public Pack3Class2(String param1, String param2)
{
// do something
}

In my code I'm using Pack3Class2:

com.mycompany.package3.Pack3Class2 p3c2 = new com.mycompany.package3.Pack3Class2

At that point, Visual Studio gracefully suggests all the available constructors. Netbeans just sits there waiting for me to figure out what kind of constructors there are.
Comment 4 Dusan Balek 2013-04-17 11:52:59 UTC
Similar behavior could be achieved by enabling 'Auto Popup on Typing Any Identifier Part' and adding space character to 'Auto Popup Triggers for Java' in Tools -> Options -> Editor -> Code Completion -> Java. You could also limit the list of 'Completion Selectors for Java' to '.(' in such a case.


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