use of org.eclipse.core.runtime.CoreException in project che by eclipse.
the class MultiStateTextFileChange method isValid.
/*
* @see org.eclipse.ltk.core.refactoring.Change#isValid(org.eclipse.core.runtime.IProgressMonitor)
*/
public final RefactoringStatus isValid(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
if (monitor == null)
monitor = new NullProgressMonitor();
//$NON-NLS-1$
monitor.beginTask("", 1);
try {
if (fValidationState == null)
//$NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), "MultiStateTextFileChange has not been initialialized"));
final ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
fDirty = buffer != null && buffer.isDirty();
final RefactoringStatus status = fValidationState.isValid(needsSaving());
if (needsSaving()) {
status.merge(Changes.validateModifiesFiles(new IFile[] { fFile }));
} else {
// we are reading the file. So it should be at least in sync
status.merge(Changes.checkInSync(new IFile[] { fFile }));
}
return status;
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.CoreException in project che by eclipse.
the class PerformChangeOperation method executeChange.
/**
* Actually executes the change.
*
* @param pm a progress monitor to report progress
*
* @throws CoreException if an unexpected error occurs during
* change execution
*/
protected void executeChange(IProgressMonitor pm) throws CoreException {
fChangeExecuted = false;
if (!fChange.isEnabled())
return;
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
boolean undoInitialized = false;
try {
//$NON-NLS-1$
monitor.beginTask("", 10);
fValidationStatus = fChange.isValid(new SubProgressMonitor(monitor, 1));
if (fValidationStatus.hasFatalError())
return;
boolean aboutToPerformChangeCalled = false;
try {
if (fUndoManager != null) {
ResourcesPlugin.getWorkspace().checkpoint(false);
fUndoManager.aboutToPerformChange(fChange);
aboutToPerformChangeCalled = true;
}
fChangeExecutionFailed = true;
fUndoChange = fChange.perform(new SubProgressMonitor(monitor, 9));
fChangeExecutionFailed = false;
fChangeExecuted = true;
} finally {
if (fUndoManager != null) {
ResourcesPlugin.getWorkspace().checkpoint(false);
if (aboutToPerformChangeCalled)
fUndoManager.changePerformed(fChange, !fChangeExecutionFailed);
}
}
fChange.dispose();
if (fUndoChange != null) {
fUndoChange.initializeValidationData(new NotCancelableProgressMonitor(new SubProgressMonitor(monitor, 1)));
undoInitialized = true;
}
if (fUndoManager != null) {
if (fUndoChange != null) {
fUndoManager.addUndo(fUndoName, fUndoChange);
} else {
fUndoManager.flush();
}
}
} catch (CoreException e) {
if (fUndoManager != null)
fUndoManager.flush();
if (fUndoChange != null && undoInitialized) {
Change ch = fUndoChange;
fUndoChange = null;
ch.dispose();
}
fUndoChange = null;
throw e;
} catch (RuntimeException e) {
if (fUndoManager != null)
fUndoManager.flush();
if (fUndoChange != null && undoInitialized) {
Change ch = fUndoChange;
fUndoChange = null;
ch.dispose();
}
fUndoChange = null;
throw e;
} finally {
monitor.done();
}
}
};
ResourcesPlugin.getWorkspace().run(runnable, fSchedulingRule, IWorkspace.AVOID_UPDATE, pm);
}
use of org.eclipse.core.runtime.CoreException in project che by eclipse.
the class TextEditChangePreviewViewer method setInput.
// public void createControl(Composite parent) {
// fViewer = new ComparePreviewer(parent);
// }
//
// public Control getControl() {
// return fViewer;
// }
public ChangePreview setInput(ChangePreviewViewerInput input) {
try {
Change change = input.getChange();
if (input instanceof TextEditBasedChangeInput) {
TextEditBasedChangeInput extended = (TextEditBasedChangeInput) input;
if (extended.group != null && extended.surroundingLines >= 0) {
TextEditBasedChangeGroup group = extended.group;
TextEditBasedChange editChange = group.getTextEditChange();
// setInput(editChange, editChange.getCurrentContent(group.getRegion(), true, 2, new NullProgressMonitor()),
// editChange.getPreviewContent(new TextEditBasedChangeGroup[]{group}, group.getRegion(), true, 2,
// new NullProgressMonitor()),
// editChange.getTextType());
ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
preview.setFileName(getFileName(editChange));
preview.setOldContent(editChange.getCurrentContent(group.getRegion(), true, 2, new NullProgressMonitor()));
preview.setNewContent(editChange.getPreviewContent(new TextEditBasedChangeGroup[] { group }, group.getRegion(), true, 2, new NullProgressMonitor()));
return preview;
} else if (extended.groups != null && extended.groups.length > 0 && extended.range != null) {
TextEditBasedChange editChange = extended.groups[0].getTextEditChange();
TextEditBasedChangeGroup[] groups = extended.groups;
// if (extended.groupCategory != null) {
//
// }
// setInput(editChange, editChange.getCurrentContent(extended.range, true, 0, new NullProgressMonitor()),
// editChange.getPreviewContent(groups, extended.range, true, 0, new NullProgressMonitor()),
// editChange.getTextType());
ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
preview.setFileName(getFileName(editChange));
preview.setOldContent(editChange.getCurrentContent(extended.range, true, 0, new NullProgressMonitor()));
preview.setNewContent(editChange.getPreviewContent(groups, extended.range, true, 0, new NullProgressMonitor()));
return preview;
}
} else if (change instanceof TextEditBasedChange) {
TextEditBasedChange editChange = (TextEditBasedChange) change;
// setInput(editChange, editChange.getCurrentContent(new NullProgressMonitor()),
// editChange.getPreviewContent(new NullProgressMonitor()), editChange.getTextType());
ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
preview.setFileName(getFileName(editChange));
preview.setOldContent(editChange.getCurrentContent(new NullProgressMonitor()));
preview.setNewContent(editChange.getPreviewContent(new NullProgressMonitor()));
return preview;
} else {
// fViewer.setInput(null);
return null;
}
} catch (CoreException | AssertionFailedException e) {
JavaPlugin.log(e);
// fViewer.setInput(null);
return null;
}
// }
return null;
}
use of org.eclipse.core.runtime.CoreException in project che by eclipse.
the class CompletionProposalCollector method acceptPotentialMethodDeclaration.
private void acceptPotentialMethodDeclaration(CompletionProposal proposal) {
try {
IJavaElement enclosingElement = null;
// if (getContext().isExtended()) {
// enclosingElement= getContext().getEnclosingElement();
// } else if (fCompilationUnit != null) {
// kept for backward compatibility: CU is not reconciled at this moment, information is missing (bug 70005)
enclosingElement = fCompilationUnit.getElementAt(proposal.getCompletionLocation() + 1);
// }
if (enclosingElement == null)
return;
IType type = (IType) enclosingElement.getAncestor(IJavaElement.TYPE);
if (type != null) {
String prefix = String.valueOf(proposal.getName());
int completionStart = proposal.getReplaceStart();
int completionEnd = proposal.getReplaceEnd();
int relevance = computeRelevance(proposal);
GetterSetterCompletionProposal.evaluateProposals(type, prefix, completionStart, completionEnd - completionStart, relevance + 2, fSuggestedMethodNames, fJavaProposals);
MethodDeclarationCompletionProposal.evaluateProposals(type, prefix, completionStart, completionEnd - completionStart, relevance, fSuggestedMethodNames, fJavaProposals);
}
} catch (CoreException e) {
JavaPlugin.log(e);
}
}
use of org.eclipse.core.runtime.CoreException in project che by eclipse.
the class FileStoreTextFileBuffer method revert.
/*
* @see org.eclipse.core.filebuffers.IFileBuffer#revert(org.eclipse.core.runtime.IProgressMonitor)
*/
public void revert(IProgressMonitor monitor) throws CoreException {
if (isDisconnected())
return;
IDocument original = null;
fStatus = null;
try {
original = fManager.createEmptyDocument(getLocationOrName(), LocationKind.LOCATION);
cacheEncodingState();
setDocumentContent(original, fFileStore, fEncoding, fHasBOM, monitor);
} catch (CoreException x) {
fStatus = x.getStatus();
}
if (original == null)
return;
String originalContents = original.get();
boolean replaceContents = !originalContents.equals(fDocument.get());
if (!replaceContents && !fCanBeSaved)
return;
fManager.fireStateChanging(this);
try {
if (replaceContents) {
fManager.fireBufferContentAboutToBeReplaced(this);
fDocument.set(original.get());
}
boolean fireDirtyStateChanged = fCanBeSaved;
if (fCanBeSaved) {
fCanBeSaved = false;
addFileBufferContentListeners();
}
if (replaceContents)
fManager.fireBufferContentReplaced(this);
IFileInfo info = fFileStore.fetchInfo();
if (info.exists())
fSynchronizationStamp = fFileStore.fetchInfo().getLastModified();
if (fireDirtyStateChanged)
fManager.fireDirtyStateChanged(this, fCanBeSaved);
} catch (RuntimeException x) {
fManager.fireStateChangeFailed(this);
throw x;
}
}
Aggregations