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
Type type;
			String typeName;
			if (typeBinding != null) {
				typeName= proposal.addImport(typeBinding);
				type= ASTNodeFactory.newType(ast, typeName);
			} else {
				typeName= "void"; 		
				type= ast.newPrimitiveType(PrimitiveType.VOID);	
			}
			proposal.setDisplayName(CorrectionMessages.getFormattedString("ReturnTypeSubProcessor.missingreturntype.description", typeName)); 		
			rewrite.markAsInserted(type);
			methodDeclaration.setReturnType(type);
			
			MethodDeclaration modifiedNode= ast.newMethodDeclaration();
			modifiedNode.setModifiers(methodDeclaration.getModifiers()); 
			modifiedNode.setExtraDimensions(methodDeclaration.getExtraDimensions()); 
			modifiedNode.setConstructor(false);
			rewrite.markAsModified(methodDeclaration, modifiedNode);
			
			proposal.ensureNoModifications();
			proposals.add(proposal);
			
			
			ASTNode parentType= ASTResolving.findParentType(decl);
			if (parentType instanceof TypeDeclaration) {
				String constructorName= ((TypeDeclaration) parentType).getName().getIdentifier();
				ASTNode nameNode= methodDeclaration.getName();
				String label= CorrectionMessages.getFormattedString("ReturnTypeSubProcessor.wrongconstructorname.description", constructorName); 		
				proposals.add(new ReplaceCorrectionProposal(label, cu, nameNode.getStartPosition(), nameNode.getLength(), constructorName, 1));
			}