本文整理汇总了Java中org.eclipse.jdt.core.IPackageFragmentRoot.getChildren方法的典型用法代码示例。如果您正苦于以下问题:Java IPackageFragmentRoot.getChildren方法的具体用法?Java IPackageFragmentRoot.getChildren怎么用?Java IPackageFragmentRoot.getChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IPackageFragmentRoot
的用法示例。
在下文中一共展示了IPackageFragmentRoot.getChildren方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultPackage
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
public String getDefaultPackage() {
WPILibJavaPlugin.logInfo("Project: "+project);
String defaultPackage = null;
if (project != null) {
try {
IPackageFragmentRoot root = JavaCore.create(project)
.getPackageFragmentRoot(project.getFolder("src"));
String backupPackage = "";
for (IJavaElement child : root.getChildren()) {
if (child.getElementType()==IJavaElement.PACKAGE_FRAGMENT
&& child.getElementName().endsWith("."+ending)) {
defaultPackage = child.getElementName();
}
backupPackage = child.getElementName();
}
if (defaultPackage == null) defaultPackage = backupPackage;
} catch (JavaModelException e) {
WPILibJavaPlugin.logError("Error getting default package.", e);
}
}
if (defaultPackage != null) return defaultPackage;
else return "";
}
示例2: populatePackageNameFromSelectedJar
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
/**
* Populate packages for selected jar file
*
*/
public void populatePackageNameFromSelectedJar() {
sourcePackageList.removeAll();
IPackageFragmentRoot iPackageFragmentRoot = (IPackageFragmentRoot) comboJarList.getData(String
.valueOf(comboJarList.getSelectionIndex()));
if (iPackageFragmentRoot != null) {
try {
for (IJavaElement iJavaElement : iPackageFragmentRoot.getChildren()) {
if (iJavaElement instanceof IPackageFragment) {
IPackageFragment packageFragment = (IPackageFragment) iJavaElement;
if (packageFragment.containsJavaResources()) {
if(!isAlreadyPresentInTargetList(packageFragment.getElementName()))
sourcePackageList.add(packageFragment.getElementName());
}
}
}
} catch (JavaModelException javaModelException) {
LOGGER.warn("Error occurred while fetching packages from "
+ iPackageFragmentRoot.getElementName());
}
}
if(comboJarList.getSelectionIndex() ==0){
deleteButton.setEnabled(false);
}else{
deleteButton.setEnabled(true);
}
enableOrDisableAddLabelsOnComboSelection();
}
示例3: choosePackage
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
protected IPackageFragment choosePackage() {
IPackageFragmentRoot froot = getPackageFragmentRoot();
IJavaElement[] packages = null;
try {
if (froot != null && froot.exists()) {
packages = froot.getChildren();
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
if (packages == null) {
packages = new IJavaElement[0];
}
ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new JavaElementLabelProvider(
JavaElementLabelProvider.SHOW_DEFAULT));
dialog.setIgnoreCase(false);
dialog.setTitle(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_title);
dialog.setMessage(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_description);
dialog.setEmptyListMessage(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_empty);
dialog.setElements(packages);
dialog.setHelpAvailable(false);
if (dialog.open() == Window.OK) {
return (IPackageFragment) dialog.getFirstResult();
}
return null;
}
示例4: collectCompilationUnits
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
private void collectCompilationUnits(IPackageFragmentRoot root, Collection<IJavaElement> result, String prefix) throws JavaModelException {
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
IJavaElement[] children = root.getChildren();
for (int i = 0; i < children.length; i++) {
IPackageFragment pack = (IPackageFragment) children[i];
if (StringUtils.isBlank(prefix) || pack.getElementName().indexOf(prefix) >= 0) {
collectCompilationUnits(pack, result);
}
}
}
}
示例5: isJavaFilePresent
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
/**
* Checks that the Java file for the given class name exists in the project.
*
* @param project
* the project, must not be {@code null}
* @param className
* the class name, must not be {@code null}
* @return whether the corresponding java file exists in the project
*/
public boolean isJavaFilePresent(final IProject project, final String className) {
int packageSplitIndex = className.lastIndexOf('.');
if (packageSplitIndex == -1) {
throw new IllegalArgumentException(String.format("%s is a simple class name or not a class name at all.", className));
}
int fileNameEndIndex = className.indexOf('$');
if (fileNameEndIndex == -1) {
fileNameEndIndex = className.length();
}
String packageName = className.substring(0, packageSplitIndex);
String fileName = className.substring(packageSplitIndex + 1, fileNameEndIndex) + ".java";
try {
if (project.hasNature(JavaCore.NATURE_ID)) {
for (IPackageFragmentRoot root : JavaCore.create(project).getAllPackageFragmentRoots()) {
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
for (IJavaElement element : root.getChildren()) {
if (element instanceof IPackageFragment && packageName.equals(element.getElementName())
&& ((IPackageFragment) element).getCompilationUnit(fileName).exists()) {
return true;
}
}
}
}
}
} catch (CoreException e) {
LOGGER.error(String.format("Failed to read project %s.", project.getName()), e);
}
return false;
}