org.eclipse.core.resources.IResourceVisitor Java Examples
The following examples show how to use
org.eclipse.core.resources.IResourceVisitor.
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: ResourceUtils.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
/** * Gets all resources (see {@link IResource}) matches specified {@link filter} * * @param project * @param filter - filter to match, if null - matches everything * @return all resources (see {@link IResource}) matches specified filter */ public static <T extends IResource> List<T> getProjectResources(IProject project, final Predicate<IResource> filter) { final List<T> resources = new ArrayList<T>(); try { project.accept(new IResourceVisitor() { @Override @SuppressWarnings("unchecked") public boolean visit(IResource r) throws CoreException { if (filter == null || filter.apply(r)) { resources.add((T)r); } return true; } }); } catch (CoreException e) { LogHelper.logError(e); } return resources; }
Example #2
Source File: CordovaPluginManager.java From thym with Eclipse Public License 1.0 | 6 votes |
private void updatePluginList() throws CoreException { long start = System.currentTimeMillis(); if(installedPlugins == null || installedPlugins.isEmpty()) { HybridCore.trace("Really updating the installed plugin list"); IResourceVisitor visitor = new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { if(resource.getType() == IResource.FOLDER){ IFolder folder = (IFolder) resource.getAdapter(IFolder.class); IFile file = folder.getFile(PlatformConstants.FILE_XML_PLUGIN); if(file.exists()){ addInstalledPlugin(file); } } return resource.getName().equals(PlatformConstants.DIR_PLUGINS); } }; IFolder plugins = this.project.getProject().getFolder(PlatformConstants.DIR_PLUGINS); if(plugins != null && plugins.exists()){ synchronized (installedPlugins) { plugins.accept(visitor,IResource.DEPTH_ONE,false); } } } HybridCore.trace(NLS.bind("Updated plugin list in {0} ms", (System.currentTimeMillis() - start))); }
Example #3
Source File: SVNTeamProvider.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
private void configureTeamPrivateResource(IProject project) { try { project.accept( new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if ((resource.getType() == IResource.FOLDER) && (resource.getName().equals(SVNProviderPlugin.getPlugin().getAdminDirectoryName())) && (!resource.isTeamPrivateMember())) { resource.setTeamPrivateMember(true); return false; } else { return true; } } }, IResource.DEPTH_INFINITE, IContainer.INCLUDE_PHANTOMS | IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS); } catch (CoreException e) { SVNProviderPlugin.log(SVNException.wrapException(e)); } }
Example #4
Source File: FileUtils.java From gama with GNU General Public License v3.0 | 6 votes |
private static IFile findExistingLinkedFile(final IFolder folder, final String name) { final IFile[] result = new IFile[1]; try { folder.accept((IResourceVisitor) resource -> { if (resource.isLinked()) { final String p = resource.getLocation().toString(); if (p.equals(name)) { result[0] = (IFile) resource; return false; } } return true; }, IResource.DEPTH_INFINITE, IResource.FILE); } catch (final CoreException e1) { e1.printStackTrace(); } final IFile file = result[0]; return file; }
Example #5
Source File: ModuleUtils.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Finds all GWT modules located directly in a particular container. * * @param container container to search within * @return the list of modules found */ public static IModule[] findChildModules(IContainer container) { final List<IModule> modules = new ArrayList<IModule>(); IResourceVisitor moduleVisitor = new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { if (resource.getType() == IResource.FILE) { IModule module = create((IFile) resource); if (module != null) { modules.add(module); } } return true; } }; try { container.accept(moduleVisitor, IResource.DEPTH_ONE, false); } catch (CoreException e) { GWTPluginLog.logError(e); } return modules.toArray(new IModule[modules.size()]); }
Example #6
Source File: LegacyGWTLaunchShortcutStrategy.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
private static Set<IFile> findHostPages(IFile moduleFile) { List<IFolder> publicFolders = getModulePublicFolders(moduleFile); if (publicFolders.isEmpty()) { return Collections.emptySet(); } final Set<IFile> hostPages = new HashSet<IFile>(); try { for (IFolder publicFolder : publicFolders) { publicFolder.accept(new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { // Look for any HTML files if (resource.getType() == IResource.FILE && "html".equalsIgnoreCase(resource.getFileExtension())) { hostPages.add((IFile) resource); } return true; } }); } } catch (CoreException e) { CorePluginLog.logError(e); } return hostPages; }
Example #7
Source File: DiagramPartitioningBreadcrumbViewer.java From statecharts with Eclipse Public License 1.0 | 6 votes |
protected Set<IFile> getProjectStatechartInput(Diagram diagram) { final IFile file = WorkspaceSynchronizer.getFile(diagram.eResource()); final IProject project = file.getProject(); final Set<IFile> result = new HashSet<IFile>(); try { project.accept(new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { // TODO check for package explorer filters here if (resource.isHidden()) { return false; } if (resource instanceof IFile) { if (file.getFileExtension().equals(resource.getFileExtension())) result.add((IFile) resource); } return true; } }); } catch (CoreException e) { e.printStackTrace(); } return result; }
Example #8
Source File: NewCheckCatalogWizardPage.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Checks if a given catalog name already exists in the project. * * @param packageFragment * the package in which the file is looked for * @return true, if catalog exists */ private boolean catalogExists(final IResource packageFragment) { final Set<IResource> foundResources = Sets.newHashSet(); final String catalogName = getCatalogName() + '.' + CheckConstants.FILE_EXTENSION; IResourceVisitor catalogNameVisitor = new IResourceVisitor() { public boolean visit(final IResource res) throws CoreException { String resourceName = res.getName(); if (catalogName.equalsIgnoreCase(resourceName)) { foundResources.add(res); } return foundResources.isEmpty(); } }; try { packageFragment.accept(catalogNameVisitor); return !foundResources.isEmpty(); } catch (CoreException e) { // packageFragment does not yet exist. Therefore, the catalog name is unique. return false; } }
Example #9
Source File: DecoratorUtils.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
public static void refreshXdsDecorators(IProject project, String decoratorId){ IDecoratorManager decoratorManager = WorkbenchUtils.getWorkbench().getDecoratorManager(); if (decoratorManager != null && decoratorManager.getEnabled(decoratorId)) { final IXdsDecorator decorator = (IXdsDecorator)decoratorManager.getBaseLabelProvider(decoratorId); if (decorator != null && project.exists()) { try { project.accept(new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { decorator.refresh(new IResource[]{resource}); return true; } }); } catch (CoreException e) { LogHelper.logError(e); } } } }
Example #10
Source File: ResourceUtils.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
/** * Gets resource children * @param f * @param tagClass filter class, subclass of {@link IResource} * @return list of child resources */ public static <T extends IResource, U extends IResource> List<U> getChildren(T f, Class<U> tagClass) { List<U> found = new ArrayList<>(); try { f.accept(new IResourceVisitor() { @SuppressWarnings("unchecked") @Override public boolean visit(IResource r) throws CoreException { if (tagClass.isAssignableFrom(r.getClass())) { found.add((U)r); } return true; } }, IResource.DEPTH_ONE, false); } catch (CoreException e) { LogHelper.logError(e); } return found; }
Example #11
Source File: SymbolModelManager.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
@Override protected void handleProjectRemoved(IResourceDelta delta, IProject affectedProject, boolean isPreDeleteEvent) { try { affectedProject.accept(new IResourceVisitor() { @Override public boolean visit(IResource r) throws CoreException { if (isCompilationUnitFile(r)) { SymbolModelManager.instance().scheduleRemove(Arrays.asList((IFile)r)); } return true; } }); } catch (CoreException e) { LogHelper.logError(e); } super.handleProjectRemoved(delta, affectedProject, isPreDeleteEvent); }
Example #12
Source File: AbstractProjectCreator.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected IFile getModelFile(IProject project) throws CoreException { IFolder srcFolder = project.getFolder(getModelFolderName()); final String expectedExtension = getPrimaryModelFileExtension(); final IFile[] result = new IFile[1]; srcFolder.accept(new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { if (IResource.FILE == resource.getType() && expectedExtension.equals(resource.getFileExtension())) { result[0] = (IFile) resource; return false; } return IResource.FOLDER == resource.getType(); } }); return result[0]; }
Example #13
Source File: Storage2UriMapperImpl.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.4 */ @Override public Map<URI, IStorage> getAllEntries(IContainer container) { final Map<URI,IStorage> result = newLinkedHashMap(); try { container.accept(new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { if (resource instanceof IFile) { final IFile storage = (IFile) resource; URI uri = getUri(storage); if (uri != null) result.put(uri, storage); } if (resource instanceof IFolder) { return isHandled((IFolder)resource); } return true; } }); } catch (CoreException e) { log.error(e.getMessage(), e); } return result; }
Example #14
Source File: EPackageChooser.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected Iterable<IResource> findResourcesContainingGenModels() { final List<IResource> filteredResources = Lists.newArrayList(); try { ResourcesPlugin.getWorkspace().getRoot().accept(new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { if (resource instanceof IFile) { String fileExtension = ((IFile) resource).getFileExtension(); if ("genmodel".equals(fileExtension) || "xcore".equals(fileExtension)) { filteredResources.add(resource); } } if (jdtHelper.isJavaCoreAvailable()) { return !jdtHelper.isFromOutputPath(resource); } return true; } }); } catch (CoreException e) { Logger.getLogger(this.getClass()).error(Messages.EPackageChooser_ErrorFindingGenModels, e); } return filteredResources; }
Example #15
Source File: FacetUtil.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** * Returns a list of WEB-INF folders in {@code container}. */ @VisibleForTesting static List<IFolder> findAllWebInfFolders(IContainer container) { final List<IFolder> webInfFolders = new ArrayList<>(); try { IResourceVisitor webInfCollector = new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { if (resource.getType() == IResource.FOLDER && "WEB-INF".equals(resource.getName())) { webInfFolders.add((IFolder) resource); return false; // No need to visit sub-directories. } return true; } }; container.accept(webInfCollector); } catch (CoreException ex) { // Our attempt to find folders failed, but don't error out. } return webInfFolders; }
Example #16
Source File: ProjectBuilder.java From neoscada with Eclipse Public License 1.0 | 6 votes |
protected void validateAll ( final IProject project, final ComposedAdapterFactory adapterFactory, final Set<String> extensions, final IProgressMonitor monitor ) { logger.debug ( "Validating all resources of {}", project ); try { project.accept ( new IResourceVisitor () { @Override public boolean visit ( final IResource resource ) throws CoreException { return handleResource ( null, resource, adapterFactory, extensions, monitor ); } } ); } catch ( final CoreException e ) { StatusManager.getManager ().handle ( e.getStatus () ); } }
Example #17
Source File: IndexableFilesDiscoveryUtil.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Scans workspace for files that may end up in XtextIndex when given location is processed by the builder. This is * naive filtering based on {@link IndexableFilesDiscoveryUtil#INDEXABLE_FILTERS file extensions}. Symlinks are not * followed. * * @param workspace * to scan * @return collection of indexable locations * @throws CoreException * if scanning of the workspace is not possible. */ public static Collection<String> collectIndexableFiles(IWorkspace workspace) throws CoreException { Set<String> result = new HashSet<>(); workspace.getRoot().accept(new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { if (resource.getType() == IResource.FILE) { IFile file = (IFile) resource; boolean isIndexableFileExtension = false; String extension = file.getFileExtension(); if (extension != null) { isIndexableFileExtension = INDEXABLE_FILTERS.contains(extension.toLowerCase()); } boolean isIndexableFilename = INDEXABLE_FILENAMES.contains(file.getName()); if (isIndexableFileExtension || isIndexableFilename) { result.add(file.getFullPath().toString()); } } return true; } }); return result; }
Example #18
Source File: PackageFilterEditor.java From eclipse-cs with GNU Lesser General Public License v2.1 | 6 votes |
private void setSubElementsGrayedChecked(final IContainer container, final boolean checked) { final List<IContainer> subContainers = new ArrayList<>(); try { container.accept(new IResourceVisitor() { @Override public boolean visit(IResource resource) { if (!resource.equals(container) && resource instanceof IContainer) { subContainers.add((IContainer) resource); } return true; } }); } catch (CoreException e) { CheckstyleUIPlugin.errorDialog(getShell(), e, true); } for (IContainer grayedChild : subContainers) { mViewer.setGrayChecked(grayedChild, checked); } }
Example #19
Source File: PlatformResourceURI.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override public Iterator<PlatformResourceURI> getAllChildren() { IResource container = getCachedResource(); if (container instanceof IContainer) { final List<PlatformResourceURI> result = Lists.newArrayList(); try { container.accept(new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { if (resource.getType() == IResource.FILE) result.add(new PlatformResourceURI(resource)); // do not iterate over contents of nested node_modules folders if (resource.getType() == IResource.FOLDER && resource.getName().equals(N4JSGlobals.NODE_MODULES)) { return false; } return true; } }); return Iterators.unmodifiableIterator(result.iterator()); } catch (CoreException e) { return Iterators.unmodifiableIterator(result.iterator()); } } return Iterators.unmodifiableIterator(Collections.emptyIterator()); }
Example #20
Source File: PyFileListing.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * @return All the IFiles below the current folder that are python files (does not check if it has an __init__ path) */ public static List<IFile> getAllIFilesBelow(IContainer member) { final ArrayList<IFile> ret = new ArrayList<IFile>(); try { member.accept(new IResourceVisitor() { @Override public boolean visit(IResource resource) { if (resource instanceof IFile) { ret.add((IFile) resource); return false; //has no members } return true; } }); } catch (CoreException e) { throw new RuntimeException(e); } return ret; }
Example #21
Source File: ExternalProject.java From n4js with Eclipse Public License 1.0 | 5 votes |
private void acceptUnsafe(IResourceVisitor visitor) { try { accept(visitor); } catch (CoreException e) { throw new RuntimeException("Error while visiting resource." + this, e); } }
Example #22
Source File: Axis2ServiceUtils.java From developer-studio with Apache License 2.0 | 5 votes |
/** * This method provides logic for getting all Axis2 service folders with related project in workspace. * * @return a map contains all service folders with corresponding project * @throws org.wso2.developerstudio.eclipse.utils.exception.Axis2ServiceUtilsException */ public static Map<IFolder, IProject> getServiceFolders() throws Axis2ServiceUtilsException { Map<IFolder, IProject> map = new HashMap<IFolder, IProject>(); for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { if (WebUtils.isDynamicWebProject(project)) { final IFolder servicesFolder; servicesFolder = WebUtils.getAxis2WebContainerWEB_INFServicesFolderPath(project); final List<IFolder> folders = new ArrayList<IFolder>(); try { if (servicesFolder.exists()) { servicesFolder.accept(new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if (resource.getLocation().toOSString() .equals(servicesFolder.getLocation().toOSString())) { return true; } else { if (resource instanceof IFolder) { folders.add((IFolder) resource); } } return false; } }); } } catch (CoreException e) { throw new Axis2ServiceUtilsException("Error in getting service folders for Axis2 projects", e); } for (IFolder folder : folders) { map.put(folder, project); } } } return map; }
Example #23
Source File: JavaDeleteProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void checkDirtyResources(final RefactoringStatus result) throws CoreException { for (int i= 0; i < fResources.length; i++) { IResource resource= fResources[i]; resource.accept(new IResourceVisitor() { public boolean visit(IResource visitedResource) throws CoreException { if (visitedResource instanceof IFile) { checkDirtyFile(result, (IFile)visitedResource); } return true; } }, IResource.DEPTH_INFINITE, false); } }
Example #24
Source File: StatusCacheManager.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
private Set<IResource> resourcesToRefresh(IResource resource, int depth, int flags, int expectedSize) throws CoreException { if (!resource.exists() && !resource.isPhantom()) { return new HashSet<IResource>(0); } final Set<IResource> resultSet = (expectedSize != 0) ? new HashSet<IResource>(expectedSize) : new HashSet<IResource>(); resource.accept(new IResourceVisitor() { public boolean visit(IResource aResource) throws CoreException { resultSet.add(aResource); return true; } }, depth, flags); return resultSet; }
Example #25
Source File: SVNLightweightDecorator.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public void refresh(IProject project) { final List resources = new ArrayList(); try { project.accept(new IResourceVisitor() { public boolean visit(IResource resource) { resources.add(resource); return true; } }); postLabelEvent(new LabelProviderChangedEvent(this, resources.toArray())); } catch (CoreException e) { SVNProviderPlugin.log(e.getStatus()); } }
Example #26
Source File: ExternalFolder.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override public void accept(IResourceVisitor visitor, int depth, int memberFlags) throws CoreException { if (depth == DEPTH_ZERO) { visitor.visit(this); } else { if (visitor.visit(this)) { for (IResource member : members()) { member.accept(visitor, DEPTH_ONE == depth ? DEPTH_ZERO : DEPTH_INFINITE, memberFlags); } } } }
Example #27
Source File: ExternalFolder.java From n4js with Eclipse Public License 1.0 | 5 votes |
private void acceptUnsafe(IResourceVisitor visitor) { try { accept(visitor); } catch (final CoreException e) { throw new RuntimeException("Error while visiting resource." + this, e); } }
Example #28
Source File: DeployJob.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Fetches the check configuration files of this project. * * @return the list of configuration files, never {@code null} * @throws DeployException * deploy exception */ private List<IFile> getCheckConfigurationFiles() throws DeployException { final List<IFile> checkCfgFiles = new ArrayList<IFile>(); try { project.accept(new IResourceVisitor() { @Override public boolean visit(final IResource resource) throws CoreException { if (resource instanceof IProject) { return true; } if (resource instanceof IFile && CheckCfgConstants.FILE_EXTENSION.equalsIgnoreCase(((IFile) resource).getFileExtension())) { checkCfgFiles.add((IFile) resource); return false; } if (isProjectJarIgnoreResource(resource)) { return false; } if (resource instanceof IFolder && "bin".equals(resource.getName())) { return false; } return true; } }); } catch (CoreException e) { LOGGER.error(e.getMessage(), e); throw new DeployException(e); } return checkCfgFiles; }
Example #29
Source File: ToBeBuiltComputer.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Full build was triggered. Update all information that is available for the given project. * All contained resources are processed by {@link #updateStorage(IProgressMonitor, ToBeBuilt, IStorage)}. * * @see #updateStorage(IProgressMonitor, ToBeBuilt, IStorage) * @see #isHandled(IFolder) * @see IToBeBuiltComputerContribution#updateProject(ToBeBuilt, IProject, IProgressMonitor) */ public ToBeBuilt updateProject(IProject project, IProgressMonitor monitor) throws CoreException, OperationCanceledException { final SubMonitor progress = SubMonitor.convert(monitor, Messages.ToBeBuiltComputer_CollectingResources, 10); progress.subTask(Messages.ToBeBuiltComputer_CollectingResources); final ToBeBuilt toBeBuilt = doRemoveProject(project, progress.split(8)); if (!project.isAccessible()) return toBeBuilt; if (progress.isCanceled()) throw new OperationCanceledException(); final SubMonitor childMonitor = progress.split(1); project.accept(new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { if (progress.isCanceled()) throw new OperationCanceledException(); if (resource instanceof IStorage) { return updateStorage(childMonitor, toBeBuilt, (IStorage) resource); } if (resource instanceof IFolder) { return isHandled((IFolder) resource); } return true; } }); if (progress.isCanceled()) throw new OperationCanceledException(); contribution.updateProject(toBeBuilt, project, progress.split(1)); return toBeBuilt; }
Example #30
Source File: ExternalProject.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override public void accept(IResourceVisitor visitor, int depth, int memberFlags) throws CoreException { if (depth == DEPTH_ZERO) { visitor.visit(this); } else { if (visitor.visit(this)) { for (IResource member : members()) { member.accept(visitor, DEPTH_ONE == depth ? DEPTH_ZERO : DEPTH_INFINITE, memberFlags); } } } }