org.eclipse.jface.text.ISynchronizable#org.eclipse.core.filebuffers.LocationKind源码实例Demo

下面列出了org.eclipse.jface.text.ISynchronizable#org.eclipse.core.filebuffers.LocationKind 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: eclipse.jdt.ls   文件: DocumentAdapter.java
@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);
	}
}
 
源代码2 项目: eclipse.jdt.ls   文件: JavadocContentAccess2.java
/**
 * Reads the content of the IFile.
 *
 * @param file
 *            the file whose content has to be read
 * @return the content of the file
 * @throws CoreException
 *             if the file could not be successfully connected or disconnected
 */
private static String getIFileContent(IFile file) throws CoreException {
	String content = null;
	ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
	IPath fullPath = file.getFullPath();
	manager.connect(fullPath, LocationKind.IFILE, null);
	try {
		ITextFileBuffer buffer = manager.getTextFileBuffer(fullPath, LocationKind.IFILE);
		if (buffer != null) {
			content = buffer.getDocument().get();
		}
	} finally {
		manager.disconnect(fullPath, LocationKind.IFILE, null);
	}

	return content;
}
 
源代码3 项目: eclipse.jdt.ls   文件: JavadocContentAccess2.java
/**
 * Reads the content of the java.io.File.
 *
 * @param file
 *            the file whose content has to be read
 * @return the content of the file
 * @throws CoreException
 *             if the file could not be successfully connected or disconnected
 */
private static String getFileContent(File file) throws CoreException {
	String content = null;
	ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();

	IPath fullPath = new Path(file.getAbsolutePath());
	manager.connect(fullPath, LocationKind.LOCATION, null);
	try {
		ITextFileBuffer buffer = manager.getTextFileBuffer(fullPath, LocationKind.LOCATION);
		if (buffer != null) {
			content = buffer.getDocument().get();
		}
	} finally {
		manager.disconnect(fullPath, LocationKind.LOCATION, null);
	}
	return content;
}
 
源代码4 项目: eclipse.jdt.ls   文件: JsonRpcHelpers.java
/**
 * Returns an {@link IDocument} for the given {@link IFile}.
 *
 * @param file an {@link IFile}
 * @return a document with the contents of the file,
 * or <code>null</code> if the file can not be opened.
 */
public static IDocument toDocument(IFile file) {
	if (file != null && file.isAccessible()) {
		IPath path = file.getFullPath();
		ITextFileBufferManager fileBufferManager = FileBuffers.getTextFileBufferManager();
		LocationKind kind = LocationKind.IFILE;
		try {
			fileBufferManager.connect(path, kind, new NullProgressMonitor());
			ITextFileBuffer fileBuffer = fileBufferManager.getTextFileBuffer(path, kind);
			if (fileBuffer != null) {
				return fileBuffer.getDocument();
			}
		} catch (CoreException e) {
			JavaLanguageServerPlugin.logException("Failed to convert "+ file +"  to an IDocument", e);
		} finally {
			try {
				fileBufferManager.disconnect(path, kind, new NullProgressMonitor());
			} catch (CoreException slurp) {
				//Don't care
			}
		}
	}
	return null;
}
 
源代码5 项目: xds-ide   文件: ModulaSearchUtils.java
private static void evaluateTextEditor(Map<IFile, IDocument> result, IEditorPart ep, IFile filter) {
    IEditorInput input = ep.getEditorInput();
    if (input instanceof IFileEditorInput) {
        IFile file = ((IFileEditorInput) input).getFile();
        if (filter == null || filter.equals(file)) { 
            if (!result.containsKey(file)) { // take the first editor found
                ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
                ITextFileBuffer textFileBuffer = bufferManager
                        .getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
                if (textFileBuffer != null) {
                    // file buffer has precedence
                    result.put(file, textFileBuffer.getDocument());
                }
                else {
                    // use document provider
                    IDocument document = ((ITextEditor) ep).getDocumentProvider().getDocument(input);
                    if (document != null) {
                        result.put(file, document);
                    }
                }
            }
        }
    }
}
 
源代码6 项目: typescript.java   文件: EditorUtils.java
public static Position getPosition(IFile file, TextSpan textSpan) throws BadLocationException {
	ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
	ITextFileBuffer buffer = bufferManager.getTextFileBuffer(file.getLocation(), LocationKind.IFILE);
	if (buffer != null) {
		return getPosition(buffer.getDocument(), textSpan);
	}
	IDocumentProvider provider = new TextFileDocumentProvider();
	try {
		provider.connect(file);
		IDocument document = provider.getDocument(file);
		if (document != null) {
			return getPosition(document, textSpan);
		}
	} catch (CoreException e) {
	} finally {
		provider.disconnect(file);
	}
	return null;
}
 
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());
	}
}
 
