org.eclipse.core.filebuffers.ITextFileBuffer Java Examples
The following examples show how to use
org.eclipse.core.filebuffers.ITextFileBuffer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResourceUtils.java From goclipse with Eclipse Public License 1.0 | 6 votes |
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; }
Example #2
Source File: FileUtils.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * @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; } }
Example #3
Source File: PyChange.java From Pydev with Eclipse Public License 1.0 | 6 votes |
public long getModificationStamp(IResource resource) { if (!(resource instanceof IFile)) { return resource.getModificationStamp(); } IFile file = (IFile) resource; ITextFileBuffer buffer = getBuffer(file); if (buffer == null) { return file.getModificationStamp(); } else { IDocument document = buffer.getDocument(); if (document instanceof IDocumentExtension4) { return ((IDocumentExtension4) document).getModificationStamp(); } else { return file.getModificationStamp(); } } }
Example #4
Source File: JavadocContentAccess2.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * 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; }
Example #5
Source File: JavadocContentAccess2.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * 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; }
Example #6
Source File: CleanUpPostSaveListener.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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(); } }
Example #7
Source File: DeleteChangeCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static TextChange addTextEditFromRewrite(TextChangeManager manager, ICompilationUnit cu, ASTRewrite rewrite) throws CoreException { try { ITextFileBuffer buffer= RefactoringFileBuffers.acquire(cu); TextEdit resultingEdits= rewrite.rewriteAST(buffer.getDocument(), cu.getJavaProject().getOptions(true)); TextChange textChange= manager.get(cu); if (textChange instanceof TextFileChange) { TextFileChange tfc= (TextFileChange) textChange; tfc.setSaveMode(TextFileChange.KEEP_SAVE_STATE); } String message= RefactoringCoreMessages.DeleteChangeCreator_1; TextChangeCompatibility.addTextEdit(textChange, message, resultingEdits); return textChange; } finally { RefactoringFileBuffers.release(cu); } }
Example #8
Source File: JavaDeleteProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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))); } } }
Example #9
Source File: CodeRefactoringUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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()); } }
Example #10
Source File: EditorUtils.java From typescript.java with MIT License | 6 votes |
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; }
Example #11
Source File: ModulaSearchUtils.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
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); } } } } } }
Example #12
Source File: JavadocContentAccess2.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
/** * 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; }
Example #13
Source File: JavadocContentAccess2.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
/** * 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; }
Example #14
Source File: JsonRpcHelpers.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
/** * 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; }
Example #15
Source File: DeleteChangeCreator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static TextChange addTextEditFromRewrite(TextChangeManager manager, ICompilationUnit cu, ASTRewrite rewrite) throws CoreException { try { ITextFileBuffer buffer= RefactoringFileBuffers.acquire(cu); TextEdit resultingEdits= rewrite.rewriteAST(buffer.getDocument(), cu.getJavaProject().getOptions(true)); TextChange textChange= manager.get(cu); if (textChange instanceof TextFileChange) { TextFileChange tfc= (TextFileChange) textChange; tfc.setSaveMode(TextFileChange.KEEP_SAVE_STATE); } String message= RefactoringCoreMessages.DeleteChangeCreator_1; TextChangeCompatibility.addTextEdit(textChange, message, resultingEdits); return textChange; } finally { RefactoringFileBuffers.release(cu); } }
Example #16
Source File: DocumentReconcileManager.java From goclipse with Eclipse Public License 1.0 | 5 votes |
public DocumentReconcileConnection connectDocument(IDocument document, StructureInfo structureInfo) { Location location = structureInfo.getLocation(); ITextFileBuffer textFileBuffer = location == null ? null : ResourceUtils.getTextFileBuffer(fbm, location); if(textFileBuffer != null) { return new TextReconcileConnection(document, structureInfo, textFileBuffer); } return new DocumentReconcileConnection(document, structureInfo); }
Example #17
Source File: PyDocumentProvider.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * The file buffer for the given element or null if no buffer is available. */ public ITextFileBuffer getFileBuffer(Object element) { FileInfo fileInfo = super.getFileInfo(element); if (fileInfo == null) { return null; } return fileInfo.fTextFileBuffer; }
Example #18
Source File: ChangedLinesComputer.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Return the lines which have changed in the given buffer since the last save occurred. * * @param buffer the buffer to compare contents from * @param monitor to report progress to * @return the regions of the changed lines or null if something went wrong. */ public static int[] calculateChangedLines(final ITextFileBuffer buffer, final IProgressMonitor monitor) throws CoreException { int[] result = null; try { monitor.beginTask("Calculating changed lines", 20); IFileStore fileStore = buffer.getFileStore(); ITextFileBufferManager fileBufferManager = FileBuffers.createTextFileBufferManager(); fileBufferManager.connectFileStore(fileStore, getSubProgressMonitor(monitor, 15)); try { IDocument currentDocument = buffer.getDocument(); IDocument oldDocument = ((ITextFileBuffer) fileBufferManager.getFileStoreFileBuffer(fileStore)) .getDocument(); result = getChangedLines(oldDocument, currentDocument); } finally { fileBufferManager.disconnectFileStore(fileStore, getSubProgressMonitor(monitor, 5)); monitor.done(); } } catch (Exception e) { Log.log(e); return null; } return result; }
Example #19
Source File: FileUtils.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * @return null if it was unable to get the document from the path (this may happen if it was not refreshed). * Or the document that represents the file */ public static IDocument getDocFromPath(IPath path) { ITextFileBuffer buffer = getBufferFromPath(path); if (buffer != null) { return buffer.getDocument(); } return null; }
Example #20
Source File: PyChange.java From Pydev with Eclipse Public License 1.0 | 5 votes |
private static ITextFileBuffer getBuffer(IFile file) { try { ITextFileBufferManager manager = ITextFileBufferManager.DEFAULT; return manager.getTextFileBuffer(file.getFullPath(), org.eclipse.core.filebuffers.LocationKind.IFILE); } catch (Throwable e) {//NoSuchMethod/NoClassDef exception if (e instanceof ClassNotFoundException || e instanceof LinkageError || e instanceof NoSuchMethodException || e instanceof NoSuchMethodError || e instanceof NoClassDefFoundError) { return null; // that's ok -- not available in Eclipse 3.2 } throw new RuntimeException(e); } }
Example #21
Source File: ContentTypeHelper.java From tm4e with Eclipse Public License 1.0 | 5 votes |
/** * Returns the content of the given buffer. * * @param buffer * @return the content of the given buffer. * @throws CoreException */ private static InputStream getContents(ITextFileBuffer buffer) throws CoreException { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IFile file = workspaceRoot.getFile(buffer.getLocation()); if (file.exists() && buffer.isSynchronized()) { return file.getContents(); } return buffer.getFileStore().openInputStream(EFS.NONE, null); }
Example #22
Source File: TexSpellingEngine.java From texlipse with Eclipse Public License 1.0 | 5 votes |
/** * Returns the project that belongs to the given document. * Thanks to Nitin Dahyabhai for the tip. * * @param document * @return the project or <code>null</code> if no project was found */ private static IProject getProject(IDocument document) { ITextFileBufferManager fileBufferMgr = FileBuffers.getTextFileBufferManager(); ITextFileBuffer fileBuffer = fileBufferMgr.getTextFileBuffer(document); if (fileBuffer != null) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IResource res = workspace.getRoot().findMember(fileBuffer.getLocation()); if (res != null) return res.getProject(); } return null; }
Example #23
Source File: TextSearchVisitor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
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; }
Example #24
Source File: OpenTypeHistory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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; }
Example #25
Source File: NLSSearchResultRequestor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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(); }
Example #26
Source File: PasteAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Change createChange(IProgressMonitor pm) throws CoreException { ASTParser p= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL); p.setSource(getDestinationCu()); CompilationUnit cuNode= (CompilationUnit) p.createAST(pm); ASTRewrite rewrite= ASTRewrite.create(cuNode.getAST()); TypedSource source= null; for (int i= fSources.length - 1; i >= 0; i--) { source= fSources[i]; final ASTNode destination= getDestinationNodeForSourceElement(fDestination, source.getType(), cuNode); if (destination != null) { if (destination instanceof CompilationUnit) insertToCu(rewrite, createNewNodeToInsertToCu(source, rewrite), (CompilationUnit) destination); else if (destination instanceof AbstractTypeDeclaration) insertToType(rewrite, createNewNodeToInsertToType(source, rewrite), (AbstractTypeDeclaration) destination); } } final CompilationUnitChange result= new CompilationUnitChange(ReorgMessages.PasteAction_change_name, getDestinationCu()); try { ITextFileBuffer buffer= RefactoringFileBuffers.acquire(getDestinationCu()); TextEdit rootEdit= rewrite.rewriteAST(buffer.getDocument(), fDestination.getJavaProject().getOptions(true)); if (getDestinationCu().isWorkingCopy()) result.setSaveMode(TextFileChange.LEAVE_DIRTY); TextChangeCompatibility.addTextEdit(result, ReorgMessages.PasteAction_edit_name, rootEdit); } finally { RefactoringFileBuffers.release(getDestinationCu()); } return result; }
Example #27
Source File: AbstractDeleteChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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(); }
Example #28
Source File: RefactoringFileBuffers.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * 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); }
Example #29
Source File: RefactoringFileBuffers.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * 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); }
Example #30
Source File: AbstractDeleteChange.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
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(); }