IJavaElement elem= cu.getElementAt(context.getOffset()); if (elem instanceof IImportDeclaration) { String label= CorrectionMessages.getString("ReorgCorrectionsSubProcessor.unusedimport.description"); Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_DELETE_IMPORT); CUCorrectionProposal proposal= new CUCorrectionProposal(label, cu, 1, image); ImportEdit importEdit= new ImportEdit(cu, JavaPreferencesSettings.getCodeGenerationSettings()); importEdit.removeImport(elem.getElementName()); proposal.getRootTextEdit().add(importEdit); proposals.add(proposal);
ASTNode selectedNode= context.getCoveringNode(); if (selectedNode != null) { ASTNode node= ASTNodes.getParent(selectedNode, ASTNode.IMPORT_DECLARATION); if (node instanceof ImportDeclaration) { ASTRewrite rewrite= new ASTRewrite(node.getParent());  rewrite.markAsRemoved(node);  String label= CorrectionMessages.getString("ReorgCorrectionsSubProcessor.unusedimport.description"); Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_DELETE_IMPORT);  ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, 1, image); proposal.ensureNoModifications(); proposals.add(proposal); }
	public static void removeImportStatementProposals(ICorrectionContext context, List proposals) throws CoreException {		final ICompilationUnit cu= context.getCompilationUnit();		IJavaElement elem= cu.getElementAt(context.getOffset());		if (elem instanceof IImportDeclaration) {			String label= CorrectionMessages.getString("ReorgCorrectionsSubProcessor.unusedimport.description"); //$NON-NLS-1$			Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_DELETE_IMPORT);			CUCorrectionProposal proposal= new CUCorrectionProposal(label, cu, 1, image);			ImportEdit importEdit= new ImportEdit(cu, JavaPreferencesSettings.getCodeGenerationSettings());			importEdit.removeImport(elem.getElementName());			proposal.getRootTextEdit().add(importEdit);			proposals.add(proposal);		}				String name= CorrectionMessages.getString("ReorgCorrectionsSubProcessor.organizeimports.description"); //$NON-NLS-1$		ChangeCorrectionProposal proposal= new ChangeCorrectionProposal(name, null, 0) {			public void apply(IDocument document) {				IEditorInput input= new FileEditorInput((IFile) JavaModelUtil.toOriginal(cu).getResource());				IWorkbenchPage p= JavaPlugin.getActivePage();				if (p == null) {					return;				}				IEditorPart part= p.findEditor(input);				if (part instanceof JavaEditor) {					OrganizeImportsAction action= new OrganizeImportsAction((JavaEditor) part);					action.run(cu);										}								}		};		proposals.add(proposal);	}