use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class CodeRefactoringUtil method getIndentationLevel.
public static int getIndentationLevel(ASTNode node, ICompilationUnit unit) throws CoreException {
IPath fullPath = unit.getCorrespondingResource().getFullPath();
try {
FileBuffers.getTextFileBufferManager().connect(fullPath, LocationKind.IFILE, new NullProgressMonitor());
ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fullPath, LocationKind.IFILE);
try {
IRegion region = buffer.getDocument().getLineInformationOfOffset(node.getStartPosition());
return Strings.computeIndentUnits(buffer.getDocument().get(region.getOffset(), region.getLength()), unit.getJavaProject());
} catch (BadLocationException exception) {
JavaPlugin.log(exception);
}
return 0;
} finally {
FileBuffers.getTextFileBufferManager().disconnect(fullPath, LocationKind.IFILE, new NullProgressMonitor());
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class DeleteResourceChange method saveFileIfNeeded.
private static void saveFileIfNeeded(IFile file, IProgressMonitor pm) throws CoreException {
ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
if (buffer != null && buffer.isDirty() && buffer.isStateValidated() && buffer.isSynchronized()) {
//$NON-NLS-1$
pm.beginTask("", 2);
buffer.commit(new SubProgressMonitor(pm, 1), false);
file.refreshLocal(IResource.DEPTH_ONE, new SubProgressMonitor(pm, 1));
pm.done();
} else {
//$NON-NLS-1$
pm.beginTask("", 1);
pm.worked(1);
pm.done();
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class UndoTextFileChange method isValid.
/**
* {@inheritDoc}
*/
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
//$NON-NLS-1$
pm.beginTask("", 1);
try {
if (fValidationState == null)
//$NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), "UndoTextFileChange has not been initialialized"));
ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
fDirty = buffer != null && buffer.isDirty();
return fValidationState.isValid(needsSaving(), true);
} finally {
pm.done();
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class UndoTextFileChange method perform.
/**
* {@inheritDoc}
*/
public Change perform(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
//$NON-NLS-1$
pm.beginTask("", 2);
ITextFileBuffer buffer = null;
try {
manager.connect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
buffer = manager.getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
IDocument document = buffer.getDocument();
ContentStamp currentStamp = ContentStamps.get(fFile, document);
boolean[] setContentStampSuccess = { false };
UndoEdit redo = performEdits(buffer, document, setContentStampSuccess);
if (needsSaving()) {
buffer.commit(pm, false);
if (!setContentStampSuccess[0]) {
// We weren't able to restore document stamp.
// Since we save restore the file stamp instead
ContentStamps.set(fFile, fContentStampToRestore);
}
}
return createUndoChange(redo, currentStamp);
} catch (BadLocationException e) {
if (fValidationState == null || !fValidationState.wasDerived())
throw Changes.asCoreException(e);
else
return new NullChange();
} catch (MalformedTreeException e) {
if (fValidationState == null || !fValidationState.wasDerived())
throw Changes.asCoreException(e);
else
return new NullChange();
} catch (CoreException e) {
if (fValidationState == null || !fValidationState.wasDerived())
throw e;
else
return new NullChange();
} finally {
if (buffer != null)
manager.disconnect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class ModificationStampValidationState method getBuffer.
protected static ITextFileBuffer getBuffer(IFile file) {
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
IPath path = file.getFullPath();
ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
return buffer;
}
Aggregations