Bug 27762 Enhancment of "Add return statement" quickfix
It would be nice if "Add return statement" would insert/suggest the best matched variable that should be returned. e.g. public Dimension getPreferredSize() { Dimension dim = inlined.getPreferredSize(); Dimension myDim = new Dimension(); myDim.setSize(inlined.getWidth()*1.5, inlined.getHeight()*1.5); } Here the last line the Quick Fix "Add return statement" is possible - but it inserts "return null;" at the end. It could just as well insert "return myDim;" Maybe has it as an second quick fix, so the quick fix options would be: Add return null statement Add return myDim statement
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ReturnTypeSubProcessor.java
ITypeBinding binding= ASTResolving.normalizeTypeBinding(expr.resolveTypeBinding());
				if (binding == null) {
					binding= selectedNode.getAST().resolveWellKnownType("java.lang.Object"); 
				}
				MethodDeclaration methodDeclaration= (MethodDeclaration) decl;   
				
				ASTRewrite rewrite= new ASTRewrite(methodDeclaration);
					
				String label= CorrectionMessages.getFormattedString("ReturnTypeSubProcessor.voidmethodreturns.description", binding.getName()); 	
				Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
				ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, 2, image);
				String returnTypeName= proposal.addImport(binding);
				Type newReturnType= ASTNodeFactory.newType(astRoot.getAST(), returnTypeName);
				
				if (methodDeclaration.isConstructor()) {
					MethodDeclaration modifiedNode= astRoot.getAST().newMethodDeclaration();
					modifiedNode.setModifiers(methodDeclaration.getModifiers()); 
					modifiedNode.setExtraDimensions(methodDeclaration.getExtraDimensions()); 
					modifiedNode.setConstructor(false);
					rewrite.markAsModified(methodDeclaration, modifiedNode);
					methodDeclaration.setReturnType(newReturnType);
					rewrite.markAsInserted(newReturnType);
				} else {
					rewrite.markAsReplaced(methodDeclaration.getReturnType(), newReturnType);
				}			
				proposal.ensureNoModifications();
				proposals.add(proposal);
			}
			ASTRewrite rewrite= new ASTRewrite(decl);
			rewrite.markAsRemoved(returnStatement);