public void resolve(MultiFixTarget[] targets, final IProgressMonitor monitor) throws CoreException { if (targets.length == 0) return; if (fCleanUp == null) return; String changeName; String[] descriptions = fCleanUp.getStepDescriptions(); if (descriptions.length == 1) { changeName = descriptions[0]; } else { changeName = CorrectionMessages.FixCorrectionProposal_MultiFixChange_label; } final CleanUpRefactoring refactoring = new CleanUpRefactoring(changeName); for (int i = 0; i < targets.length; i++) { refactoring.addCleanUpTarget(targets[i]); } refactoring.addCleanUp(fCleanUp); IRunnableContext context = new IRunnableContext() { public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { runnable.run(monitor == null ? new NullProgressMonitor() : monitor); } }; Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); RefactoringExecutionHelper helper = new RefactoringExecutionHelper( refactoring, IStatus.INFO, RefactoringSaveHelper.SAVE_REFACTORING, shell, context); try { helper.perform(true, true); } catch (InterruptedException e) { } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause instanceof CoreException) { throw (CoreException) cause; } else { throw new CoreException( new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, cause.getLocalizedMessage(), cause)); } } }
/* (non-Javadoc) * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, char, int, int) */ public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { if (stateMask == SWT.CONTROL && fCleanUp != null) { CleanUpRefactoring refactoring = new CleanUpRefactoring(); refactoring.addCompilationUnit(getCompilationUnit()); refactoring.addCleanUp(fCleanUp); refactoring.setLeaveFilesDirty(true); int stopSeverity = RefactoringCore.getConditionCheckingFailedSeverity(); Shell shell = JavaPlugin.getActiveWorkbenchShell(); IRunnableContext context = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); RefactoringExecutionHelper executer = new RefactoringExecutionHelper( refactoring, stopSeverity, RefactoringSaveHelper.SAVE_NOTHING, shell, context); try { executer.perform(true, true); } catch (InterruptedException e) { } catch (InvocationTargetException e) { JavaPlugin.log(e); } return; } apply(viewer.getDocument()); }