本文整理匯總了Java中org.eclipse.jdt.core.ICompilationUnit.getChildren方法的典型用法代碼示例。如果您正苦於以下問題:Java ICompilationUnit.getChildren方法的具體用法?Java ICompilationUnit.getChildren怎麽用?Java ICompilationUnit.getChildren使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.ICompilationUnit
的用法示例。
在下文中一共展示了ICompilationUnit.getChildren方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testResolveStandaloneCompilationUnit
import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
@Test
public void testResolveStandaloneCompilationUnit() throws CoreException {
Path helloSrcRoot = Paths.get("projects", "eclipse", "hello", "src").toAbsolutePath();
URI uri = helloSrcRoot.resolve(Paths.get("java", "Foo.java")).toUri();
ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri.toString());
assertNotNull("Could not find compilation unit for " + uri, cu);
assertEquals(ProjectsManager.DEFAULT_PROJECT_NAME, cu.getResource().getProject().getName());
IJavaElement[] elements = cu.getChildren();
assertEquals(2, elements.length);
assertTrue(IPackageDeclaration.class.isAssignableFrom(elements[0].getClass()));
assertTrue(IType.class.isAssignableFrom(elements[1].getClass()));
assertTrue(cu.getResource().isLinked());
assertEquals(cu.getResource(), JDTUtils.findResource(uri, ResourcesPlugin.getWorkspace().getRoot()::findFilesForLocationURI));
uri = helloSrcRoot.resolve("NoPackage.java").toUri();
cu = JDTUtils.resolveCompilationUnit(uri.toString());
assertNotNull("Could not find compilation unit for " + uri, cu);
assertEquals(ProjectsManager.DEFAULT_PROJECT_NAME, cu.getResource().getProject().getName());
elements = cu.getChildren();
assertEquals(1, elements.length);
assertTrue(IType.class.isAssignableFrom(elements[0].getClass()));
}