Bug 495125 - Generate Constructor: Allow Insertion point after last field
Summary: Generate Constructor: Allow Insertion point after last field
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.6   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-01 05:32 EDT by Roland Illig CLA
Modified: 2016-06-03 04:25 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Roland Illig CLA 2016-06-01 05:32:25 EDT
Currently, when generating a constructor, it is inserted after the last member. In the common case where a class already has methods, this will be after the last method.

It should be possible to insert the constructor between the fields and the method, where it belongs, according to the Java Coding Conventions.

References:
http://www.oracle.com/technetwork/java/codeconventions-150003.pdf, section 3.1.1, p1.
Comment 1 Stephan Herrmann CLA 2016-06-01 18:21:04 EDT
Are you referring to 
  - Source > Generate Constructor using Fields...
  - Source > Generate Constructors from Superclass...
?

Both these commands are completely agnostic to ordering, they just insert their stuff at the current cursor location (and thus don't stop you from having it at your desired location).

Do you observe s.t. different?
Comment 2 Roland Illig CLA 2016-06-02 02:48:49 EDT
(In reply to Stephan Herrmann from comment #1)
> Are you referring to 
>   - Source > Generate Constructor using Fields...
>   - Source > Generate Constructors from Superclass...
> ?

Yes, exactly.

When I click on “Source > Generate Constructor using Fields...”, a large dialog opens. Below the checkbox-list of fields, there is a combobox where I can select the “Insertion point”. I was referring to that.
Comment 3 Stephan Herrmann CLA 2016-06-02 07:22:54 EDT
(In reply to Roland Illig from comment #2)
> (In reply to Stephan Herrmann from comment #1)
> > Are you referring to 
> >   - Source > Generate Constructor using Fields...
> >   - Source > Generate Constructors from Superclass...
> > ?
> 
> Yes, exactly.
> 
> When I click on “Source > Generate Constructor using Fields...”, a large
> dialog opens. Below the checkbox-list of fields, there is a combobox where I
> can select the “Insertion point”. I was referring to that.

Thanks. So this combo is initialized with s.t. like "after foo()" describing the current cursor position, which makes this the default behavior. The combo also offers "first member" and "last member", the latter selecting the behavior you describe.

=> You seem to be requesting another fixed option here. Which one would it be?
- "After last field"
- "First method"
?

I.e., what happens if fields and methods are happily mixed in a file? Other question: should this option distinguish constructors from regular methods? Should the option, e.g., read: "Last constructor"?
Comment 4 Roland Illig CLA 2016-06-03 04:25:03 EDT
(In reply to Stephan Herrmann from comment #3)
> => You seem to be requesting another fixed option here. Which one would it
> be?
> - "After last field"
> - "First method"
> ?
> 
> I.e., what happens if fields and methods are happily mixed in a file?

I prefer the choice “After last field”.

> should this option distinguish constructors from regular methods?

When there are constructors, the new constructor should be inserted below the existing ones.

> Should the option, e.g., read: "Last constructor"?

When I generate a constructor, it is mostly because no other constructor exists. Therefore this wording could be confusing. Same for “Before first method” when the methods don’t exist yet.