Bug 82940 [quick fix] Missing sensible conversion suggestion
For this code > % cat Test.java import java.util.Collections; import java.util.List; public class Test { interface Wrapper { int doit(); } private static final List<Wrapper> STD_WRAPPERS = Collections.singletonList ((Wrapper)new Wrapper() { public int doit() { return 0; } }); private static final List<Wrapper> STD_WRAPPERS2 = Collections.singletonList (new Wrapper() { public int doit() { return 0; } }); } The value passed Collections.singletonList is actually of the right type so a sensible conversion would be to put in the cast (see the difference between the 2 statics). The current quick fixes offered assume the type being assigned to is wrong (when infact it is right). A useful quick fix would be to cast the parameter to the right type to give the left type (this would help with any 1 arg method of the form X<T> method(T)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/MissingReturnTypeCorrectionProposal.java
ITypeBinding returnBinding= getReturnTypeBinding();
		if (fExistingReturn != null) {
			ASTRewrite rewrite= ASTRewrite.create(ast);
			Expression expression= evaluateReturnExpressions(ast, returnBinding, fExistingReturn.getStartPosition());
			if (expression != null) {
				rewrite.set(fExistingReturn, ReturnStatement.EXPRESSION_PROPERTY, expression, null);
				addLinkedPosition(rewrite.track(expression), true, RETURN_EXPRESSION_KEY);
			}
			return rewrite;
		} else {
			ASTRewrite rewrite= ASTRewrite.create(ast);
			Block block= fMethodDecl.getBody();
			List statements= block.statements();
			int nStatements= statements.size();
			ASTNode lastStatement= null;
			if (nStatements > 0) {
				lastStatement= (ASTNode) statements.get(nStatements - 1);
			}
			if (returnBinding != null && lastStatement instanceof ExpressionStatement && lastStatement.getNodeType() != ASTNode.ASSIGNMENT) {
				Expression expression= ((ExpressionStatement) lastStatement).getExpression();
				ITypeBinding binding= expression.resolveTypeBinding();
				if (binding != null && TypeRules.canAssign(binding, returnBinding)) {
					Expression placeHolder= (Expression) rewrite.createMoveTarget(expression);
					ReturnStatement returnStatement= ast.newReturnStatement();
					returnStatement.setExpression(placeHolder);
					rewrite.replace(lastStatement, returnStatement, null);
					return rewrite;
				}
			}
			int offset;