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 142159 - [65cat] Code completion to create constructors with parameters
Summary: [65cat] Code completion to create constructors with parameters
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 blocker with 1 vote (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-29 22:59 UTC by malfunction84
Modified: 2013-09-02 14:24 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description malfunction84 2008-07-29 22:59:00 UTC
When invoking CC to generate a constructor, the only option provided is that of a "default" (no-argument) constructor,
even when the superclass has no such constructor.  The result is generated code that does not compile.

It would be great if the CC would scan the superclass for all constructors, including those with parameters, and provide
CC options for constructors of the current class with the same parameters.  The resulting code would provide automatic
pass-through of the arguments to a generated call to the appropriate super(...) constructor.

For instance:

public class TestParent {
    private String s;

    TestParent(String s) {
        this.s = s;
    }
}

public class TestChild extends TestParent {
    | (*code-completion invoked*)
+-----------------------------------------+
| * TestChild(String) - generate          |
| o clone() - override             Object |
| o equals(Object) - override     boolean |
| o finalize() - override            void |
| ...                                     |
+-----------------------------------------+
}

Selecting the first option would generate:

public class TestChild extends TestParent {
    public TestChild(String s) {
        super(s);
    }
}
Comment 1 Michel Graciano 2008-07-30 02:58:19 UTC
> When invoking CC to generate a constructor, the only option provided is that of a "default" (no-argument) constructor,
> even when the superclass has no such constructor.  The result is generated code that does not compile.
Agreed! The IDE never should create code that don't compile.

Beside that, I think that Alt + Insert > Constructor... should help you. With it is possible choose the parameters for
constructor.

Regards.
Comment 2 malfunction84 2008-07-30 20:26:18 UTC
Yes, that is helpful.  Thanks.

Still, whatever inspection occurs to generate the constructor list provided by the code insertion dialog should provide
that same constructor list to the code completion dialog.  These sorts of constructors are similar in function to
overridden methods which, when generated by code completion, automatically chain to the superclass's implementation and
pass all arguments through.