if (ASTNodes.isControlStatementBody(dominantStatement.getLocationInParent())) { dominantStatement= (Statement) dominantStatement.getParent(); }
	private ASTRewrite doAddLocal(CompilationUnit cu) throws CoreException {		AST ast= cu.getAST();				Block body;		BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(fOriginalNode);		if (decl instanceof MethodDeclaration) {			body= (((MethodDeclaration) decl).getBody());		} else if (decl instanceof Initializer) {			body= (((Initializer) decl).getBody());		} else {			return null;		}		ASTRewrite rewrite= ASTRewrite.create(ast);				SimpleName[] names= getAllReferences(body);		ASTNode dominant= getDominantNode(names);				Statement dominantStatement= ASTResolving.findParentStatement(dominant);		SimpleName node= names[0];				if (isAssigned(dominantStatement, node)) {			// x = 1; -> int x = 1;			Assignment assignment= (Assignment) node.getParent();						// trick to avoid comment removal around the statement: keep the expression statement			// and replace the assignment with an VariableDeclarationExpression			VariableDeclarationFragment newDeclFrag= ast.newVariableDeclarationFragment();			VariableDeclarationExpression newDecl= ast.newVariableDeclarationExpression(newDeclFrag);			newDecl.setType(evaluateVariableType(ast));						Expression placeholder= (Expression) rewrite.createCopyTarget(assignment.getRightHandSide());			newDeclFrag.setInitializer(placeholder);			newDeclFrag.setName(ast.newSimpleName(node.getIdentifier()));			rewrite.replace(assignment, newDecl, null);						addLinkedPosition(rewrite.track(newDecl.getType()), false, KEY_TYPE);			addLinkedPosition(rewrite.track(newDeclFrag.getName()), true, KEY_NAME);						setEndPosition(rewrite.track(assignment.getParent()));			return rewrite;		} else if ((dominant != dominantStatement) && isForStatementInit(dominantStatement, node)) {			//	for (x = 1;;) ->for (int x = 1;;)						Assignment assignment= (Assignment) node.getParent();						VariableDeclarationFragment frag= ast.newVariableDeclarationFragment();			VariableDeclarationExpression expression= ast.newVariableDeclarationExpression(frag);			frag.setName(ast.newSimpleName(node.getIdentifier()));			Expression placeholder= (Expression) rewrite.createCopyTarget(assignment.getRightHandSide());			frag.setInitializer(placeholder);			expression.setType(evaluateVariableType(ast));						rewrite.replace(assignment, expression, null);						addLinkedPosition(rewrite.track(expression.getType()), false, KEY_TYPE); 			addLinkedPosition(rewrite.track(frag.getName()), true, KEY_NAME); 						setEndPosition(rewrite.track(expression));						return rewrite;		}		//	foo(x) -> int x; foo(x)				VariableDeclarationFragment newDeclFrag= ast.newVariableDeclarationFragment();		VariableDeclarationStatement newDecl= ast.newVariableDeclarationStatement(newDeclFrag);		newDeclFrag.setName(ast.newSimpleName(node.getIdentifier()));		newDecl.setType(evaluateVariableType(ast));//		newDeclFrag.setInitializer(ASTNodeFactory.newDefaultExpression(ast, newDecl.getType(), 0));		addLinkedPosition(rewrite.track(newDecl.getType()), false, KEY_TYPE);		addLinkedPosition(rewrite.track(node), true, KEY_NAME); 		addLinkedPosition(rewrite.track(newDeclFrag.getName()), false, KEY_NAME);				Statement statement= dominantStatement;		List list= ASTNodes.getContainingList(statement);		while (list == null && statement.getParent() instanceof Statement) { // parent must be if, for or while			statement= (Statement) statement.getParent();			list= ASTNodes.getContainingList(statement);		}		if (list != null) {			ASTNode parent= statement.getParent();			StructuralPropertyDescriptor childProperty= statement.getLocationInParent();			if (childProperty.isChildListProperty()) {				rewrite.getListRewrite(parent, (ChildListPropertyDescriptor) childProperty).insertBefore(newDecl, statement, null);				return rewrite;			} else {				return null;			}		}		return rewrite;	}