private void checkDirtyFile(RefactoringStatus result, IFile file) {
	if (file == null || !file.exists())
		return;
	ITextFileBuffer buffer= FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
	if (buffer != null && buffer.isDirty()) {
		if (buffer.isStateValidated() && buffer.isSynchronized()) {
			result.addWarning(Messages.format(
				RefactoringCoreMessages.JavaDeleteProcessor_unsaved_changes,
				BasicElementLabels.getPathLabel(file.getFullPath(), false)));
		} else {
			result.addFatalError(Messages.format(
				RefactoringCoreMessages.JavaDeleteProcessor_unsaved_changes,
				BasicElementLabels.getPathLabel(file.getFullPath(), false)));
		}
	}
}
 
private long getDocumentStamp(IFile file, IProgressMonitor monitor) throws CoreException {
 final ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
 final IPath path= file.getFullPath();

 monitor.beginTask("", 2); //$NON-NLS-1$

 ITextFileBuffer buffer= null;
 try {
 	manager.connect(path, LocationKind.IFILE, new SubProgressMonitor(monitor, 1));
  buffer= manager.getTextFileBuffer(path, LocationKind.IFILE);
	    IDocument document= buffer.getDocument();

	    if (document instanceof IDocumentExtension4) {
			return ((IDocumentExtension4)document).getModificationStamp();
		} else {
			return file.getModificationStamp();
		}
 } finally {
 	if (buffer != null)
 		manager.disconnect(path, LocationKind.IFILE, new SubProgressMonitor(monitor, 1));
 	monitor.done();
 }
}
 
/**
 * Reads the content of the IFile.
 * 
 * @param file the file whose content has to be read
 * @return the content of the file
 * @throws CoreException if the file could not be successfully connected or disconnected
 */
private static String getIFileContent(IFile file) throws CoreException {
	String content= null;
	ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
	IPath fullPath= file.getFullPath();
	manager.connect(fullPath, LocationKind.IFILE, null);
	try {
		ITextFileBuffer buffer= manager.getTextFileBuffer(fullPath, LocationKind.IFILE);
		if (buffer != null) {
			content= buffer.getDocument().get();
		}
	} finally {
		manager.disconnect(fullPath, LocationKind.IFILE, null);
	}

	return content;
}
 
/**
 * Reads the content of the java.io.File.
 * 
 * @param file the file whose content has to be read
 * @return the content of the file
 * @throws CoreException if the file could not be successfully connected or disconnected
 */
private static String getFileContent(File file) throws CoreException {
	String content= null;
	ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();

	IPath fullPath= new Path(file.getAbsolutePath());
	manager.connect(fullPath, LocationKind.LOCATION, null);
	try {
		ITextFileBuffer buffer= manager.getTextFileBuffer(fullPath, LocationKind.LOCATION);
		if (buffer != null) {
			content= buffer.getDocument().get();
		}
	} finally {
		manager.disconnect(fullPath, LocationKind.LOCATION, null);
	}
	return content;
}
 
源代码12 项目: Pydev   文件: FileUtils.java
/**
 * @param path the path we're interested in
 * @return a file buffer to be used.
 */
public static ITextFileBuffer getBufferFromPath(IPath path) {
    try {
        //eclipse 3.3 onwards
        ITextFileBufferManager textFileBufferManager = ITextFileBufferManager.DEFAULT;
        if (textFileBufferManager != null) {//we don't have it in tests
            ITextFileBuffer textFileBuffer = textFileBufferManager.getTextFileBuffer(path,
                    LocationKind.LOCATION);

            if (textFileBuffer != null) { //we don't have it when it is not properly refreshed
                return textFileBuffer;
            }
        }
        return null;

    } catch (Throwable e) {
        //private static final IWorkspaceRoot WORKSPACE_ROOT= ResourcesPlugin.getWorkspace().getRoot();
        //throws an error and we don't even have access to the FileBuffers class in tests
        if (!IN_TESTS) {
            Log.log("Unable to get doc from text file buffer");
        }
        return null;
    }
}
 
