Bug 69471 - [DOM/AST] Improve guessing of method binding for overloaded methods
Summary: [DOM/AST] Improve guessing of method binding for overloaded methods
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M3   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 90400 97268 107000 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-07-07 10:46 EDT by David Corbin CLA
Modified: 2005-11-17 10:38 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 David Corbin CLA 2004-07-07 10:46:06 EDT
if I have "assertEquals(1,foo.bar)" in a unittest, and Foo does not currently
have a field called "bar", I'm given a quick-fix choice to create such a field,
but it always uses "Object" as the type.  It should be able to tell better which
assertEquals signature to use because of the constant as the first argument.  At
the least, it should offer the "picklist" of int and long as choices, rather
than using Object.
Comment 1 Martin Aeschlimann CLA 2004-07-08 08:26:35 EDT
The problem comes from the overloaded methods 'assertEquals'.

jdt.core does the guessing of the method binding and it seems to select 
assertEquals(Object, Object). It could choose assertEquals(int, int), having a 
resolvable first argument: Then the quick fix would also create an 'int'

Moving to jdt.core 
Comment 2 Philipe Mulet CLA 2005-04-07 07:34:57 EDT
Deferring post 3.1
Comment 3 Martin Aeschlimann CLA 2005-05-24 05:18:57 EDT
bug 45155 is a dup of this
Comment 4 Martin Aeschlimann CLA 2005-05-24 05:19:23 EDT
*** Bug 90400 has been marked as a duplicate of this bug. ***
Comment 5 Martin Aeschlimann CLA 2005-05-31 06:11:35 EDT
*** Bug 97268 has been marked as a duplicate of this bug. ***
Comment 6 Martin Aeschlimann CLA 2005-08-15 11:13:22 EDT
Olivier, this bug would be good thing to have fixed. Shouldn't be that hard.
Comment 7 Martin Aeschlimann CLA 2005-08-15 11:13:39 EDT
*** Bug 107000 has been marked as a duplicate of this bug. ***
Comment 8 Olivier Thomann CLA 2005-08-15 13:02:28 EDT
What binding do you expect?
Comment 9 Michael Stevens CLA 2005-08-15 13:05:44 EDT
My example (following in from 10700):

I write:

assertFalse(wibble());

Quickfix gives me a method with a return type of String, because there's a method:

assertFalse(String, boolean)

This doesn't compile.

I want it to give me a return type of boolean, which would compile - there's a
method:

assertFalse(boolean)
Comment 10 Olivier Thomann CLA 2005-08-15 15:10:02 EDT
Do you expect to get methods that are not visible?

class Y {
	public static void assertFalse(String s, boolean b) {}
	private static void assertFalse(boolean b) {}
}
public class X {
	
	public static void main(String[] args) {
		Y.assertFalse(foo());
	}
}

would you expect private static void assertFalse(boolean b) {} to be returned?
Comment 11 Martin Aeschlimann CLA 2005-08-16 03:39:34 EDT
I guess I would first check for the same number of parameters, then visibility,
then number of matching parameter types.
Comment 12 Michael Stevens CLA 2005-08-16 06:09:10 EDT
That's a hard example - as a user I'd probably rather get:

public static void assertFalse(String s, boolean b) {}

matched - neither will compile, but changing a line of code in a method feels
like a smaller change than changing the public contract of a class - so it's
closer to compiling.
Comment 13 Kent Johnson CLA 2005-09-28 15:44:15 EDT
Changed the heuristic to detect the best 'non-matching' method and fixed a 
problem in MessageSend (when an argument expression could not be resolved, all 
known arg types were thrown away).

We're using the number of argument type and parameter type matches as well as 
the parameter count to decide.

Let us know if there are some cases that need a different algorithm.

Changed a few tests which picked up a poor method match and now get the best 
non-match.
Comment 14 Olivier Thomann CLA 2005-10-28 13:57:59 EDT
Verified for 3.2 M3 using build I20051025-0800+JDT/Core v_618a
Comment 15 Martin Aeschlimann CLA 2005-11-16 18:59:41 EST
This bug doesn not seem to be correctly fixed:

In the following example, 'assertFalse(x, y);' gets the binding of
'assertFalse(boolean b)'. See bug 116573.

public class C {
		public void assertFalse(String s, boolean b) {}
		public void assertFalse(boolean b) {}
		
		public static void main(String[] args) {
			C.assertFalse(x, y);
		}
}
Comment 16 Olivier Thomann CLA 2005-11-16 21:29:56 EST
I verified that the case in comment 9 works properly now.
Kent, we might want to see how we can support other cases.
Comment 17 Kent Johnson CLA 2005-11-17 10:38:34 EST
Martin, we have a new PR for that case.

We do not need to reopen this one.