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
import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.BodyDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.PrimitiveType;
import org.eclipse.jdt.core.dom.ReturnStatement;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
import org.eclipse.jdt.internal.corext.dom.ASTRewrite;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
/**
  */
public class ReturnTypeSubProcessor {
	
	private static class ReturnStatementCollector extends ASTVisitor {
		private ArrayList fResult= new ArrayList();
		
		public Iterator returnStatements() {
			return fResult.iterator();
		}
		public ITypeBinding getTypeBinding(AST ast) {
			boolean couldBeObject= false;
			for (int i= 0; i < fResult.size(); i++) {
				ReturnStatement node= (ReturnStatement) fResult.get(i);
				Expression expr= node.getExpression();
				if (expr != null) {
					ITypeBinding binding= ASTResolving.normalizeTypeBinding(expr.resolveTypeBinding());