Community
Participate
Working Groups
I would like eclipse to detect possible typos in constructors/setter where the syntax is: public MyClass(int myInt) { this.myInt = myInt; } Suppose the user makes a typo and we have public MyClass(int myint) { this.myInt = myInt; } (notice the lowercase argument "myint"). While we can detect such problems by turning on "unused variables/arguments" warning, it is problematic since in many methods not all arguments are used and the warning message will be lost among other warnings. I suggest handling it another way: Eclipse can detect whether the same field is referenced both using the "this.fieldName" syntax and the "fieldName syntax". Most methods will not be affected by it, but methods that are affected usually require user's attention. If it is not a bug in user's code, it is defenetely misleading and in my opinion is a bad programming practice. I can contribute the code if somebody will point me to where to start. Genady
This sounds similar to the request to notice no-op assignments, arg = arg this.field = field
Similar request is bug 18320. Let's put it on the 2.1 plan. If you want to contribute a fix for it, you should look at the AST node: Assignment in its #resolveType method. A bonus check for detecting this scenario would be necessary (looking at the expression binding if it is a NameReference or a field reference with This as a receiver). Once you have some basic check working, we can talk about having an optional setting for controlling its enabling. Do you have any idea about when you could start working on this ?
This feature request should indeed solve the problem of no-op assignement, but is a little more general. What I mean by "where do I start" is - where do you perform such checks ? in what package ?
pkg: org.eclipse.jdt.internal.compiler.ast type: Assignment method: resolveType
I think I can write the code until M4 release. Although the documentation is missing I think it is possible even for non-OTI employee :)
Excellent. We indeed did not put too much comment on internal code. Mostly annotations for us later. Please interact with us to get it in time for M4, i.e. we will need to challenge it, have some tests, etc...
Also one thing to keep in mind is that the overhead should be almost zero, we don't want to slow down the compiler for checking some optional warning.
I will try to complete it in the next two weeks
Created attachment 2348 [details] First proposed patch
Congrats, your first patch looks good. Will integrate it for M4. We should provide an option (all our warnings have an associated option).
Also, we cannot print AST nodes in error messages, this could be problematic. We have to isolate names.
I'm sorry, what did you mean by the last comment ?
In the code reporting an error, it seems your are using #toString on AST nodes, this isn't an official protocol to use for outputting information to users (only for internal debug purpose).
Actually more issues, #getBinding will return the first binding for a qualified name reference: e.g. this.y = y.z would think it is a noop
I have integrated your changes, with a few modifications as mentionned in previous comments, and added an option for it. Fixed, thanks much.
*** Bug 18320 has been marked as a duplicate of this bug. ***
Verified.