源代码13 项目: goclipse   文件: ResourceUtils.java
public static ITextFileBuffer getTextFileBuffer(ITextFileBufferManager fbm, Path filePath) {
	
	ITextFileBuffer fileBuffer;
	fileBuffer = fbm.getTextFileBuffer(epath(filePath), LocationKind.NORMALIZE);
	if(fileBuffer != null) {
		return fileBuffer;
	}
	
	// Could be an external file, try alternative API:
	fileBuffer = fbm.getFileStoreTextFileBuffer(FileBuffers.getFileStoreAtLocation(epath(filePath)));
	if(fileBuffer != null) {
		return fileBuffer;
	}
	
	// Fall back, try LocationKind.LOCATION
	fileBuffer = fbm.getTextFileBuffer(epath(filePath), LocationKind.LOCATION);
	if(fileBuffer != null) {
		return fileBuffer;
	}
	
	return null;
}
 
源代码14 项目: eclipse.jdt.ls   文件: DocumentAdapter.java
public DocumentAdapter(IOpenable owner, IFile file) {
	fOwner = owner;
	fFile = file;
	fBufferListeners = new ArrayList<>(3);
	fIsClosed = false;

	ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
	try {
		manager.connect(file.getFullPath(), LocationKind.IFILE, null);
		fTextFileBuffer= manager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
	} catch (CoreException e) {
	}
}
 
源代码15 项目: eclipse.jdt.ls   文件: DocumentAdapter.java
@Override
public void close() {
	synchronized (lock) {
		if (fIsClosed) {
			return;
		}

		fIsClosed= true;
		if (fDocument != null) {
			fDocument.removeDocumentListener(this);
		}

		if (fTextFileBuffer != null && fFile != 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;
	}
}
 
源代码16 项目: eclipse.jdt.ls   文件: TextSearchVisitor.java
private IDocument getOpenDocument(IFile file, Map<IFile, IDocument> documentsInEditors) {
	IDocument document= documentsInEditors.get(file);
	if (document == null) {
		ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager();
		ITextFileBuffer textFileBuffer= bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
		if (textFileBuffer != null) {
			document= textFileBuffer.getDocument();
		}
	}
	return document;
}
 
源代码17 项目: eclipse.jdt.ls   文件: RefactoringFileBuffers.java
/**
 * Returns the text file buffer for the specified compilation unit.
 *
 * @param unit the compilation unit whose text file buffer to retrieve
 * @return the associated text file buffer, or <code>null</code> if no text file buffer is managed for the compilation unit
 */
public static ITextFileBuffer getTextFileBuffer(final ICompilationUnit unit) {
	Assert.isNotNull(unit);
	final IResource resource= unit.getResource();
	if (resource == null || resource.getType() != IResource.FILE) {
		return null;
	}
	return FileBuffers.getTextFileBufferManager().getTextFileBuffer(resource.getFullPath(), LocationKind.IFILE);
}
 
源代码18 项目: eclipse.jdt.ls   文件: RefactoringFileBuffers.java
/**
 * Releases the text file buffer associated with the compilation unit.
 *
 * @param unit the compilation unit whose text file buffer has to be released
 * @throws CoreException if the buffer could not be successfully released
 */
public static void release(final ICompilationUnit unit) throws CoreException {
	Assert.isNotNull(unit);
	final IResource resource= unit.getResource();
	if (resource != null && resource.getType() == IResource.FILE) {
		FileBuffers.getTextFileBufferManager().disconnect(resource.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
	}
}
 
private static String getFileContents(IFile file) throws CoreException {
	ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
	IPath path= file.getFullPath();
	manager.connect(path, LocationKind.IFILE, new NullProgressMonitor());
	try {
		return manager.getTextFileBuffer(path, LocationKind.IFILE).getDocument().get();
	} finally {
		manager.disconnect(path, LocationKind.IFILE, new NullProgressMonitor());
	}
}
 
源代码20 项目: eclipse.jdt.ls   文件: AbstractDeleteChange.java
protected 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()) {
		pm.beginTask("", 2); //$NON-NLS-1$
		buffer.commit(new SubProgressMonitor(pm, 1), false);
		file.refreshLocal(IResource.DEPTH_ONE, new SubProgressMonitor(pm, 1));
	}
	pm.done();
}
 
源代码21 项目: xds-ide   文件: XdsSymfileDocumentProvider.java
@Override
protected IDocument createEmptyDocument() {
	IDocument document= FileBuffers.getTextFileBufferManager().createEmptyDocument(null, LocationKind.IFILE);
	if (document instanceof ISynchronizable)
		((ISynchronizable)document).setLockObject(new Object());
	return document;
}
 
