本文整理汇总了Java中org.eclipse.core.filebuffers.FileBuffers类的典型用法代码示例。如果您正苦于以下问题:Java FileBuffers类的具体用法?Java FileBuffers怎么用?Java FileBuffers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileBuffers类属于org.eclipse.core.filebuffers包,在下文中一共展示了FileBuffers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
/**
* Save the AST int he Compilation Unit
*
* @param testInterface
* @param rewrite
* @throws CoreException
*/
public static void save(CompilationUnit unit, ASTRewrite rewrite) throws CoreException {
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
IPath path = unit.getJavaElement().getPath();
try {
bufferManager.connect(path, null);
ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path);
IDocument document = textFileBuffer.getDocument();
TextEdit edit = rewrite.rewriteAST(document, null);
edit.apply(document);
textFileBuffer.commit(null /* ProgressMonitor */, true /* Overwrite */);
} catch (Exception e) {
ResourceManager.logException(e);
} finally {
// disconnect the path
bufferManager.disconnect(path, null);
}
}
示例2: updateMarker
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
private void updateMarker(IResource resource, String message, int start, int end, int severity,
IMarker marker) {
try {
marker.setAttribute(IMarker.MESSAGE, message);
marker.setAttribute(IMarker.SEVERITY, severity);
if (resource.getType() != IResource.FILE) {
return;
}
IFile file = (IFile) resource;
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer textFileBuffer = manager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
if (textFileBuffer == null) {
manager.connect(file.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
textFileBuffer = manager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
}
IDocument document = textFileBuffer.getDocument();
marker.setAttribute(IMarker.CHAR_START, start);
marker.setAttribute(IMarker.CHAR_END, end);
marker.setAttribute(IMarker.LINE_NUMBER, document.getLineOfOffset(start) + 1);
} catch (CoreException | BadLocationException e) {
e.printStackTrace();
}
}
示例3: getExistingMarkerFor
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
private IMarker getExistingMarkerFor(IResource resource, String message, int start, int end,
Set<IMarker> remainingMarkers) {
ITextFileBuffer textFileBuffer = FileBuffers.getTextFileBufferManager()
.getTextFileBuffer(resource.getFullPath(), LocationKind.IFILE);
if (textFileBuffer == null) {
return null;
}
try {
for (IMarker marker : remainingMarkers) {
int startOffset = MarkerUtilities.getCharStart(marker);
int endOffset = MarkerUtilities.getCharEnd(marker);
if (MarkerUtils.getOptionType(marker) == null && message.equals(MarkerUtilities.getMessage(marker))) {
if (start <= startOffset && end >= endOffset) {
return marker;
}
}
}
} catch (CoreException e) {
e.printStackTrace();
}
return null;
}
示例4: close
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
@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;
}
}
示例5: setContents
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
@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);
}
}
示例6: toDocument
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
/**
* 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;
}
示例7: getDocument
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
public static IDocument getDocument(IPath fileSystemPath) throws CoreException {
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
boolean connected = false;
try {
ITextFileBuffer buffer = manager.getTextFileBuffer(fileSystemPath, LocationKind.NORMALIZE);
if (buffer == null) {
// no existing file buffer..create one
manager.connect(fileSystemPath, LocationKind.NORMALIZE, new NullProgressMonitor());
connected = true;
buffer = manager.getTextFileBuffer(fileSystemPath, LocationKind.NORMALIZE);
if (buffer == null) {
return null;
}
}
return buffer.getDocument();
} finally {
if (connected) {
manager.disconnect(fileSystemPath, LocationKind.NORMALIZE, new NullProgressMonitor());
}
}
}
示例8: getPosition
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
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;
}
示例9: processJavaSource
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
private void processJavaSource(ICompilationUnit unit) throws Exception {
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
IPath path = unit.getPath();
try {
bufferManager.connect(path, null);
ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path);
IDocument doc = textFileBuffer.getDocument();
if ((license !=null) && (license.length() > 0)) {
processHeadLicense(doc);
}
if ((license_inline != null) && (license_inline.length() > 0)) {
processInlineLicense(doc);
}
textFileBuffer.commit(null, false);
} finally {
bufferManager.disconnect(path, null);
}
}
示例10: handleEvent
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
public void handleEvent(ProjectItemModifiedEvent event) {
final String eventPath = event.getPath();
if (!isJavaProject(event.getProject())) {
return;
}
try {
JavaModelManager.getJavaModelManager()
.deltaState
.resourceChanged(new ResourceChangedEvent(workspace, event));
} catch (Throwable t) {
// catch all exceptions that may be happened
LOG.error("Can't update java model in " + eventPath, t);
}
if (event.getType() == ProjectItemModifiedEvent.EventType.UPDATED) {
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer fileBuffer =
manager.getTextFileBuffer(new Path(eventPath), LocationKind.IFILE);
if (fileBuffer != null) {
try {
fileBuffer.revert(new NullProgressMonitor());
} catch (CoreException e) {
LOG.error("Can't read file content: " + eventPath, e);
}
}
}
}
示例11: getIndentationLevel
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
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());
}
}
示例12: acceptFile
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
@Override
public boolean acceptFile(IFile file) throws CoreException {
IJavaElement element = JavaCore.create(file);
if ((element != null && element.exists())) return false;
// Only touch text files (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=114153 ):
if (!FileBuffers.getTextFileBufferManager().isTextFileLocation(file.getFullPath(), false))
return false;
IPath path = file.getProjectRelativePath();
String segment = path.segment(0);
if (segment != null
&& (segment.startsWith(".refactorings")
|| segment.startsWith(".deprecations"))) // $NON-NLS-1$
// $NON-NLS-2$
return false;
return true;
}
示例13: getIFileContent
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
/**
* 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;
}
示例14: checkDirtyFile
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
private void checkDirtyFile(RefactoringStatus result, IFile file) {
if (!file.exists()) return;
ITextFileBuffer buffer =
FileBuffers.getTextFileBufferManager()
.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
if (buffer != null && buffer.isDirty()) {
String message = RefactoringCoreMessages.DeleteResourcesProcessor_warning_unsaved_file;
if (buffer.isStateValidated() && buffer.isSynchronized()) {
result.addWarning(
Messages.format(message, BasicElementLabels.getPathLabel(file.getFullPath(), false)));
} else {
result.addFatalError(
Messages.format(message, BasicElementLabels.getPathLabel(file.getFullPath(), false)));
}
}
}
示例15: isValid
import org.eclipse.core.filebuffers.FileBuffers; //导入依赖的package包/类
/** {@inheritDoc} */
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
if (pm == null) pm = new NullProgressMonitor();
pm.beginTask("", 1); // $NON-NLS-1$
try {
if (fValidationState == null)
throw new CoreException(
new Status(
IStatus.ERROR,
RefactoringCorePlugin.getPluginId(),
"MultiStateUndoChange has not been initialialized")); // $NON-NLS-1$
ITextFileBuffer buffer =
FileBuffers.getTextFileBufferManager()
.getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
fDirty = buffer != null && buffer.isDirty();
return fValidationState.isValid(needsSaving(), true);
} finally {
pm.done();
}
}