Bug 129165 [quick fix] 'Change modifier to final' changes order of variable decl fragments
I20060221-1300 Given: int i= 1, j= i + 1, h= j + 1; Serializable ser= new Serializable() { void foo() { System.out.println(j); } }; Then make j final with quick fix 'Change modifier of 'j' to final' Result: int i= 1, h= j + 1; final int j= i + 1; Serializable ser= new Serializable() { void foo() { System.out.println(j); } }; Expected: int i= 1; final int j= i + 1; int h= j + 1; Serializable ser= new Serializable() { void foo() { System.out.println(j); } }; The order of the declarations must be preserved.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ModifierChangeCompletionProposal.java
ASTNode declNode= null;
		TextEditGroup selectionDescription= null;
		if (boundNode != null) {
			declNode= boundNode; 
		} else {
			selectionDescription= new TextEditGroup("selection"); 
			
			CompilationUnit newRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
			declNode= newRoot.findDeclaringNode(fBinding.getKey());
		}
		if (declNode != null) {
			AST ast= declNode.getAST();
			ASTRewrite rewrite= ASTRewrite.create(ast);
			if (declNode.getNodeType() == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
				ASTNode parent= declNode.getParent();
				if (parent instanceof FieldDeclaration) {
					FieldDeclaration fieldDecl= (FieldDeclaration) parent;
					if (fieldDecl.fragments().size() > 1 && (fieldDecl.getParent() instanceof AbstractTypeDeclaration)) { 
						VariableDeclarationFragment placeholder= (VariableDeclarationFragment) rewrite.createMoveTarget(declNode);
						FieldDeclaration newField= ast.newFieldDeclaration(placeholder);
						newField.setType((Type) ASTNode.copySubtree(ast, fieldDecl.getType()));
						newField.modifiers().addAll(ast.newModifiers((fieldDecl.getModifiers() & ~fExcludedModifiers) | fIncludedModifiers));
						AbstractTypeDeclaration typeDecl= (AbstractTypeDeclaration) fieldDecl.getParent();
						ListRewrite listRewrite= rewrite.getListRewrite(typeDecl, typeDecl.getBodyDeclarationsProperty());
						if (fieldDecl.fragments().indexOf(declNode) == 0) { 
							listRewrite.insertBefore(newField, parent, null);
						} else {
							listRewrite.insertAfter(newField, parent, null);
						}
						declNode= newField;