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.

Bug 259016 - Code generator does not offer superclass constructors
Summary: Code generator does not offer superclass constructors
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.2
Hardware: PC Linux
: P3 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-26 11:17 UTC by jesselong
Modified: 2017-04-20 09:56 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jesselong 2016-04-26 11:17:07 UTC
Firstly, this is an exact duplicate of issue 242741. Exact same problem that was fixed before. Logging a duplicate because the problem has presented itself again. Sorry if that is incorrect procedure.

When I subclass an existing class that has constructors with parameters, I go to the body of the subclass and press CNTRL-SPACE. It brings up one constructor suggestion, which builds a constructor without any arguments.

eg:

public class SuperThing
{
    public SuperThing(String x){}
    public SuperThing(String x, int y){}
}

public class SubThing extends SuperThing
{
    |
}

"|" is the caret. I press CNTRL-SPACE, and it suggests "SubThing() - generate". If I select this option, I get:

public class SubThing extends SuperThing
{
    public SubThing()
    {
        super(null);
    }
}

I would like the return of the 8.0.1 behavior, where I would get two suggestions:
"SubThing(String) - generate" and "SubThing(String, int) - generate", resulting in (if I select the first suggestion):

public class SubThing extends SuperThing
{
    public SubThing(String x)
    {
        super(x);
    }
}

Now, in NB 8.1, before there is any constructor in SubThing, there is actually an error on the SubThing class. When I click on the error, it gives me two options, to create either of the constructors as I want. Both of these options work exactly as I need them, but I can only select one. After selecting the first option, the error is cleared from the SubThing class, and I have no way of selecting to additionally create the second constructor.

In conclusion, this is what I want:

1. When subclass has error on class level because missing default constructor, add a new option to create all constructors in super class. (Please leave existing options, they are good, just add this new one).
2. In CNTRL-SPACE menu, add suggestions to create constructors, one entry for each constructor in the super class.
3. In CNTRL-SPACE menu, remove no-args constructor when superclass does not have no-args constructor. It doesn't make sense. How will NB know which super constructor to call. It would have to guess. It may often get it wrong.

I think #1 and #2 are really necessary. I dont mind if you decline request #3.

PS. If I do this:

public class SubThing extends SuperThing
{
    private final double g;

    |
}

And press CNTRL-SPACE at caret "|", then I get three suggested constructors:
"SubThing() - generate", "SubThing(double g, String x) - generate" and "SubThing(double g, String x, int y) - generate". This is perfect. We just need the same logic when there are no uninitialized fields in the subclass.
Comment 1 jesselong 2017-04-20 09:55:30 UTC
Problem is still present in 8.2.