Java Code Examples for org.eclipse.jdt.core.IPackageFragment#hasSubpackages()
The following examples show how to use
org.eclipse.jdt.core.IPackageFragment#hasSubpackages() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaDeleteProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public boolean hasSubPackagesToDelete() { try { for (int i= 0; i < fJavaElements.length; i++) { if (fJavaElements[i] instanceof IPackageFragment) { IPackageFragment packageFragment= (IPackageFragment) fJavaElements[i]; if (packageFragment.isDefaultPackage()) continue; // see bug 132576 (can remove this if(..) continue; statement when bug is fixed) if (packageFragment.hasSubpackages()) return true; } } } catch (JavaModelException e) { JavaPlugin.log(e); } return false; }
Example 2
Source File: NonEssentialElementsFilter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public boolean select(Viewer viewer, Object parent, Object element) { if (!isStateModelInitialized) { initStateModel(viewer); } if (fContentService == null || fStateModel == null) { return true; } else if (element instanceof IPackageFragment) { if (isApplicable() && viewer instanceof StructuredViewer) { boolean isHierarchicalLayout= !fStateModel.getBooleanProperty(IExtensionStateConstants.Values.IS_LAYOUT_FLAT); try { IPackageFragment fragment = (IPackageFragment) element; if (isHierarchicalLayout && !fragment.isDefaultPackage() && fragment.hasSubpackages()) { return hasFilteredChildren((StructuredViewer) viewer, fragment); } } catch (JavaModelException e) { return false; } } } return doSelect(viewer, parent, element); }
Example 3
Source File: PackagesViewTreeViewer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private boolean isEssential(Object object) { try { if (object instanceof IPackageFragment) { IPackageFragment fragment = (IPackageFragment) object; if (!fragment.isDefaultPackage() && fragment.hasSubpackages()) { return hasFilteredChildren(fragment); } } else if (object instanceof LogicalPackage) { LogicalPackage logicalPackage= (LogicalPackage) object; if (!logicalPackage.isDefaultPackage() && logicalPackage.hasSubpackages()) { return !hasFilteredChildren(object); } } } catch (JavaModelException e) { JavaPlugin.log(e); } return false; }
Example 4
Source File: RenameModifications.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public void rename(IPackageFragment rootPackage, RenameArguments args, boolean renameSubPackages) throws CoreException { add(rootPackage, args, null); IPackageFragment[] allSubPackages= null; if (renameSubPackages) { allSubPackages= getSubpackages(rootPackage); for (int i= 0; i < allSubPackages.length; i++) { IPackageFragment pack= allSubPackages[i]; RenameArguments subArgs= new RenameArguments( getNewPackageName(rootPackage, args.getNewName(), pack.getElementName()), args.getUpdateReferences()); add(pack, subArgs, null); } } IContainer container= (IContainer)rootPackage.getResource(); if (container == null) { return; } IContainer target= (IContainer) ((IPackageFragmentRoot)rootPackage.getParent()). getPackageFragment(args.getNewName()).getResource(); if ((!rootPackage.hasSubpackages() || renameSubPackages) && canMove(container, target)) { createIncludingParents(target.getParent()); if (container.getParent().equals(target.getParent())) { getResourceModifications().addRename(container, new RenameArguments(target.getName(), args.getUpdateReferences())); } else { // This is a little tricky. The problem is that the refactoring participants // don't support a generic move like the resource API does. So for the delta // we generate one move, however for the participants we have to generate single // moves and deletes. try { getResourceModifications().ignoreForDelta(); addAllResourceModifications(rootPackage, args, renameSubPackages, allSubPackages); } finally { getResourceModifications().trackForDelta(); } getResourceModifications().addDelta(new ResourceModifications.MoveDescription(container, target.getFullPath())); } } else { addAllResourceModifications(rootPackage, args, renameSubPackages, allSubPackages); } }
Example 5
Source File: RenameModifications.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void rename(IPackageFragment rootPackage, RenameArguments args, boolean renameSubPackages) throws CoreException { add(rootPackage, args, null); IPackageFragment[] allSubPackages= null; if (renameSubPackages) { allSubPackages= getSubpackages(rootPackage); for (int i= 0; i < allSubPackages.length; i++) { IPackageFragment pack= allSubPackages[i]; RenameArguments subArgs= new RenameArguments( getNewPackageName(rootPackage, args.getNewName(), pack.getElementName()), args.getUpdateReferences()); add(pack, subArgs, null); } } IContainer container= (IContainer)rootPackage.getResource(); if (container == null) return; IContainer target= (IContainer) ((IPackageFragmentRoot)rootPackage.getParent()). getPackageFragment(args.getNewName()).getResource(); if ((!rootPackage.hasSubpackages() || renameSubPackages) && canMove(container, target)) { createIncludingParents(target.getParent()); if (container.getParent().equals(target.getParent())) { getResourceModifications().addRename(container, new RenameArguments(target.getName(), args.getUpdateReferences())); } else { // This is a little tricky. The problem is that the refactoring participants // don't support a generic move like the resource API does. So for the delta // we generate one move, however for the participants we have to generate single // moves and deletes. try { getResourceModifications().ignoreForDelta(); addAllResourceModifications(rootPackage, args, renameSubPackages, allSubPackages); } finally { getResourceModifications().trackForDelta(); } getResourceModifications().addDelta(new ResourceModifications.MoveDescription(container, target.getFullPath())); } } else { addAllResourceModifications(rootPackage, args, renameSubPackages, allSubPackages); } }
Example 6
Source File: StandardJavaElementContentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Tests if the given element is a empty package fragment. * * @param element the element to test * @return returns <code>true</code> if the package fragment is empty * @throws JavaModelException thrown if accessing the element failed */ protected boolean isPackageFragmentEmpty(IJavaElement element) throws JavaModelException { if (element instanceof IPackageFragment) { IPackageFragment fragment= (IPackageFragment)element; if (fragment.exists() && !(fragment.hasChildren() || fragment.getNonJavaResources().length > 0) && fragment.hasSubpackages()) return true; } return false; }
Example 7
Source File: NewTypeWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Checks if the package field has to be pre-filled in this page and returns the package * fragment to be used for that. The package fragment has the name of the project if the source * folder does not contain any package and if the project name is a valid package name. If the * source folder contains exactly one package then the name of that package is used as the * package fragment's name. <code>null</code> is returned if none of the above is applicable. * * @param javaProject the containing Java project of the selection used to initialize this page * * @return the package fragment to be pre-filled in this page or <code>null</code> if no * suitable package can be suggested for the given project * * @since 3.9 */ private IPackageFragment getPackage(IJavaProject javaProject) { String packName= null; final IPackageFragmentRoot pkgFragmentRoot= getPackageFragmentRoot(); IJavaElement[] packages= null; try { if (pkgFragmentRoot != null && pkgFragmentRoot.exists()) { packages= pkgFragmentRoot.getChildren(); if (packages.length == 1) { // only default package -> use Project name packName= javaProject.getElementName(); // validate package name IStatus status= validatePackageName(packName, javaProject); if (status.getSeverity() == IStatus.OK) { return pkgFragmentRoot.getPackageFragment(packName); } } else { int noOfPackages= 0; IPackageFragment thePackage= null; for (final IJavaElement pack : packages) { IPackageFragment pkg= (IPackageFragment) pack; // ignoring empty parent packages and default package if ((!pkg.hasSubpackages() || pkg.hasChildren()) && !pkg.isDefaultPackage()) { noOfPackages++; thePackage= pkg; if (noOfPackages > 1) { return null; } } } if (noOfPackages == 1) { // use package name packName= thePackage.getElementName(); return pkgFragmentRoot.getPackageFragment(packName); } } } } catch (JavaModelException e) { // fall through } return null; }
Example 8
Source File: PackageExplorerPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean isEssential(Object object) { try { if (!isFlatLayout() && object instanceof IPackageFragment) { IPackageFragment fragment = (IPackageFragment) object; if (!fragment.isDefaultPackage() && fragment.hasSubpackages()) { return hasFilteredChildren(fragment); } } } catch (JavaModelException e) { JavaPlugin.log(e); } return false; }
Example 9
Source File: EmptyInnerPackageFilter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean select(Viewer viewer, Object parent, Object element) { if (element instanceof IPackageFragment) { IPackageFragment pkg= (IPackageFragment)element; try { if (pkg.isDefaultPackage()) return pkg.hasChildren(); return !pkg.hasSubpackages() || pkg.hasChildren() || EmptyPackageFilter.hasUnfilteredResources(viewer, pkg); } catch (JavaModelException e) { return false; } } return true; }
Example 10
Source File: LogicalPackage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public boolean hasSubpackages() throws JavaModelException { for (Iterator<IPackageFragment> iter= fPackages.iterator(); iter.hasNext();) { IPackageFragment pack= iter.next(); if (pack.hasSubpackages()) { return true; } } return false; }
Example 11
Source File: BonitaProjectExplorer.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private boolean isEssential(Object object) { try { if (object instanceof IPackageFragment) { IPackageFragment fragment = (IPackageFragment) object; if (!fragment.isDefaultPackage() && fragment.hasSubpackages()) { return hasFilteredChildren(fragment); } } } catch (JavaModelException e) { JavaPlugin.log(e); } return false; }
Example 12
Source File: NewPackageWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Validates the package name and returns the status of the validation. * * @param packName the package name * * @return the status of the validation */ private IStatus getPackageStatus(String packName) { StatusInfo status= new StatusInfo(); if (packName.length() > 0) { IStatus val= validatePackageName(packName); if (val.getSeverity() == IStatus.ERROR) { status.setError(Messages.format(NewWizardMessages.NewPackageWizardPage_error_InvalidPackageName, val.getMessage())); return status; } else if (val.getSeverity() == IStatus.WARNING) { status.setWarning(Messages.format(NewWizardMessages.NewPackageWizardPage_warning_DiscouragedPackageName, val.getMessage())); } } else { status.setError(NewWizardMessages.NewPackageWizardPage_error_EnterName); return status; } IPackageFragmentRoot root= getPackageFragmentRoot(); if (root != null && root.getJavaProject().exists()) { IPackageFragment pack= root.getPackageFragment(packName); try { IPath rootPath= root.getPath(); IPath outputPath= root.getJavaProject().getOutputLocation(); if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) { // if the bin folder is inside of our root, don't allow to name a package // like the bin folder IPath packagePath= pack.getPath(); if (outputPath.isPrefixOf(packagePath)) { status.setError(NewWizardMessages.NewPackageWizardPage_error_IsOutputFolder); return status; } } if (pack.exists()) { // it's ok for the package to exist as long we want to create package level documentation // and the package level documentation doesn't exist if (!isCreatePackageDocumentation() || packageDocumentationAlreadyExists(pack)) { if (pack.containsJavaResources() || !pack.hasSubpackages()) { status.setError(NewWizardMessages.NewPackageWizardPage_error_PackageExists); } else { status.setError(NewWizardMessages.NewPackageWizardPage_error_PackageNotShown); } } } else { IResource resource= pack.getResource(); if (resource != null && !ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) { status.setError(NewWizardMessages.NewPackageWizardPage_error_PackageNameFiltered); return status; } URI location= pack.getResource().getLocationURI(); if (location != null) { IFileStore store= EFS.getStore(location); if (store.fetchInfo().exists()) { status.setError(NewWizardMessages.NewPackageWizardPage_error_PackageExistsDifferentCase); } } } } catch (CoreException e) { JavaPlugin.log(e); } } return status; }