本文整理汇总了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()));
}