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


Java CompilationUnit.getTypeRoot方法代碼示例

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


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

示例1: getNodeSource

import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
/**
 * Returns the source of the given node from the location where it was parsed.
 * @param node the node to get the source from
 * @param extendedRange if set, the extended ranges of the nodes should ne used
 * @param removeIndent if set, the indentation is removed.
 * @return return the source for the given node or null if accessing the source failed.
 */
public static String getNodeSource(ASTNode node, boolean extendedRange, boolean removeIndent) {
	ASTNode root= node.getRoot();
	if (root instanceof CompilationUnit) {
		CompilationUnit astRoot= (CompilationUnit) root;
		ITypeRoot typeRoot= astRoot.getTypeRoot();
		try {
			if (typeRoot != null && typeRoot.getBuffer() != null) {
				IBuffer buffer= typeRoot.getBuffer();
				int offset= extendedRange ? astRoot.getExtendedStartPosition(node) : node.getStartPosition();
				int length= extendedRange ? astRoot.getExtendedLength(node) : node.getLength();
				String str= buffer.getText(offset, length);
				if (removeIndent) {
					IJavaProject project= typeRoot.getJavaProject();
					int indent= getIndentUsed(buffer, node.getStartPosition(), project);
					str= Strings.changeIndent(str, indent, project, new String(), typeRoot.findRecommendedLineSeparator());
				}
				return str;
			}
		} catch (JavaModelException e) {
			// ignore
		}
	}
	return null;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:32,代碼來源:ASTNodes.java

示例2: processJavadocComments

import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
private static boolean processJavadocComments(CompilationUnit astRoot) {
	// don't visit Javadoc for 'package-info' (bug 216432)
	if (astRoot != null && astRoot.getTypeRoot() != null) {
		return !JavaModelUtil.PACKAGE_INFO_JAVA.equals(astRoot.getTypeRoot().getElementName());
	}
	return true;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:8,代碼來源:ImportReferencesCollector.java

示例3: performValidation

import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
private IStatus performValidation(IProgressMonitor monitor) throws JavaModelException {
	long start = System.currentTimeMillis();

	List<ICompilationUnit> cusToReconcile = new ArrayList<>();
	synchronized (toReconcile) {
		cusToReconcile.addAll(toReconcile);
		toReconcile.clear();
	}
	if (cusToReconcile.isEmpty()) {
		return Status.OK_STATUS;
	}
	// first reconcile all units with content changes
	SubMonitor progress = SubMonitor.convert(monitor, cusToReconcile.size() + 1);
	for (ICompilationUnit cu : cusToReconcile) {
		cu.reconcile(ICompilationUnit.NO_AST, true, null, progress.newChild(1));
	}
	this.sharedASTProvider.invalidateAll();
	List<ICompilationUnit> toValidate = Arrays.asList(JavaCore.getWorkingCopies(null));
	List<CompilationUnit> astRoots = this.sharedASTProvider.getASTs(toValidate, monitor);
	for (CompilationUnit astRoot : astRoots) {
		// report errors, even if there are no problems in the file: The client need to know that they got fixed.
		ICompilationUnit unit = (ICompilationUnit) astRoot.getTypeRoot();
		DiagnosticsHandler handler = new DiagnosticsHandler(connection, unit);
		handler.beginReporting();
		for (IProblem problem : astRoot.getProblems()) {
			handler.acceptProblem(problem);
		}
		handler.endReporting();
	}
	JavaLanguageServerPlugin.logInfo("Reconciled " + toReconcile.size() + ", validated: " + toValidate.size() + ". Took " + (System.currentTimeMillis() - start) + " ms");
	return Status.OK_STATUS;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:33,代碼來源:DocumentLifeCycleHandler.java

示例4: setAST

import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
public void setAST(CompilationUnit astRoot) {
	ITypeRoot typeRoot = astRoot.getTypeRoot();
	if (shouldCache(typeRoot)) {
		cache.put(typeRoot.getHandleIdentifier(), astRoot);
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:7,代碼來源:SharedASTProvider.java

示例5: ExtractMethodRefactoring

import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
/**
 * Creates a new extract method refactoring
 *
 * @param astRoot
 *            the AST root of an AST created from a compilation unit
 * @param selectionStart
 *            start
 * @param selectionLength
 *            length
 */
public ExtractMethodRefactoring(CompilationUnit astRoot, int selectionStart, int selectionLength) {
	this((ICompilationUnit) astRoot.getTypeRoot(), selectionStart, selectionLength);
	fRoot = astRoot;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:15,代碼來源:ExtractMethodRefactoring.java


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