當前位置: 首頁>>代碼示例>>Java>>正文


Java ICompilationUnit.getBuffer方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.ICompilationUnit.getBuffer方法的典型用法代碼示例。如果您正苦於以下問題:Java ICompilationUnit.getBuffer方法的具體用法?Java ICompilationUnit.getBuffer怎麽用?Java ICompilationUnit.getBuffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.ICompilationUnit的用法示例。


在下文中一共展示了ICompilationUnit.getBuffer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: moveBack

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
private static int moveBack(int offset, int start, String ignoreCharacters, ICompilationUnit cu) {
	try {
		IBuffer buf = cu.getBuffer();
		while (offset >= start) {
			if (ignoreCharacters.indexOf(buf.getChar(offset - 1)) == -1) {
				return offset;
			}
			offset--;
		}
	} catch (JavaModelException e) {
		// use start
	}
	return start;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:15,代碼來源:QuickFixProcessor.java

示例2: analyzeCompilationUnit

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
private void analyzeCompilationUnit(CompilationUnit unit, ICompilationUnit compilationUnit) throws IOException {

		IBuffer buffer = null;
		try {
			buffer = compilationUnit.getBuffer();
		}
		catch (JavaModelException e) {
			e.printStackTrace();
		}
		if (buffer == null) {
			return;
		}
		
		LocationVariableVisitor visitor = new LocationVariableVisitor();
		unit.accept(visitor);

		List types = unit.types();
		for (Iterator iter = types.iterator(); iter.hasNext();) {

			Object next = iter.next();
			if (next instanceof TypeDeclaration) {
				// declaration: Contains one file content at a time.
				TypeDeclaration declaration = (TypeDeclaration) next;
				traverseType(declaration);
			}
		}
	}
 
開發者ID:aroog,項目名稱:code,代碼行數:28,代碼來源:AnnotatMetrics.java

示例3: computeContentAssist

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
private List<CompletionItem> computeContentAssist(ICompilationUnit unit, int line, int column, IProgressMonitor monitor) throws JavaModelException {
	CompletionResponses.clear();
	if (unit == null) {
		return Collections.emptyList();
	}
	List<CompletionItem> proposals = new ArrayList<>();

	final int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), line, column);
	CompletionProposalRequestor collector = new CompletionProposalRequestor(unit, offset);
	// Allow completions for unresolved types - since 3.3
	collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_REF, true);
	collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
	collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.FIELD_IMPORT, true);

	collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.TYPE_REF, true);
	collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.TYPE_IMPORT, true);
	collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.METHOD_IMPORT, true);

	collector.setAllowsRequiredProposals(CompletionProposal.CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true);

	collector.setAllowsRequiredProposals(CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true);
	collector.setAllowsRequiredProposals(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, CompletionProposal.TYPE_REF, true);

	collector.setAllowsRequiredProposals(CompletionProposal.TYPE_REF, CompletionProposal.TYPE_REF, true);

	if (offset >-1 && !monitor.isCanceled()) {
		IBuffer buffer = unit.getBuffer();
		if (buffer != null && buffer.getLength() >= offset) {
			IProgressMonitor subMonitor = new ProgressMonitorWrapper(monitor) {
				private long timeLimit;
				private static final long TIMEOUT = 5000;

				@Override
				public void beginTask(String name, int totalWork) {
					timeLimit = System.currentTimeMillis() + TIMEOUT;
				}

				@Override
				public boolean isCanceled() {
					return super.isCanceled() || timeLimit <= System.currentTimeMillis();
				}

			};
			try {
				unit.codeComplete(offset, collector, subMonitor);
				proposals.addAll(collector.getCompletionItems());
			} catch (OperationCanceledException e) {
				monitor.setCanceled(true);
			}
		}
	}
	return proposals;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:54,代碼來源:CompletionHandler.java


注:本文中的org.eclipse.jdt.core.ICompilationUnit.getBuffer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。