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 242741 - Code generator does not offer superclass constructors
Summary: Code generator does not offer superclass constructors
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.0
Hardware: PC Linux
: P3 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-10 12:42 UTC by jesselong
Modified: 2016-04-26 11:18 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 2014-03-10 12:42:57 UTC
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 7.3 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.0, 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 2014-03-25 07:47:17 UTC
I can confirm that this is still an issue in Netbeans 8.0 final.
Comment 2 Dusan Balek 2014-06-09 17:45:31 UTC
Fixed in jet-main.

http://hg.netbeans.org/jet-main/rev/f284966d16e4
Comment 3 Quality Engineering 2014-06-19 02:35:51 UTC
Integrated into 'main-silver', will be available in build *201406190001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/f284966d16e4
User: Dusan Balek <dbalek@netbeans.org>
Log: Issue #242741: Code generator does not offer superclass constructors - fixed.