Bug 121076 - Wrong field gets renamed
Summary: Wrong field gets renamed
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M5   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-15 11:41 EST by Gleb Sturov CLA
Modified: 2006-02-14 05:16 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gleb Sturov CLA 2005-12-15 11:41:09 EST
public class X {
 int int1, int2, int3;
}

Call ISourceManipulation#rename for field int2.
Field int1 will get renamed instead of int2.
This is broken in both 3.1.1 and 3.2
The following test case (org.eclipse.jdt.core.tests.model.RenameTests) would not  pass:

public void testBugWrongFieldGetsRenamed() throws Exception {
	this.createJavaProject("P1", new String[] {"src"}, "bin");
	this.createFile(
		"/P1/src/X.java",
		"public class X {\n" +
		"  int int1, int2, int3;\n" +
		"}"
	);
	ICompilationUnit c = getCompilationUnit("/P1/src/X.java");
	IType type = c.getType("X");
	IField field = type.getField("int2");
	renamePositive(field, "int2_renamed", false);
	
	field = type.getField("int1");
	assertTrue("int1 should exist", field != null && field.exists());
	field = type.getField("int2_renamed");
	assertTrue("int2_renamed should exist", field != null && field.exists());
	field = type.getField("int3");
	assertTrue("int3 should exist", field != null && field.exists());
}
Comment 1 Jerome Lanneluc CLA 2006-01-05 06:23:13 EST
Thanks for the test case. It helped a lot.

Changed CreateFieldOperation#rename(ASTNode, SimpleName) to find the right fragment first.
Added regression test RenameTests#testRenameFieldFragment().
Comment 2 Frederic Fusier CLA 2006-02-14 05:16:26 EST
Verified with for 3.2 M5 using build I20060214-0010.