org.eclipse.ltk.core.refactoring.PerformChangeOperation Java Examples
The following examples show how to use
org.eclipse.ltk.core.refactoring.PerformChangeOperation.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RenameRefactoringExecuter.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void run(IProgressMonitor pm) throws CoreException { try { pm.beginTask("", 11); pm.subTask(""); final RefactoringStatus status = refactoring.checkAllConditions(SubMonitor.convert(pm, 4)); if (status.getSeverity() >= RefactoringStatus.WARNING) { final boolean[] canceled = { false }; shell.getDisplay().syncExec(new Runnable() { @Override public void run() { canceled[0] = showStatusDialog(status); } }); if (canceled[0]) { throw new OperationCanceledException(); } } Change change = refactoring.createChange(SubMonitor.convert(pm, 2)); change.initializeValidationData(SubMonitor.convert(pm, 1)); performChangeOperation = new PerformChangeOperation(change); performChangeOperation.setUndoManager(RefactoringCore.getUndoManager(), refactoring.getName()); performChangeOperation.setSchedulingRule(ResourcesPlugin.getWorkspace().getRoot()); } finally { pm.done(); } }
Example #2
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Fix(IssueCodes.WRONG_FILE) public void fixWrongFileRenameClass(final Issue issue, final IssueResolutionAcceptor acceptor) { URI uri = issue.getUriToProblem(); String className = uri.trimFileExtension().lastSegment(); String label = String.format("Rename class to '%s'", className); acceptor.accept(issue, label, label, null, (element, context) -> { context.getXtextDocument().modify(resource -> { IRenameElementContext renameContext = renameContextFactory.createRenameElementContext(element, null, new TextSelection(context.getXtextDocument(), issue.getOffset(), issue.getLength()), resource); final ProcessorBasedRefactoring refactoring = renameRefactoringProvider.getRenameRefactoring(renameContext); ((RenameElementProcessor) refactoring.getProcessor()).setNewName(className); PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, true, monitor -> { try { if (!refactoring.checkFinalConditions(monitor).isOK()) return; Change change = refactoring.createChange(monitor); change.initializeValidationData(monitor); PerformChangeOperation performChangeOperation = new PerformChangeOperation(change); performChangeOperation.setUndoManager(RefactoringCore.getUndoManager(), refactoring.getName()); performChangeOperation.setSchedulingRule(ResourcesPlugin.getWorkspace().getRoot()); performChangeOperation.run(monitor); } catch (CoreException e) { logger.error(e); } }); return null; }); }); }
Example #3
Source File: RefactoringExecutionHelper.java From typescript.java with MIT License | 5 votes |
@Override public void run(IProgressMonitor pm) throws CoreException { try { pm.beginTask("", fForked && !fForkChangeExecution ? 7 : 11); //$NON-NLS-1$ pm.subTask(""); //$NON-NLS-1$ final RefactoringStatus status= fRefactoring.checkAllConditions(new SubProgressMonitor(pm, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); if (status.getSeverity() >= fStopSeverity) { final boolean[] canceled= { false }; if (fForked) { fParent.getDisplay().syncExec(new Runnable() { @Override public void run() { canceled[0]= showStatusDialog(status); } }); } else { canceled[0]= showStatusDialog(status); } if (canceled[0]) { throw new OperationCanceledException(); } } fChange= fRefactoring.createChange(new SubProgressMonitor(pm, 2, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); fChange.initializeValidationData(new SubProgressMonitor(pm, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); fPerformChangeOperation= new PerformChangeOperation(fChange);//RefactoringUI.createUIAwareChangeOperation(fChange); fPerformChangeOperation.setUndoManager(RefactoringCore.getUndoManager(), fRefactoring.getName()); if (fRefactoring instanceof IScheduledRefactoring) fPerformChangeOperation.setSchedulingRule(((IScheduledRefactoring)fRefactoring).getSchedulingRule()); if (!fForked || fForkChangeExecution) fPerformChangeOperation.run(new SubProgressMonitor(pm, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); } finally { pm.done(); } }
Example #4
Source File: ChangeUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Performs the given change. * * @return The undo change as produced by the refactoring's change. */ public static Change performChange(IWorkspace workspace, IProgressMonitor pm, Change change) throws CoreException { PerformChangeOperation performChangeOperation = new PerformChangeOperation( change); try { workspace.run(performChangeOperation, pm); } finally { if (!performChangeOperation.changeExecuted()) { change.dispose(); } } return performChangeOperation.getUndoChange(); }
Example #5
Source File: RefactoringExecutionHelper.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void run(IProgressMonitor pm) throws CoreException { try { pm.beginTask("", fForked && !fForkChangeExecution ? 7 : 11); //$NON-NLS-1$ pm.subTask(""); //$NON-NLS-1$ final RefactoringStatus status= fRefactoring.checkAllConditions(new SubProgressMonitor(pm, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); if (status.getSeverity() >= fStopSeverity) { final boolean[] canceled= { false }; if (fForked) { fParent.getDisplay().syncExec(new Runnable() { public void run() { canceled[0]= showStatusDialog(status); } }); } else { canceled[0]= showStatusDialog(status); } if (canceled[0]) { throw new OperationCanceledException(); } } fChange= fRefactoring.createChange(new SubProgressMonitor(pm, 2, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); fChange.initializeValidationData(new SubProgressMonitor(pm, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); fPerformChangeOperation= new PerformChangeOperation(fChange);//RefactoringUI.createUIAwareChangeOperation(fChange); fPerformChangeOperation.setUndoManager(RefactoringCore.getUndoManager(), fRefactoring.getName()); if (fRefactoring instanceof IScheduledRefactoring) fPerformChangeOperation.setSchedulingRule(((IScheduledRefactoring)fRefactoring).getSchedulingRule()); if (!fForked || fForkChangeExecution) fPerformChangeOperation.run(new SubProgressMonitor(pm, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); } finally { pm.done(); } }
Example #6
Source File: RenameRefactoringExecuter.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
public PerformChangeOperation getPerformChangeOperation() { return performChangeOperation; }
Example #7
Source File: TypeScriptDocumentProvider.java From typescript.java with MIT License | 4 votes |
private void performSaveActions(IFile file, IDocument document, IProgressMonitor monitor, IPreferenceStore preferenceStore) { boolean runFormat = preferenceStore.getBoolean(TypeScriptUIPreferenceConstants.EDITOR_SAVE_ACTIONS_FORMAT); SubMonitor progress = SubMonitor.convert(monitor, (runFormat ? 10 : 0)); if (!runFormat) { return; } IUndoManager manager = RefactoringCore.getUndoManager(); CompositeChange saveActionsChange = new CompositeChange("Save Actions"); List<Change> undoChanges = new ArrayList<>(); boolean success = false; try { manager.aboutToPerformChange(saveActionsChange); // Format the file contents if (runFormat) { TextFileChange change = new TextFileChange("Format", file); try { IIDETypeScriptProject tsProject = TypeScriptResourceUtil.getTypeScriptProject(file.getProject()); final IIDETypeScriptFile tsFile = tsProject.openFile(file, document); List<CodeEdit> codeEdits = tsFile.format(0, document.getLength()).get(); change.setEdit(DocumentUtils.toTextEdit(codeEdits, document)); change.initializeValidationData(new NullProgressMonitor()); PerformChangeOperation performChangeOperation = new PerformChangeOperation(change); ResourcesPlugin.getWorkspace().run(performChangeOperation, progress.newChild(10)); Change undoChange = performChangeOperation.getUndoChange(); if (undoChange != null) { undoChanges.add(undoChange); } } catch (Exception e) { JSDTTypeScriptUIPlugin.log(e); } } success = true; } finally { manager.changePerformed(saveActionsChange, success); } // Add an undo change if possible if (!undoChanges.isEmpty()) { manager.addUndo(saveActionsChange.getName(), new CompositeChange(saveActionsChange.getName(), undoChanges.toArray(new Change[undoChanges.size()]))); } }