本文整理汇总了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;
}
示例2: getSourceReference
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
@Override
protected ISourceReference getSourceReference(IPackageFragment pkg,
String sourcename) throws CoreException {
return pkg.getCompilationUnit(sourcename);
}