当前位置: 首页>>代码示例>>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;未经允许,请勿转载。