{ ASTRewrite rewrite= new ASTRewrite(nodeToCast.getParent());  String label; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal("", cu, rewrite, 1, image); String simpleCastType= proposal.addImport(castType);  if (nodeToCast.getNodeType() == ASTNode.CAST_EXPRESSION) { label= CorrectionMessages.getFormattedString("LocalCorrectionsSubProcessor.changecast.description", castType); CastExpression expression= (CastExpression) nodeToCast; rewrite.markAsReplaced(expression.getType(), rewrite.createPlaceholder(simpleCastType, ASTRewrite.TYPE)); } else { label= CorrectionMessages.getFormattedString("LocalCorrectionsSubProcessor.addcast.description", castType);  Expression expressionCopy= (Expression) rewrite.createCopy(nodeToCast); Type typeCopy= (Type) rewrite.createPlaceholder(simpleCastType, ASTRewrite.TYPE); CastExpression castExpression= astRoot.getAST().newCastExpression(); castExpression.setExpression(expressionCopy); castExpression.setType(typeCopy);  rewrite.markAsReplaced(nodeToCast, castExpression); } proposal.setDisplayName(label); proposal.ensureNoModifications();  proposals.add(proposal);
ASTRewriteCorrectionProposal castProposal= getCastProposal(context, castType, nodeToCast); if (castProposal != null) { proposals.add(castProposal);
	public static void addCastProposals(ICorrectionContext context, List proposals) throws CoreException {		String[] args= context.getProblemArguments();		if (args.length != 2) {			return;		}					ICompilationUnit cu= context.getCompilationUnit();		String castType= args[1];		CompilationUnit astRoot= context.getASTRoot();		ASTNode selectedNode= context.getCoveredNode();		if (!(selectedNode instanceof Expression)) {			return;		}		Expression nodeToCast= (Expression) selectedNode;				int parentNodeType= selectedNode.getParent().getNodeType();		if (parentNodeType == ASTNode.ASSIGNMENT) {			Assignment assign= (Assignment) selectedNode.getParent();			if (selectedNode.equals(assign.getLeftHandSide())) {				nodeToCast= assign.getRightHandSide();			}		} else if (parentNodeType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {			VariableDeclarationFragment frag= (VariableDeclarationFragment) selectedNode.getParent();			if (selectedNode.equals(frag.getName())) {				nodeToCast= frag.getInitializer();			}		}		{			ASTRewrite rewrite= new ASTRewrite(nodeToCast.getParent());						String label;			Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);			ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal("", cu, rewrite, 1, image); //$NON-NLS-1$			String simpleCastType= proposal.addImport(castType);						if (nodeToCast.getNodeType() == ASTNode.CAST_EXPRESSION) {				label= CorrectionMessages.getFormattedString("LocalCorrectionsSubProcessor.changecast.description", castType); //$NON-NLS-1$				CastExpression expression= (CastExpression) nodeToCast;				rewrite.markAsReplaced(expression.getType(), rewrite.createPlaceholder(simpleCastType, ASTRewrite.TYPE));			} else {				label= CorrectionMessages.getFormattedString("LocalCorrectionsSubProcessor.addcast.description", castType); //$NON-NLS-1$								Expression expressionCopy= (Expression) rewrite.createCopy(nodeToCast);				Type typeCopy= (Type) rewrite.createPlaceholder(simpleCastType, ASTRewrite.TYPE);				CastExpression castExpression= astRoot.getAST().newCastExpression();				castExpression.setExpression(expressionCopy);				castExpression.setType(typeCopy);								rewrite.markAsReplaced(nodeToCast, castExpression);			}			proposal.setDisplayName(label);			proposal.ensureNoModifications();						proposals.add(proposal);		}				// change method return statement to actual type		if (parentNodeType == ASTNode.RETURN_STATEMENT) {			ITypeBinding binding= nodeToCast.resolveTypeBinding();						BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);			if (binding != null && decl instanceof MethodDeclaration) {				MethodDeclaration methodDeclaration= (MethodDeclaration) decl;					ASTRewrite rewrite= new ASTRewrite(methodDeclaration);				Type newReturnType= ASTResolving.getTypeFromTypeBinding(astRoot.getAST(), binding);				rewrite.markAsReplaced(methodDeclaration.getReturnType(), newReturnType);					String label= CorrectionMessages.getFormattedString("LocalCorrectionsSubProcessor.changereturntype.description", binding.getName()); //$NON-NLS-1$				Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);				ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, 2, image);				proposal.addImport(binding);				proposal.ensureNoModifications();				proposals.add(proposal);			}		}		if (parentNodeType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {			VariableDeclarationFragment fragment= (VariableDeclarationFragment) selectedNode.getParent();			ASTNode parent= fragment.getParent();			Type type= null;			if (parent instanceof VariableDeclarationStatement) {				VariableDeclarationStatement stmt= (VariableDeclarationStatement) parent;				if (stmt.fragments().size() == 1) {					type= stmt.getType();				}			} else if (parent instanceof FieldDeclaration) {				FieldDeclaration decl= (FieldDeclaration) parent;				if (decl.fragments().size() == 1) {					type= decl.getType();				}			}						if (type != null) {				ImportEdit edit= new ImportEdit(cu, JavaPreferencesSettings.getCodeGenerationSettings());				String typeName= edit.addImport(args[0]);				String label= CorrectionMessages.getFormattedString("LocalCorrectionsSubProcessor.addcast_var.description", typeName); //$NON-NLS-1$				ReplaceCorrectionProposal varProposal= new ReplaceCorrectionProposal(label, cu, type.getStartPosition(), type.getLength(), typeName, 1);				varProposal.getRootTextEdit().add(edit);					proposals.add(varProposal);			}		}				}