源代码22 项目: typescript.java   文件: TypeScriptResourceUtil.java
/**
 * Returns the {@link IDocument} from the given file and null if it's not
 * possible.
 */
public static IDocument getDocument(IPath location) {
	ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();

	boolean connected = false;
	try {
		ITextFileBuffer buffer = manager.getTextFileBuffer(location, LocationKind.NORMALIZE);
		if (buffer == null) {
			// no existing file buffer..create one
			manager.connect(location, LocationKind.NORMALIZE, new NullProgressMonitor());
			connected = true;
			buffer = manager.getTextFileBuffer(location, LocationKind.NORMALIZE);
			if (buffer == null) {
				return null;
			}
		}

		return buffer.getDocument();
	} catch (CoreException ce) {
		TypeScriptCorePlugin.logError(ce, "Error while getting document from file");
		return null;
	} finally {
		if (connected) {
			try {
				manager.disconnect(location, LocationKind.NORMALIZE, new NullProgressMonitor());
			} catch (CoreException e) {
				TypeScriptCorePlugin.logError(e, "Error while getting document from file");
			}
		}
	}
}
 
/**
 * Returns the text file buffer for the specified compilation unit.
 *
 * @param unit the compilation unit whose text file buffer to retrieve
 * @return the associated text file buffer, or <code>null</code> if no text file buffer is managed for the compilation unit
 */
public static ITextFileBuffer getTextFileBuffer(final ICompilationUnit unit) {
	Assert.isNotNull(unit);
	final IResource resource= unit.getResource();
	if (resource == null || resource.getType() != IResource.FILE)
		return null;
	return FileBuffers.getTextFileBufferManager().getTextFileBuffer(resource.getFullPath(), LocationKind.IFILE);
}
 
/**
 * Releases the text file buffer associated with the compilation unit.
 *
 * @param unit the compilation unit whose text file buffer has to be released
 * @throws CoreException if the buffer could not be successfully released
 */
public static void release(final ICompilationUnit unit) throws CoreException {
	Assert.isNotNull(unit);
	final IResource resource= unit.getResource();
	if (resource != null && resource.getType() == IResource.FILE)
		FileBuffers.getTextFileBufferManager().disconnect(resource.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
}
 
private static String getFileContents(IFile file) throws CoreException {
	ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
	IPath path= file.getFullPath();
	manager.connect(path, LocationKind.IFILE, new NullProgressMonitor());
	try {
		return manager.getTextFileBuffer(path, LocationKind.IFILE).getDocument().get();
	} finally {
		manager.disconnect(path, LocationKind.IFILE, new NullProgressMonitor());
	}
}
 
protected 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()) {
		pm.beginTask("", 2); //$NON-NLS-1$
		buffer.commit(new SubProgressMonitor(pm, 1), false);
		file.refreshLocal(IResource.DEPTH_ONE, new SubProgressMonitor(pm, 1));
	}
	pm.done();
}
 
private InputStream createInputStream(IFile propertiesFile) throws CoreException {
	ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
	if (manager != null) {
		ITextFileBuffer buffer= manager.getTextFileBuffer(propertiesFile.getFullPath(), LocationKind.IFILE);
		if (buffer != null) {
			return new ByteArrayInputStream(buffer.getDocument().get().getBytes());
		}
	}

	return propertiesFile.getContents();
}
 
public boolean isContainerDirty(TypeNameMatch match) {
	ICompilationUnit cu= match.getType().getCompilationUnit();
	if (cu == null) {
		return false;
	}
	IResource resource= cu.getResource();
	ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
	ITextFileBuffer textFileBuffer= manager.getTextFileBuffer(resource.getFullPath(), LocationKind.IFILE);
	if (textFileBuffer != null) {
		return textFileBuffer.isDirty();
	}
	return false;
}
 
@Override
protected IDocument createEmptyDocument() {
	IDocument document= FileBuffers.getTextFileBufferManager().createEmptyDocument(null, LocationKind.IFILE);
	if (document instanceof ISynchronizable)
		((ISynchronizable)document).setLockObject(new Object());
	return document;
}
 
/**
 * Constructs a new document adapter.
 *
 * @param owner the owner of this buffer
 * @param path the path of the file that backs the buffer
 * @since 3.2
 */
public DocumentAdapter(IOpenable owner, IPath path) {
	Assert.isLegal(path != null);
	fOwner= owner;
	fPath= path;
	fLocationKind= LocationKind.NORMALIZE;

	initialize();
}