当前位置: 首页>>代码示例>>Java>>正文


Java ITextFileBuffer.getDocument方法代码示例

本文整理汇总了Java中org.eclipse.core.filebuffers.ITextFileBuffer.getDocument方法的典型用法代码示例。如果您正苦于以下问题:Java ITextFileBuffer.getDocument方法的具体用法?Java ITextFileBuffer.getDocument怎么用?Java ITextFileBuffer.getDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.core.filebuffers.ITextFileBuffer的用法示例。


在下文中一共展示了ITextFileBuffer.getDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: save

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的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);
	}
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:26,代码来源:JDTManager.java

示例2: updateMarker

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的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();
	}
}
 
开发者ID:angelozerr,项目名称:ec4e,代码行数:27,代码来源:ValidateEditorConfigStrategy.java

示例3: toDocument

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:31,代码来源:JsonRpcHelpers.java

示例4: getDocument

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的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());
		}
	}
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:22,代码来源:DocumentUtils.java

示例5: processJavaSource

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的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);
	}
}
 
开发者ID:alexgreenbar,项目名称:open_tools,代码行数:19,代码来源:SampleAction.java

示例6: create

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的package包/类
public static BufferValidationState create(IFile file) {
  ITextFileBuffer buffer = getBuffer(file);
  if (buffer == null) {
    return new ModificationStampValidationState(file);
  } else {
    IDocument document = buffer.getDocument();
    if (document instanceof IDocumentExtension4) {
      return new ModificationStampValidationState(file);
    } else {
      if (buffer.isDirty()) {
        return new NoStampValidationState(file);
      } else {
        return new ModificationStampValidationState(file);
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:BufferValidationState.java

示例7: getTextEdit

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的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));
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:AccessorClassModifier.java

示例8: getDocumentStamp

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的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();
 }
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:CleanUpPostSaveListener.java

示例9: applyCodeCoverageMarker

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的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);
}
  }
 
开发者ID:forcedotcom,项目名称:idecore,代码行数:20,代码来源:RunTestsView.java

示例10: getModificationStamp

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的package包/类
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();
        }
    }
}
 
开发者ID:fabioz,项目名称:Pydev,代码行数:18,代码来源:PyChange.java

示例11: getDocument

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的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();
}
 
开发者ID:tlaplus,项目名称:tlaplus,代码行数:17,代码来源:PCalDetectingBuilder.java

示例12: getDocument

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的package包/类
/**
 * 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");
			}
		}
	}
}
 
开发者ID:angelozerr,项目名称:typescript.java,代码行数:35,代码来源:TypeScriptResourceUtil.java

示例13: computeAssistProposals

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Proposals computeAssistProposals(
    IJavaProject project, String fqn, int offset, List<Problem> problems) throws CoreException {
  ICompilationUnit compilationUnit;

  IType type = project.findType(fqn);
  if (type == null) {
    return null;
  }
  if (type.isBinary()) {
    throw new JavaModelException(
        new JavaModelStatus(
            IJavaModelStatusConstants.CORE_EXCEPTION,
            "Can't calculate Quick Assist on binary file"));
  } else {
    compilationUnit = type.getCompilationUnit();
  }

  IBuffer buffer = compilationUnit.getBuffer();

  ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
  bufferManager.connect(compilationUnit.getPath(), LocationKind.IFILE, new NullProgressMonitor());
  ITextFileBuffer textFileBuffer =
      bufferManager.getTextFileBuffer(compilationUnit.getPath(), LocationKind.IFILE);
  IDocument document = textFileBuffer.getDocument();
  TextViewer viewer = new TextViewer(document, new Point(offset, 0));
  AssistContext context = new AssistContext(compilationUnit, offset, 0);
  ArrayList proposals = new ArrayList<>();
  JavaCorrectionProcessor.collectProposals(context, problems, true, true, proposals);
  return convertProposals(offset, compilationUnit, viewer, proposals);
}
 
开发者ID:eclipse,项目名称:che,代码行数:32,代码来源:CodeAssist.java

示例14: getOpenDocument

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的package包/类
private IDocument getOpenDocument(IFile file, Map documentsInEditors) {
  IDocument document = (IDocument) 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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:13,代码来源:TextSearchVisitor.java

示例15: perform

import org.eclipse.core.filebuffers.ITextFileBuffer; //导入方法依赖的package包/类
/** {@inheritDoc} */
public Change perform(IProgressMonitor pm) throws CoreException {
  if (fValidationState == null || fValidationState.isValid(needsSaving(), false).hasFatalError())
    return new NullChange();
  if (pm == null) pm = new NullProgressMonitor();
  ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
  pm.beginTask("", 2); // $NON-NLS-1$
  ITextFileBuffer buffer = null;
  try {
    manager.connect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
    buffer = manager.getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
    IDocument document = buffer.getDocument();
    ContentStamp currentStamp = ContentStamps.get(fFile, document);
    // perform the changes
    LinkedList list = new LinkedList();
    for (int index = 0; index < fUndos.length; index++) {
      UndoEdit edit = fUndos[index];
      UndoEdit redo = edit.apply(document, TextEdit.CREATE_UNDO);
      list.addFirst(redo);
    }

    // try to restore the document content stamp
    boolean success = ContentStamps.set(document, fContentStampToRestore);
    if (needsSaving()) {
      buffer.commit(pm, false);
      if (!success) {
        // We weren't able to restore document stamp.
        // Since we save restore the file stamp instead
        ContentStamps.set(fFile, fContentStampToRestore);
      }
    }
    return createUndoChange((UndoEdit[]) list.toArray(new UndoEdit[list.size()]), currentStamp);
  } catch (BadLocationException e) {
    throw Changes.asCoreException(e);
  } finally {
    if (buffer != null)
      manager.disconnect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:40,代码来源:MultiStateUndoChange.java


注:本文中的org.eclipse.core.filebuffers.ITextFileBuffer.getDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。