Search in sources :

Example 16 with ITextFileBuffer

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());
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 17 with ITextFileBuffer

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();
    }
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 18 with ITextFileBuffer

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();
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer)

Example 19 with ITextFileBuffer

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));
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) UndoEdit(org.eclipse.text.edits.UndoEdit) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 20 with ITextFileBuffer

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer)

Aggregations

ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)20 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 BadLocationException (org.eclipse.jface.text.BadLocationException)6 IDocument (org.eclipse.jface.text.IDocument)6 CoreException (org.eclipse.core.runtime.CoreException)5 IPath (org.eclipse.core.runtime.IPath)4 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)4 UndoEdit (org.eclipse.text.edits.UndoEdit)4 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 ArrayList (java.util.ArrayList)2 IFile (org.eclipse.core.resources.IFile)2 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 ResourceChangedEvent (org.eclipse.che.jdt.core.resources.ResourceChangedEvent)1 TextViewer (org.eclipse.che.jdt.javaeditor.TextViewer)1 LocationKind (org.eclipse.core.filebuffers.LocationKind)1 Path (org.eclipse.core.runtime.Path)1 IBuffer (org.eclipse.jdt.core.IBuffer)1