Search in sources :

Example 76 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.jdt.ls by eclipse.

the class SerialVersionHashOperation method computeId.

private String computeId(final ASTNode declarationNode, final IProgressMonitor monitor) throws InterruptedException {
    Assert.isNotNull(monitor);
    long serialVersionID = SERIAL_VALUE;
    try {
        monitor.beginTask(CorrectionMessages.SerialVersionHashOperation_computing_id, 200);
        final IJavaProject project = fCompilationUnit.getJavaProject();
        final IPath path = fCompilationUnit.getResource().getFullPath();
        ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
        try {
            bufferManager.connect(path, LocationKind.IFILE, new SubProgressMonitor(monitor, 10));
            if (monitor.isCanceled()) {
                throw new InterruptedException();
            }
            if (monitor.isCanceled()) {
                throw new InterruptedException();
            }
        } finally {
            bufferManager.disconnect(path, LocationKind.IFILE, new SubProgressMonitor(monitor, 10));
        }
        project.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new SubProgressMonitor(monitor, 60));
        if (monitor.isCanceled()) {
            throw new InterruptedException();
        }
        ITypeBinding typeBinding = getTypeBinding(declarationNode);
        if (typeBinding != null) {
            Long id = calculateSerialVersionId(typeBinding, new SubProgressMonitor(monitor, 100));
            if (id != null) {
                serialVersionID = id.longValue();
            }
        }
    } catch (CoreException exception) {
        JavaLanguageServerPlugin.logException(exception.getMessage(), exception);
    } catch (IOException exception) {
        JavaLanguageServerPlugin.logException(exception.getMessage(), exception);
    } finally {
        monitor.done();
    }
    return serialVersionID + LONG_SUFFIX;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) IOException(java.io.IOException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 77 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.jdt.ls by eclipse.

the class DocumentAdapter method close.

@Override
public void close() {
    synchronized (lock) {
        if (fIsClosed) {
            return;
        }
        fIsClosed = true;
        fDocument.removeDocumentListener(this);
        if (fTextFileBuffer != null) {
            try {
                ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
                manager.disconnect(fFile.getFullPath(), LocationKind.NORMALIZE, null);
            } catch (CoreException x) {
            // ignore
            }
            fTextFileBuffer = null;
        }
        fireBufferChanged(new BufferChangedEvent(this, 0, 0, null));
        fBufferListeners.clear();
        fDocument = null;
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) BufferChangedEvent(org.eclipse.jdt.core.BufferChangedEvent)

Example 78 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.jdt.ls by eclipse.

the class DocumentAdapter method setContents.

@Override
public void setContents(String contents) {
    synchronized (lock) {
        if (fDocument == null) {
            if (fTextFileBuffer != null) {
                fDocument = fTextFileBuffer.getDocument();
            } else {
                ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
                fDocument = manager.createEmptyDocument(fFile.getFullPath(), LocationKind.IFILE);
            }
            fDocument.addDocumentListener(this);
            ((ISynchronizable) fDocument).setLockObject(lock);
        }
    }
    if (!contents.equals(fDocument.get())) {
        fDocument.set(contents);
    }
}
Also used : ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ISynchronizable(org.eclipse.jface.text.ISynchronizable)

Example 79 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project jbosstools-hibernate by jbosstools.

the class NewHibernateMappingPreviewPage method performDisconnect.

protected void performDisconnect() {
    final ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
    for (IPath filePathTo_Show : paths2Disconnect) {
        try {
            bufferManager.disconnect(filePathTo_Show, LocationKind.IFILE, null);
        } catch (CoreException e) {
            // $NON-NLS-1$
            HibernateConsolePlugin.getDefault().logErrorMessage("CoreException: ", e);
        }
    }
    paths2Disconnect.clear();
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager)

Example 80 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project egit by eclipse.

the class IndexDiffCache method dispose.

/**
 * Used by {@link Activator}
 */
public void dispose() {
    if (bufferListener != null) {
        ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
        if (bufferManager != null) {
            bufferManager.removeFileBufferListener(bufferListener);
            bufferListener = null;
        }
    }
    for (IndexDiffCacheEntry entry : entries.values()) {
        entry.dispose();
    }
    Job.getJobManager().cancel(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
    try {
        Job.getJobManager().join(JobFamilies.INDEX_DIFF_CACHE_UPDATE, null);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
Also used : ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager)

Aggregations

ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)87 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)66 IDocument (org.eclipse.jface.text.IDocument)54 IPath (org.eclipse.core.runtime.IPath)52 CoreException (org.eclipse.core.runtime.CoreException)36 BadLocationException (org.eclipse.jface.text.BadLocationException)26 IFile (org.eclipse.core.resources.IFile)22 Test (org.junit.Test)17 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)11 IOException (java.io.IOException)10 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)10 IResource (org.eclipse.core.resources.IResource)8 Path (org.eclipse.core.runtime.Path)8 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)7 TextEdit (org.eclipse.text.edits.TextEdit)7 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)6 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)6 UndoEdit (org.eclipse.text.edits.UndoEdit)6 FileNotFoundException (java.io.FileNotFoundException)5 MalformedURLException (java.net.MalformedURLException)5