Bug 210308 - [quick fix] "Change method..add params" inserts params in wrong order if type is same
Summary: [quick fix] "Change method..add params" inserts params in wrong order if type...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2007-11-19 17:26 EST by Luke Hutchison CLA
Modified: 2009-01-23 11:36 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luke Hutchison CLA 2007-11-19 17:26:33 EST
Build ID: M20070921-1145

Consider this code segment:

	String f(int x, int y, String z) {
		return g(z);
	}
	
	String g(String z) {
		return z;
	}

If I change the invocation of g to "g(x, y, z)" then I get an error.  Quick fix allows me to "Change method g(int): add params "int, int".  The result is:

	String f(int x, int y, String z) {
		return g(x, y, z);
	}
	
	String g(int x, int y, String z) {
		return z;
	}

This works as expected.  However now change the type of z to int:
	
	int f(int x, int y, int z) {
		return g(z);
	}
	
	int g(int z) {
		return z;
	}

Again change the invocation to "g(x, y, z)" and apply the quick fix.  You get:
	
	int f(int x, int y, int z) {
		return g(x, y, z);
	}
	
	int g(int z, int y, int z2) {
		return z;
	}

It seems like Quick Fix is doing a sequence alignment (probably using dynamic programming) -- but that it is only looking at types.  Within a type, the algorithm should also look at variable names, and if there are any exact matches between invocation and method declaration, this alignment should be preserved after inserting the new parameters.

The expected output is:
	
	int f(int x, int y, int z) {
		return g(x, y, z);
	}
	
	int g(int x, int y, int z) {
		return z;
	}



More information:
Comment 1 Martin Aeschlimann CLA 2007-11-20 08:07:42 EST
Yes, quick fix only looks at types and fills in matching variables. Could be improved, but not on the list of urgent fixes. Help is welcome.