Bug 210308

Summary: [quick fix] "Change method..add params" inserts params in wrong order if type is same
Product: [Eclipse Project] JDT Reporter: Luke Hutchison <luke.hutch>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert, martinae
Version: 3.4Keywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

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.