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


Java IPackageFragment.getCompilationUnit方法代码示例

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


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

示例1: internalGetContentReader

import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
/**
 * Gets a reader for an package fragment's Javadoc comment content from the source attachment.
 * The content does contain only the text from the comment without the Javadoc leading star characters.
 * Returns <code>null</code> if the package fragment does not contain a Javadoc comment or if no source is available.
 * @param fragment The package fragment to get the Javadoc of.
 * @return Returns a reader for the Javadoc comment content or <code>null</code> if the member
 * does not contain a Javadoc comment or if no source is available
 * @throws JavaModelException is thrown when the package fragment's javadoc can not be accessed
 * @since 3.4
 */
private static Reader internalGetContentReader(IPackageFragment fragment) throws JavaModelException {
	IPackageFragmentRoot root= (IPackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);

	//1==> Handle the case when the documentation is present in package-info.java or package-info.class file
	boolean isBinary= root.getKind() == IPackageFragmentRoot.K_BINARY;
	ITypeRoot packageInfo;
	if (isBinary) {
		packageInfo= fragment.getClassFile(PACKAGE_INFO_CLASS);
	} else {
		packageInfo= fragment.getCompilationUnit(PACKAGE_INFO_JAVA);
	}
	if (packageInfo != null && packageInfo.exists()) {
		String source = packageInfo.getSource();
		//the source can be null for some of the class files
		if (source != null) {
			Javadoc javadocNode = getPackageJavadocNode(fragment, source);
			if (javadocNode != null) {
				int start = javadocNode.getStartPosition();
				int length = javadocNode.getLength();
				return new JavaDocCommentReader(source, start, start + length - 1);
			}
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:36,代码来源:JavadocContentAccess.java

示例2: getSourceReference

import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
@Override
protected ISourceReference getSourceReference(IPackageFragment pkg,
    String sourcename) throws CoreException {
  return pkg.getCompilationUnit(sourcename);
}
 
开发者ID:eclipse,项目名称:eclemma,代码行数:6,代码来源:SessionExporter.java


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