當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。