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 210804

Summary: Implement an interface into an existing class
Product: editor Reporter: Geertjan Wielenga <geertjan>
Component: Hints & AnnotationsAssignee: Dusan Balek <dbalek>
Status: RESOLVED FIXED    
Severity: normal CC: jglick
Priority: P3    
Version: 7.2   
Hardware: PC   
OS: Linux   
Issue Type: DEFECT Exception Reporter:

Description Geertjan Wielenga 2012-04-06 10:10:31 UTC
From 7.2 onwards, there's a hint on an interface for generating its implementations. But it assumes you want to create a new class; it doesn't let you select an existing class where the interface should be implemented.
Comment 1 Jan Lahoda 2012-04-06 10:27:12 UTC
Does not sounds like a defect to me.
Comment 2 Geertjan Wielenga 2012-04-06 10:33:28 UTC
Well, I think this one is a defect because if you type an existing class into the dialog, a new class is created. I would expect the normal behavior to be that if an existing class is entered, the interface will be added to the interfaces declared in the existing class, not in a new one.
Comment 3 Jan Lahoda 2012-04-06 10:43:54 UTC
Yes, I agree it should add the interface to the list of implemented interfaces in such a case.

Dusan, I do not remember if there was a reason to instantiate the template before entering the user task, but note that there is GeneratorUtilities.createFromTemplate now. If the template wouldn't be instantiated before the user task, that would make a fix for this much easier, I think. Note that a new file can be created by calling WorkingCopy.rewrite(null, CUT).
Comment 4 Geertjan Wielenga 2012-04-06 11:26:39 UTC
Since this is a defect, could it be fixed for 7.2?
Comment 5 Jesse Glick 2012-04-06 12:21:57 UTC
Why wouldn't you just type "implements WordProcessor" at the end of the existing class definition and then accept to hint to implement all unimplemented methods?
Comment 6 Geertjan Wielenga 2012-04-06 13:14:27 UTC
Because the nice thing about this hint is that you can define your interface and then, from the interface, automatically implement it.

But even if you disagree with this, then it still is an error that the user can enter an existing class and then end up having the hint create a new class. E.g., if I type "MyImpl" and then "MyImpl" already exists, the hint will create "MyImpl1". That's simply wrong.
Comment 7 Dusan Balek 2012-04-11 13:31:06 UTC
Fixed in jet-main.

http://hg.netbeans.org/jet-main/rev/4e7f17de507b
Comment 8 Quality Engineering 2012-04-13 09:50:56 UTC
Integrated into 'main-golden', will be available in build *201204130400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/4e7f17de507b
User: Dusan Balek <dbalek@netbeans.org>
Log: Issue #210804: Implement an interface into an existing class - fixed.