Bug 27907 Autocreate of a local variable outside of current block
If you type something like the following void myMethod() { try { a=someCall(); } catch(Exception e) { } System.out.println(a); } the variable 'a' isn't declared and code assist proposes to create a declaration for the local variable 'a'. But it is created inside the current block and not in the context of the method: void myMethod() { try { int a=someCall(); } catch(Exception e) { } System.out.println(a); // we've still got a problem here... } Code assist should detect wether the variable is used only inside the current block and create the delcaration only block local if the variable isn't used outside of the block.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/NewVariableCompletionProposal.java
}
		Type type= ASTResolving.guessTypeForReference(ast, fOriginalNode);
		if (type != null) {
			return type;
		}
		if (fVariableKind == CONST_FIELD) {
			return ast.newSimpleType(ast.newSimpleName("String")); 
		}
		return ast.newSimpleType(ast.newSimpleName("Object")); 
	}
	
	private boolean isVariableAssigned() {
		ASTNode parent= fOriginalNode.getParent();
		return (parent instanceof Assignment) && (fOriginalNode == ((Assignment) parent).getLeftHandSide());
	}
	
	
	private int evaluateFieldModifiers(ASTNode newTypeDecl) {
		if (fSenderBinding.isInterface()) {
			
			FieldDeclaration[] fieldDecls= ((TypeDeclaration) newTypeDecl).getFields();
			if (fieldDecls.length > 0) {
				return fieldDecls[0].getModifiers();
			}
			return 0;
		}
		int modifiers= 0;
		if (fVariableKind == CONST_FIELD) {
			modifiers |= Modifier.FINAL | Modifier.STATIC;
		} else {