Bug 78688 [1.5] [Generics] Erroneous quick fix results generated for this code. [quick fix]
I had this code which needs fixing where marked. % cat Test.java import java.util.LinkedHashMap; public class Test<K, V> { public void check() { final LinkedHashMap<K, V> data = new LinkedHashMap<K, V>(); final Integer x = data.entrySet(); // this line needs fixing. } } <<<< So I did Ctrl-1 to get the quickfix and selected "Change type of 'x' to 'Set<Map.Entry<K,V>>'" - this gives a drop down of choices .. Set<Map.Entry<K,V>> Collection<Map.Entry<K,V>> Iterable<Map.Entry<K,V>> So I choose Iterable<Map.Entry<K,V>> but notice the code is inserted incorrectly -- I get final Iterable<Entry<K,V x = data.entrySet(); // this line needs fixing. ^^^^^ missing terminating >>
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/TypeChangeCompletionProposal.java
String typeString= getImportRewrite().addImport(fNewType);
			Type type= ASTNodeFactory.newType(ast, typeString);
			
			if (declNode instanceof MethodDeclaration) {
				MethodDeclaration methodDecl= (MethodDeclaration) declNode;
				rewrite.set(methodDecl, MethodDeclaration.RETURN_TYPE2_PROPERTY, type, null);
				rewrite.set(methodDecl, MethodDeclaration.EXTRA_DIMENSIONS_PROPERTY, new Integer(0), null);
			} else if (declNode instanceof VariableDeclarationFragment) {
				ASTNode parent= declNode.getParent();
				if (parent instanceof FieldDeclaration) {
					FieldDeclaration fieldDecl= (FieldDeclaration) parent;
					if (fieldDecl.fragments().size() > 1 && (fieldDecl.getParent() instanceof TypeDeclaration)) { 
						VariableDeclarationFragment placeholder= (VariableDeclarationFragment) rewrite.createMoveTarget(declNode);
						FieldDeclaration newField= ast.newFieldDeclaration(placeholder);
						newField.setType(type);
						rewrite.getListRewrite(fieldDecl.getParent(), TypeDeclaration.BODY_DECLARATIONS_PROPERTY).insertAfter(newField, parent, null);
					} else {
						rewrite.set(fieldDecl, FieldDeclaration.TYPE_PROPERTY, type, null);
						rewrite.set(declNode, VariableDeclarationFragment.EXTRA_DIMENSIONS_PROPERTY, new Integer(0), null);
					}
				} else if (parent instanceof VariableDeclarationStatement) {
					VariableDeclarationStatement varDecl= (VariableDeclarationStatement) parent;
					if (varDecl.fragments().size() > 1 && (varDecl.getParent() instanceof Block)) { 
						VariableDeclarationFragment placeholder= (VariableDeclarationFragment) rewrite.createMoveTarget(declNode);
						VariableDeclarationStatement newStat= ast.newVariableDeclarationStatement(placeholder);
						newStat.setType(type);
						rewrite.getListRewrite(varDecl.getParent(), Block.STATEMENTS_PROPERTY).insertAfter(newStat, parent, null);
					} else {
						rewrite.set(varDecl, VariableDeclarationStatement.TYPE_PROPERTY, type, null);
						rewrite.set(declNode, VariableDeclarationFragment.EXTRA_DIMENSIONS_PROPERTY, new Integer(0), null);