/** * Hook to create an undo change for the given undo edit. This hook gets * called while performing the change to construct the corresponding undo * change object. * <p> * Subclasses may override it to create a different undo change. * </p> * * @param edits * the {@link UndoEdit undo edit} to create a undo change for * @param stampToRestore * the content stamp to restore when the undo edit is executed. * * @return the undo change * * @throws CoreException * if an undo change can't be created */ protected Change createUndoChange(UndoEdit[] edits, ContentStamp stampToRestore) throws CoreException { return new MultiStateUndoChange(getName(), fFile, edits, stampToRestore, fSaveMode); }
@Override public final Object[] getAffectedObjects() { Object modifiedElement= getModifiedElement(); if (modifiedElement == null) return null; return new Object[] { modifiedElement}; }
@Override public Change perform(IProgressMonitor pm) throws CoreException { if (fValidationState == null || fValidationState.isValid(needsSaving(), false).hasFatalError()) return new NullChange(); if (pm == null) if (needsSaving()) { buffer.commit(pm, false); if (!success) { return createUndoChange(list.toArray(new UndoEdit[list.size()]), currentStamp); } catch (BadLocationException e) { throw Changes.asCoreException(e);
@Override public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { if (pm == null) pm= new NullProgressMonitor(); pm.beginTask("", 1); //$NON-NLS-1$ try { if (fValidationState == null) throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), "MultiStateUndoChange has not been initialialized")); //$NON-NLS-1$ ITextFileBuffer buffer= FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE); fDirty= buffer != null && buffer.isDirty(); return fValidationState.isValid(needsSaving(), true); } finally { pm.done(); } }
@Override public final Change perform(final IProgressMonitor monitor) throws CoreException { monitor.beginTask("", 3); //$NON-NLS-1$ IDocument document= null; try { document= acquireDocument(new SubProgressMonitor(monitor, 1)); final LinkedList<UndoEdit> undoList= new LinkedList<>(); performChanges(document, undoList, false); if (needsSaving()) fBuffer.commit(new SubProgressMonitor(monitor, 1), false); return new MultiStateUndoChange(getName(), fFile, undoList.toArray(new UndoEdit[undoList.size()]), fContentStamp, fSaveMode); } catch (BadLocationException exception) { throw Changes.asCoreException(exception); } finally { if (document != null) { releaseDocument(document, new SubProgressMonitor(monitor, 1)); } monitor.done(); } }
@Override public Change perform(IProgressMonitor pm) throws CoreException { if (fValidationState == null || fValidationState.isValid(needsSaving(), false).hasFatalError()) return new NullChange(); if (pm == null) if (needsSaving()) { buffer.commit(pm, false); if (!success) { return createUndoChange(list.toArray(new UndoEdit[list.size()]), currentStamp); } catch (BadLocationException e) { throw Changes.asCoreException(e);
@Override public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { if (pm == null) pm= new NullProgressMonitor(); pm.beginTask("", 1); //$NON-NLS-1$ try { if (fValidationState == null) throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), "MultiStateUndoChange has not been initialialized")); //$NON-NLS-1$ ITextFileBuffer buffer= FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE); fDirty= buffer != null && buffer.isDirty(); return fValidationState.isValid(needsSaving(), true); } finally { pm.done(); } }
@Override public final Change perform(final IProgressMonitor monitor) throws CoreException { monitor.beginTask("", 3); //$NON-NLS-1$ IDocument document= null; try { document= acquireDocument(new SubProgressMonitor(monitor, 1)); final LinkedList<UndoEdit> undoList= new LinkedList<>(); performChanges(document, undoList, false); if (needsSaving()) fBuffer.commit(new SubProgressMonitor(monitor, 1), false); return new MultiStateUndoChange(getName(), fFile, undoList.toArray(new UndoEdit[undoList.size()]), fContentStamp, fSaveMode); } catch (BadLocationException exception) { throw Changes.asCoreException(exception); } finally { if (document != null) { releaseDocument(document, new SubProgressMonitor(monitor, 1)); } monitor.done(); } }
/** * Hook to create an undo change for the given undo edit. This hook gets * called while performing the change to construct the corresponding undo * change object. * <p> * Subclasses may override it to create a different undo change. * </p> * * @param edits * the {@link UndoEdit undo edit} to create a undo change for * @param stampToRestore * the content stamp to restore when the undo edit is executed. * * @return the undo change * * @throws CoreException * if an undo change can't be created */ protected Change createUndoChange(UndoEdit[] edits, ContentStamp stampToRestore) throws CoreException { return new MultiStateUndoChange(getName(), fFile, edits, stampToRestore, fSaveMode); }
if (fValidationState.isValid(needsSaving(), false).hasFatalError()) return new NullChange(); if (pm == null) if (needsSaving()) { buffer.commit(pm, false); if (!success) { return createUndoChange((UndoEdit[]) list.toArray(new UndoEdit[list.size()]), currentStamp); } catch (BadLocationException e) { throw Changes.asCoreException(e);
/** * {@inheritDoc} */ public final Object[] getAffectedObjects() { Object modifiedElement= getModifiedElement(); if (modifiedElement == null) return null; return new Object[] { modifiedElement}; }
/** * {@inheritDoc} */ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { if (pm == null) pm= new NullProgressMonitor(); pm.beginTask("", 1); //$NON-NLS-1$ ITextFileBuffer buffer= FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE); fDirty= buffer != null && buffer.isDirty(); RefactoringStatus result= fValidationState.isValid(needsSaving(), true); pm.worked(1); return result; }
public final Change perform(final IProgressMonitor monitor) throws CoreException { monitor.beginTask("", 3); //$NON-NLS-1$ IDocument document= null; DocumentRewriteSession session= null; try { document= acquireDocument(new SubProgressMonitor(monitor, 1)); if (document instanceof IDocumentExtension4) session= ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED); final LinkedList undoList= new LinkedList(); performChanges(document, undoList, false); if (needsSaving()) fBuffer.commit(new SubProgressMonitor(monitor, 1), false); return new MultiStateUndoChange(getName(), fFile, (UndoEdit[]) undoList.toArray(new UndoEdit[undoList.size()]), fContentStamp, fSaveMode); } catch (BadLocationException exception) { throw Changes.asCoreException(exception); } finally { if (document != null) { try { if (session != null) ((IDocumentExtension4) document).stopRewriteSession(session); } finally { releaseDocument(document, new SubProgressMonitor(monitor, 1)); } } monitor.done(); } }
/** * Hook to create an undo change for the given undo edit. This hook gets * called while performing the change to construct the corresponding undo * change object. * <p> * Subclasses may override it to create a different undo change. * </p> * * @param edits * the {@link UndoEdit undo edit} to create a undo change for * @param stampToRestore * the content stamp to restore when the undo edit is executed. * * @return the undo change * * @throws CoreException * if an undo change can't be created */ protected Change createUndoChange(UndoEdit[] edits, ContentStamp stampToRestore) throws CoreException { return new MultiStateUndoChange(getName(), fFile, edits, stampToRestore, fSaveMode); }
@Override public final Object[] getAffectedObjects() { Object modifiedElement= getModifiedElement(); if (modifiedElement == null) return null; return new Object[] { modifiedElement}; }