Bug 25092 - Detect/Warn on possible user typos
Summary: Detect/Warn on possible user typos
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 2.1 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 18320 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-10-19 03:47 EDT by Genady Beryozkin CLA
Modified: 2002-11-13 09:48 EST (History)
1 user (show)

See Also:


Attachments
First proposed patch (4.43 KB, patch)
2002-11-08 11:44 EST, Genady Beryozkin CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Genady Beryozkin CLA 2002-10-19 03:47:38 EDT
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
Comment 1 Philipe Mulet CLA 2002-10-19 07:09:44 EDT
This sounds similar to the request to notice no-op assignments, 

arg = arg

this.field = field
Comment 2 Philipe Mulet CLA 2002-10-19 07:13:51 EDT
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 ?
Comment 3 Genady Beryozkin CLA 2002-10-19 07:54:03 EDT
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 ?
Comment 4 Philipe Mulet CLA 2002-10-21 09:51:47 EDT
pkg: org.eclipse.jdt.internal.compiler.ast
type: Assignment
method: resolveType
Comment 5 Genady Beryozkin CLA 2002-10-25 16:13:43 EDT
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 :)
Comment 6 Philipe Mulet CLA 2002-10-29 08:26:51 EST
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... 
Comment 7 Philipe Mulet CLA 2002-10-29 08:28:05 EST
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.
Comment 8 Genady Beryozkin CLA 2002-10-30 01:18:54 EST
I will try to complete it in the next two weeks
Comment 9 Genady Beryozkin CLA 2002-11-08 11:44:36 EST
Created attachment 2348 [details]
First proposed patch
Comment 10 Philipe Mulet CLA 2002-11-08 13:17:18 EST
Congrats, your first patch looks good. Will integrate it for M4.
We should provide an option (all our warnings have an associated option).
Comment 11 Philipe Mulet CLA 2002-11-08 13:21:55 EST
Also, we cannot print AST nodes in error messages, this could be problematic. 
We have to isolate names.
Comment 12 Genady Beryozkin CLA 2002-11-08 14:34:30 EST
I'm sorry, what did you mean by the last comment ?
Comment 13 Philipe Mulet CLA 2002-11-09 11:00:26 EST
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).
Comment 14 Philipe Mulet CLA 2002-11-11 08:39:01 EST
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
Comment 15 Philipe Mulet CLA 2002-11-11 17:09:08 EST
I have integrated your changes, with a few modifications as mentionned in 
previous comments, and added an option for it.

Fixed, thanks much.
Comment 16 Philipe Mulet CLA 2002-11-12 10:32:58 EST
*** Bug 18320 has been marked as a duplicate of this bug. ***
Comment 17 David Audel CLA 2002-11-13 09:48:03 EST
Verified.