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
ASTNode selectedNode= context.getCoveringNode();
		if (selectedNode instanceof MethodDeclaration) {
			MethodDeclaration declaration= (MethodDeclaration) selectedNode;
			
			ASTRewrite rewrite= new ASTRewrite(declaration);
			rewrite.markAsRemoved(declaration.getReturnType());
			
			String label= CorrectionMessages.getString("ReturnTypeSubProcessor.constrnamemethod.description"); 
			Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
			ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, 1, image);
			proposal.ensureNoModifications();
			proposals.add(proposal);
		}
	
	}
	
	public static void addVoidMethodReturnsProposals(ICorrectionContext context, List proposals) throws CoreException {
		ICompilationUnit cu= context.getCompilationUnit();
		
		CompilationUnit astRoot= context.getASTRoot();
		ASTNode selectedNode= context.getCoveringNode();
		if (selectedNode == null) {
			return;
		}
			
		BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);
		if (decl instanceof MethodDeclaration && selectedNode.getNodeType() == ASTNode.RETURN_STATEMENT) {
			ReturnStatement returnStatement= (ReturnStatement) selectedNode;
			Expression expr= returnStatement.getExpression();
			if (expr != null) {