本文整理汇总了Java中org.eclipse.core.filebuffers.ITextFileBufferManager.connect方法的典型用法代码示例。如果您正苦于以下问题:Java ITextFileBufferManager.connect方法的具体用法?Java ITextFileBufferManager.connect怎么用?Java ITextFileBufferManager.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.core.filebuffers.ITextFileBufferManager
的用法示例。
在下文中一共展示了ITextFileBufferManager.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import org.eclipse.core.filebuffers.ITextFileBufferManager; //导入方法依赖的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.ITextFileBufferManager; //导入方法依赖的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: toDocument
import org.eclipse.core.filebuffers.ITextFileBufferManager; //导入方法依赖的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;
}
示例4: getDocument
import org.eclipse.core.filebuffers.ITextFileBufferManager; //导入方法依赖的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());
}
}
}
示例5: processJavaSource
import org.eclipse.core.filebuffers.ITextFileBufferManager; //导入方法依赖的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);
}
}
示例6: getIFileContent
import org.eclipse.core.filebuffers.ITextFileBufferManager; //导入方法依赖的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;
}
示例7: acquireDocument
import org.eclipse.core.filebuffers.ITextFileBufferManager; //导入方法依赖的package包/类
/**
* Acquires a document from the file buffer manager.
*
* @param monitor the progress monitor to use
* @return the document
* @throws CoreException if the document could not successfully be acquired
*/
private IDocument acquireDocument(final IProgressMonitor monitor) throws CoreException {
if (fCount > 0) return fBuffer.getDocument();
final ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
final IPath path = fFile.getFullPath();
manager.connect(path, LocationKind.IFILE, monitor);
fCount++;
fBuffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
final IDocument document = fBuffer.getDocument();
fContentStamp = ContentStamps.get(fFile, document);
return document;
}
示例8: getTextEdit
import org.eclipse.core.filebuffers.ITextFileBufferManager; //导入方法依赖的package包/类
private TextEdit getTextEdit() throws CoreException {
IDocument document= null;
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
IPath path= fCU.getPath();
if (manager != null && path != null) {
manager.connect(path, LocationKind.NORMALIZE, null);
try {
ITextFileBuffer buffer= manager.getTextFileBuffer(path, LocationKind.NORMALIZE);
if (buffer != null)
document= buffer.getDocument();
} finally {
manager.disconnect(path, LocationKind.NORMALIZE, null);
}
}
if (document == null)
document= new Document(fCU.getSource());
return fASTRewrite.rewriteAST(document, fCU.getJavaProject().getOptions(true));
}
示例9: getDocumentStamp
import org.eclipse.core.filebuffers.ITextFileBufferManager; //导入方法依赖的package包/类
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();
}
}
示例10: initialize
import org.eclipse.core.filebuffers.ITextFileBufferManager; //导入方法依赖的package包/类
private void initialize() {
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
try {
if (fFileStore != null) {
manager.connectFileStore(fFileStore, new NullProgressMonitor());
fTextFileBuffer= manager.getFileStoreTextFileBuffer(fFileStore);
} else {
manager.connect(fPath, fLocationKind, new NullProgressMonitor());
fTextFileBuffer= manager.getTextFileBuffer(fPath, fLocationKind);
}
fDocument= fTextFileBuffer.getDocument();
} catch (CoreException x) {
fDocument= manager.createEmptyDocument(fPath, fLocationKind);
if (fDocument instanceof ISynchronizable)
((ISynchronizable)fDocument).setLockObject(new Object());
}
fDocument.addDocumentListener(this);
fIsClosed= false;
}
示例11: getIFileContent
import org.eclipse.core.filebuffers.ITextFileBufferManager; //导入方法依赖的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;
}
示例12: getFileContent
import org.eclipse.core.filebuffers.ITextFileBufferManager; //导入方法依赖的package包/类
/**
* 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;
}
示例13: applyCodeCoverageMarker
import org.eclipse.core.filebuffers.ITextFileBufferManager; //导入方法依赖的package包/类
/**
* For each uncovered line in the resource, find the start and end of the line
* and annotate it as not covered.
*/
private void applyCodeCoverageMarker(IResource resource, List<Integer> uncoveredLines) throws CoreException, BadLocationException {
IFile iFile = (IFile) resource;
ITextFileBufferManager iTextFileBufferManager = FileBuffers.getTextFileBufferManager();
iTextFileBufferManager.connect(iFile.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
ITextFileBuffer iTextFileBuffer = iTextFileBufferManager.getTextFileBuffer(iFile.getFullPath(), LocationKind.IFILE);
IDocument iDoc = iTextFileBuffer.getDocument();
iTextFileBufferManager.disconnect(iFile.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
for (Integer uncoveredLine : uncoveredLines) {
int start = iDoc.getLineOffset(uncoveredLine - 1);
int end = iDoc.getLineLength(uncoveredLine - 1);
MarkerUtils.getInstance().applyCodeCoverageWarningMarker(resource, uncoveredLine, start, start + end, Messages.View_LineNotCovered);
}
}
示例14: DocumentAdapter
import org.eclipse.core.filebuffers.ITextFileBufferManager; //导入方法依赖的package包/类
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: getDocument
import org.eclipse.core.filebuffers.ITextFileBufferManager; //导入方法依赖的package包/类
/**
* @param resourcePath The {@link IPath} to the {@link IResource} for which an {@link IDocument} should be received
* @param locKind The {@link LocationKind} of the {@link IPath}
* @return The corresponding {@link IDocument} or null
* @throws CoreException If the resource could not successfully be received
*/
private IDocument getDocument(final IPath resourcePath, final LocationKind locKind) throws CoreException {
// connect the buffer manager to the given resource
// the buffermanager takes care of cleanup/disconnecting
final ITextFileBufferManager bufferManager = ITextFileBufferManager.DEFAULT;
bufferManager.connect(resourcePath, locKind, new NullProgressMonitor());
// get the text file buf from the manager and receive the document
final ITextFileBuffer itfb = bufferManager.getTextFileBuffer(resourcePath, locKind);
return itfb.getDocument();
}