Bug 322223 - Generate Getter/Setter creates wrong names for fields having upper case second char
Summary: Generate Getter/Setter creates wrong names for fields having upper case secon...
Status: VERIFIED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Linux
: P3 minor (vote)
Target Milestone: 3.7 M5   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 343645 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-08-10 08:57 EDT by Jan Bernitt CLA
Modified: 2020-01-10 12:26 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Bernitt CLA 2010-08-10 08:57:09 EDT
Build Identifier: 20090920-1017

I think a short Example shows good what went wrong:

Before:
class Example {
  String aString;
}

After generate Getter/Setter:

class Example {
  String aString;

  public String getaString() {
    return aString;
  }

  public void setaString(String aString) {
    this.aString = aString;
  }
}

This is not correct: Correct Names would be "getAString" und  "setAString". At least this is what most reflection frameworks would try for property "aString".

Reproducible: Always

Steps to Reproduce:
1. See example above
Comment 1 Ayushman Jain CLA 2010-08-10 10:14:30 EDT
Moving to JDT/UI.
Comment 2 Srikanth Sankaran CLA 2010-08-10 11:05:23 EDT
(In reply to comment #1)
> Moving to JDT/UI.

We have a finger in the pie too:

org.eclipse.jdt.core.NamingConventions.suggestGetterName(IJavaProject, char[], int, boolean, char[][])
Comment 3 Jan Bernitt CLA 2010-08-10 11:38:14 EDT
(In reply to comment #2)
 
> org.eclipse.jdt.core.NamingConventions.suggestGetterName(IJavaProject, char[],
> int, boolean, char[][])
Yes. That's where it went wrong. Simply wrong suggestion. Same for Setter.
Comment 4 Markus Keller CLA 2010-08-11 07:05:19 EDT
Back to JDT/Core.
Comment 5 Jay Arthanareeswaran CLA 2011-01-19 09:24:45 EST
This is contradicting with bug #154823. There appear to be conventions that require the getter/setter name to be either ways. For instance, frameworks such as Struts (and perhaps Spring too) require the first lower case character, if followed by an upper case char, to be kept as is. On the other hand, reflection seem to work the other way.
Comment 6 Jan Bernitt CLA 2011-01-19 10:24:28 EST
(In reply to comment #5)
> ...There appear to be conventions that
> require the getter/setter name to be either ways. For instance, frameworks such
> as Struts (and perhaps Spring too) require the first lower case character...
I don't think any framework expectation should drive the naming conventions. 

Apart from that a lower case after get/set is simply horrible to read. A bit C#isch. Also a lower case after get/set would mean there is no general rule. It would be a special case. No thanks. That are good reasons against the lower case. 

If you decide to do the lower case solution the code generation (getter/setter) and everything connected to it has to be adapted accordingly. 

Anyway... now it took month and there is still no solution in sight. What... I mean what the heck is going on there ? Its no rocket science!
Comment 7 Markus Keller CLA 2011-01-19 10:39:37 EST
As discussed in https://jira.springframework.org/browse/IDE-337 , the
contradiction is already in the java.beans classes:
java.beans.Introspector#decapitalize(String) and
java.beans.NameGenerator#capitalize(String) (which is used in
PropertyDescriptor) are not bijective. 

See also http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4727079 and
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6590463 .

I think we should keep adhering to the JavaBeans spec (8.8 Capitalization of inferred names), which mentions Introspector#decapitalize(String).
Comment 8 Jay Arthanareeswaran CLA 2011-01-20 04:53:25 EST
I don't think eclipse can do anything here. Closing the bug.
Comment 9 Jan Bernitt CLA 2011-01-20 05:19:31 EST
For me this is against the java naming conventions:

http://www.oracle.com/technetwork/java/codeconventions-135099.html#367

"Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized."

Any character after the get is the first of a internal word. I don't think that any specification out there should break this basic naming convention.

I like to read things as they are:

  boolean iAtHome;

  void setiAtHome(boolean) { ... } // really - wow - When did I become a member ?
  // instead of
  void setIAtHome(boolean) { ... } // ah.. its about me... :)

Looks sick to me.
Comment 10 Jay Arthanareeswaran CLA 2011-01-20 05:29:08 EST
(In reply to comment #9)
> For me this is against the java naming conventions:

I understand your concern. However, naming conventions are not rules by themselves. When we are talking of a specification, we have to give more importance to that, for many users will be left with broken code.
Comment 11 Ayushman Jain CLA 2011-01-25 06:47:28 EST
Verified for 3.7M5
Comment 12 Markus Keller CLA 2011-04-22 13:39:52 EDT
*** Bug 343645 has been marked as a duplicate of this bug. ***
Comment 13 Jörg Hohwiller CLA 2020-01-10 12:26:12 EST
For the record:
https://github.com/devonfw/cobigen/issues/1095