Bug 154823 - [getter setter] Getters Setters generation doesn't follow naming convention
Summary: [getter setter] Getters Setters generation doesn't follow naming convention
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 3.5 M7   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 201874 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-08-23 03:50 EDT by Mark Platvoet CLA
Modified: 2011-10-26 08:57 EDT (History)
8 users (show)

See Also:


Attachments
A simple program that show the difference (618 bytes, text/plain)
2006-08-23 10:56 EDT, Mark Platvoet CLA
no flags Details
Proposed patch (6.37 KB, patch)
2009-04-22 09:28 EDT, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Platvoet CLA 2006-08-23 03:50:19 EDT
The getter and setter generation doesn't follow naming convention. Attributes like

private String eMail;

Should have a corresponding getter and setter like:
public String geteMail();
public void seteMail(String eMail);

This applies to all attributes where the second character of the attribute is a capital and the first is not.
Comment 1 Mark Platvoet CLA 2006-08-23 04:46:37 EDT
This seems to affect a lot more than only getter and setter generation. I'm, for instance, using the springIDE plugin and it reports that property 'eMail' doesn't excist if I declare the setter as 'seteMail'. This probably implies that this plugin is leaning on information provided by Eclipse. 

In runtime the method 'seteMail' is correctly found.
Comment 2 Maxime Daniel CLA 2006-08-23 05:38:51 EDT
Moving to JDT UI.
Comment 3 Torsten Juergeleit CLA 2006-08-23 10:04:26 EDT
(In reply to comment #1)
> This seems to affect a lot more than only getter and setter generation. I'm,
> for instance, using the springIDE plugin and it reports that property 'eMail'
> doesn't excist if I declare the setter as 'seteMail'. This probably implies
> that this plugin is leaning on information provided by Eclipse. 
> 
> In runtime the method 'seteMail' is correctly found.
> 
Regarding the spec-conformant behaviour of Spring IDE please refer to the comment http://springide.org/project/ticket/355#comment:1 on the corresponding Spring IDE ticket.
Comment 4 Mark Platvoet CLA 2006-08-23 10:56:49 EDT
Created attachment 48470 [details]
A simple program that show the difference
Comment 5 Martin Aeschlimann CLA 2006-08-29 09:42:39 EDT
We should follow the bean conventions with say:
"Thus when we extract a property or event name from the middle of an existing Java name, we
normally convert the first character to lower case. However to support the occasional use of all
upper-case names, we check if the first two characters of the name are both upper case and if
so leave it alone. So for example,
“FooBah” becomes “fooBah”
“Z” becomes “z”
“URL” becomes “URL”
We provide a method Introspector.decapitalize which implements this conversion rule."
(http://java.sun.com/products/javabeans/docs/spec.html)

The conclusion is:
For a field called eMail, we should call the getter 'geteMail'. If we would call it getEMail, Java Beans would conclude that this is a constant name and assume the property is 'EMail'.

Getter and setter names are created using NamingConvention.suggestGetter/SetterName. Moving to jdt.core.

Comment 6 David Audel CLA 2009-04-22 09:28:24 EDT
Created attachment 132764 [details]
Proposed patch
Comment 7 David Audel CLA 2009-04-22 09:31:03 EDT
Released for 3.5M7.

Tests added
  NamingConventionTests#testSuggestGetterName010() -> testSuggestGetterName013()
Comment 8 Srikanth Sankaran CLA 2009-04-28 07:32:52 EDT
Verified for 3.5M7 using I20090428-0100
Comment 9 David Audel CLA 2009-06-29 06:11:53 EDT
*** Bug 201874 has been marked as a duplicate of this bug. ***
Comment 10 Markus Keller CLA 2011-01-20 06:00:55 EST
This has come up again in bug 322223 (just in case someone CCd here wants to voice an opinion).