Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 319318

Summary: Preferences->Java Compiler-> Errors/Warnings -> Name shadowing enhancement
Product: [Eclipse Project] JDT Reporter: Daniel Holmes <dholmes>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P4 CC: amj87.iitr, markus.kell.r, Olivier_Thomann
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Daniel Holmes CLA 2010-07-08 16:50:53 EDT
Build Identifier: 20100218-1602

The property for "Local variable declaration hides another field or variable" has an option that allows constructors and setter methods to be not included.  We are also now using a lot of fluent setters having the withXXX() signature as they are different than the bean setXXX() signature.  It would be good to have these also considered and ignored based on this option selection.

Reproducible: Always

Steps to Reproduce:
Just need a object with a fluent withXXX() version of a setter and a variable to the method named same as the class attribute.
Comment 1 Ayushman Jain CLA 2010-07-09 02:59:14 EDT
I think it'll be a better approach to just let the user customize what kind of prefixes he wants to be recognized for a method which is to be excluded from the "variable hiding" warning, since in the future someone might start using some other prefixes such as 'put'.
Olivier, what do you think?
Comment 2 Olivier Thomann CLA 2010-07-09 13:54:59 EDT
Yes, we could investigate making these prefixes configurable.
Comment 3 Ayushman Jain CLA 2010-07-12 03:13:39 EDT
I'll investigate
Comment 4 Markus Keller CLA 2010-11-05 12:00:00 EDT
Since the withXXX() convention is not (yet) widely used (is there even a spec for this anywhere?), we shouldn't hard-code this into the compiler.

The existing option is about constructors and setters, but if I understood the "fluent setters" correctly, they are not really setters but they return a different object than 'this'. So it would have to be a new option. But also for that, we're too early at this time.
Comment 5 Daniel Holmes CLA 2010-11-05 13:30:10 EDT
The convention we are using is that withXXX is simply a setter that returns "this", which allows the user of the POJO to to do method chaining within the construction.  There is no 'spec' for this, but it is a pretty common pattern that people are stating to apply (just google for java fluent setters)

A separate option that allowed the definition of method prefix(es) to ignore for the field hiding would be a fine solution.  As is, we cannot use this warning at all because of these fluent with setters are all flagged.  Such an option would allow for project conventions to be accounted for.
Comment 6 Markus Keller CLA 2010-11-08 06:33:01 EST
Sorry, we can't add support or a compiler option for every possible internal convention. The only thing I could agree on would be an implicit notion of "setter" that is not based on the JavaBeans naming convention but on the structure of the method. In addition to the current notion of "setter", the compiler would not generate a problem for the local variable fieldName in a method that matches this template:

any_modifiers ThisType any_method_name (FieldType fieldName) {
    this.fieldName = fieldName;
    return this;
}
Comment 7 Daniel Holmes CLA 2010-11-08 08:53:37 EST
I didn't know how this was done internally, but basing this on the concept of setter and method structure as you suggest would be perfect.  I didn't realize that would be doable in that manner.  Thanks for your time and input.