Java 类org.eclipse.core.resources.IResourceVisitor 实例源码

项目:n4js    文件:IndexableFilesDiscoveryUtil.java   
/**
 * 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;
                if (INDEXABLE_FILTERS.contains(file.getFileExtension().toLowerCase())) {
                    result.add(file.getFullPath().toString());
                }
            }
            return true;
        }
    });
    return result;
}
项目:neoscada    文件:ProjectBuilder.java   
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 () );
    }
}
项目:subclipse    文件:SVNTeamProvider.java   
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));
    }
}
项目:google-cloud-eclipse    文件:FacetUtil.java   
/**
 * 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;
}
项目:dsl-devkit    文件:NewCheckCatalogWizardPage.java   
/**
 * 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;
  }
}
项目:bts    文件:Storage2UriMapperImpl.java   
/**
 * @since 2.4
 */
public Map<URI, IStorage> getAllEntries(IContainer container) {
    final Map<URI,IStorage> result = newLinkedHashMap();
    try {
        container.accept(new IResourceVisitor() {
            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;
}
项目:statecharts    文件:WorkspaceTreeContentProvider.java   
public Object[] filterForContent(Object[] inputElements) throws CoreException {
    final Set<Object> result = new LinkedHashSet<Object>();
    for (final Object obj : inputElements) {
        ((IResource) obj).accept(new IResourceVisitor() {
            public boolean visit(IResource resource) throws CoreException {
                // no file extension check
                if (resource instanceof IFile && hasFileExtension((IFile) resource)) {
                    return false;
                }
                // check if file extension is proper
                else if (resource instanceof IFile && resource.getFileExtension().equals(fileExtension)) {
                    result.add(obj);
                    return true;
                } else if (resource instanceof IFolder && containsFile((IFolder) resource)) {
                    result.add(obj);
                    return true;
                }
                return false;
            }
        });
    }
    return result.toArray(new IResource[0]);
}
项目:statecharts    文件:DiagramPartitioningBreadcrumbViewer.java   
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;
}
项目:che    文件:ResourceChangeDescriptionFactory.java   
/**
 * Helper method that generate a move or copy delta for a sub-tree of resources being moved or
 * copied.
 */
private void moveOrCopyDeep(IResource resource, IPath destination, final boolean move) {
  final IPath sourcePrefix = resource.getFullPath();
  final IPath destinationPrefix = destination;
  try {
    // build delta for the entire sub-tree if available
    if (resource.isAccessible()) {
      resource.accept(
          new IResourceVisitor() {
            public boolean visit(IResource child) {
              return moveOrCopy(child, sourcePrefix, destinationPrefix, move);
            }
          });
    } else {
      // just build a delta for the single resource
      moveOrCopy(resource, sourcePrefix, destination, move);
    }
  } catch (CoreException e) {
    fail(e);
  }
}
项目:che    文件:DeleteResourcesProcessor.java   
private void checkDirtyResources(final RefactoringStatus result) throws CoreException {
  for (int i = 0; i < fResources.length; i++) {
    IResource resource = fResources[i];
    if (resource instanceof IProject && !((IProject) resource).isOpen()) continue;
    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);
  }
}
项目:gwt-eclipse-plugin    文件:LegacyGWTLaunchShortcutStrategy.java   
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;
}
项目:gwt-eclipse-plugin    文件:ModuleUtils.java   
/**
 * 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()]);
}
项目:umlet    文件:UmletBuilder.java   
@Override
protected void clean(IProgressMonitor monitor) throws CoreException {

    IProject project = getProject();
    project.accept(new IResourceVisitor() {

        @Override
        public boolean visit(IResource res) throws CoreException {
            if (res instanceof IFile) {
                IFile png = (IFile) res;
                if ("png".equalsIgnoreCase(png.getFileExtension())) {
                    IFile uxf = UmletPluginUtils.getUxfDiagramForImgFile(png);
                    if (uxf.exists()) {
                        // clean only pngs with corresponding umlet diagrams
                        png.delete(true, null);
                    }
                }
            }
            return true;
        }
    });
}
项目:chromedevtools    文件:FileBasedAction.java   
private static <RES> List<RES> readFiles(ResourceMapping resourceMapping,
    final FileFilter<RES> fileFilter) {
  final List<RES> fileList = new ArrayList<RES>(1);
  IResourceVisitor visitor = new IResourceVisitor() {
    public boolean visit(IResource resource) throws CoreException {
      if (resource instanceof IFile == false) {
        return true;
      } else {
        IFile file = (IFile) resource;
        RES res = fileFilter.accept(file);
        if (res != null) {
          fileList.add(res);
        }
        return false;
      }
    }
  };
  try {
    resourceMapping.accept(null, visitor, null);
  } catch (CoreException e) {
    throw new RuntimeException(e);
  }
  return fileList;
}
项目:filesync4eclipse    文件:TestBuilder.java   
private void delete() throws CoreException {
    IResourceVisitor visitor = new IResourceVisitor() {
        public boolean visit(IResource resource) throws CoreException {
            if (resource.getName().startsWith(".")) {
                return false;
            }
            // there is a possibility for bugs if variables file is deleted too
            // then sync breaks ... so this is intensionally
            // disabled to simulate deletion of variables files
            //                if (resource.getName().startsWith(PREFIX_EXCL_FROM_SYNC)) {
            //                    return false;
            //                }
            if (resource.getType() == IResource.FOLDER) {
                resource.delete(true, monitor);
                return false;
            }
            return true;
        }
    };
    srcProj.accept(visitor);
}
项目:APICloud-Studio    文件:SVNTeamProvider.java   
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));
    }
}
项目:mondo-hawk    文件:Workspace.java   
private Set<IFile> getAllFiles() {
    try {
        final Set<IFile> allFiles = new HashSet<>();
        ResourcesPlugin.getWorkspace().getRoot().accept(new IResourceVisitor() {
            @Override
            public boolean visit(IResource resource) throws CoreException {
                if (resource instanceof IFile) {
                    allFiles.add((IFile) resource);
                }
                return true;
            }

        });
        return allFiles;
    } catch (CoreException e) {
        console.printerrln(e);
        return Collections.emptySet();
    }
}
项目:OpenSPIFe    文件:EPlanUtils.java   
public static IFile getPlanFile(IProject project) {
    final List<IFile> planFiles = new ArrayList<IFile>();
    try {
        project.accept(new IResourceVisitor() {
            @Override
            public boolean visit(IResource resource) {
                if (resource instanceof IFile 
                        && CommonUtils.equals("plan", resource.getFileExtension())
                        && !CommonUtils.equals("template.plan", resource.getName())) {
                    planFiles.add((IFile) resource);
                }
                return true;
            }
        });
    } catch (CoreException e) {
        LogUtil.error(e);
    }
    if (planFiles.isEmpty()) {
        LogUtil.warn("Didn't fine any .plan files in project " + project.getName());
        return null;
    } else if (planFiles.size() > 1) {
        LogUtil.warn("Found more than one .plan file in project " + project.getName());
    } 
    return planFiles.get(0);
}
项目:thym    文件:CordovaPluginManager.java   
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)));
}
项目:AutoDeriv    文件:TreeRule.java   
@Override
public void applyOnProject(final IProgressMonitor progress) {
    // initialization
    if(!checkIni()) return;

    // effective action
    try {
        member.accept(new IResourceVisitor() {
            @Override
            public boolean visit(IResource res) throws CoreException {
                Tools.checkedSetDerived(res, isDerived, progress);
                return true;
            }
        });
    } catch (CoreException e) { e.printStackTrace(); }
}
项目:Pydev    文件:PyFileListing.java   
/**
 * @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;
}
项目:bento    文件:FindFileDialog.java   
@Override
public int open() {
    final ArrayList<IResource> resources = new ArrayList<IResource>();

    try {
        ResourcesPlugin.getWorkspace().getRoot().accept(new IResourceVisitor() {
            @Override
            public boolean visit(IResource resource) throws CoreException {
                // if ( resource instanceof IFile && ((IFile) resource).
                if ( resource.getLocation() != null && resource.getLocation().getFileExtension() != null && 
                     resource.getLocation().getFileExtension().equals( extension ) ) {
                    resources.add(resource);
                }
                return true;
            }
        });
    } catch (CoreException e1) {
        e1.printStackTrace();
    }

    this.setElements(resources.toArray());

    return super.open();
}
项目:q7.quality.mockups    文件:LockResourcesPart.java   
protected void lockResources() {
    if (files.size() == 0) {
        try {
            ResourcesPlugin.getWorkspace().getRoot()
                    .accept(new IResourceVisitor() {

                        public boolean visit(IResource resource)
                                throws CoreException {
                            if (resource.isAccessible()
                                    && resource.getType() == IResource.FILE) {
                                files.put((IFile) resource,
                                        ((IFile) resource).getContents());
                            }
                            return resource.isAccessible();
                        }
                    });
        } catch (CoreException e) {
            e.printStackTrace();
        }
        if (files.size() > 0) {
            value.setValue("Locked:" + files.size());
        }
    }
}
项目:GrayTin    文件:DownloadSdkBundlesJob.java   
private void cleanUpFolder(final IProgressMonitor monitor) throws CoreException {
    monitor.subTask("Deleting existing files.");
    // delete all files in the target folder

    sdkBundlesFolder.accept(new IResourceVisitor() {

        @Override
        public boolean visit(IResource resource) {
            if (resource instanceof IFile) {
                deleteFile((IFile) resource, monitor);
            }
            return true;
        }
    }, IResource.DEPTH_ONE, false);
    monitor.worked(1);
}
项目:byteman-editor    文件:BytemanEditorPluginBuilder.java   
protected void fullBuild(IProgressMonitor monitor) {
    class FullBuildVisitor implements IResourceVisitor {

        @Override
        public boolean visit(IResource resource) throws CoreException {
            buildRuleFile(resource);
            return true;
        }
    }

    try {
        getProject().accept(new FullBuildVisitor());
    } catch (CoreException e) {
        BytemanEditorPlugin.logException(e);
    }
}
项目:byteman-editor    文件:BytemanEditorPluginBuilder.java   
protected void cleanBuild(IProgressMonitor monitor) {
    class CleanBuildVisitor implements IResourceVisitor {
        @Override
        public boolean visit(IResource resource) throws CoreException {
            if(resource instanceof IFile && resource.getName().endsWith(".btm")) {
                BytemanRuleValidator.deleteMarker(resource);
            }
            return true;
        }
    }
    try {
        getProject().accept(new CleanBuildVisitor());
    } catch (CoreException e) {
        BytemanEditorPlugin.logException(e);
    }
}
项目:n4js    文件:ExternalFolder.java   
@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);
            }
        }
    }
}
项目:n4js    文件:ExternalFolder.java   
private void acceptUnsafe(IResourceVisitor visitor) {
    try {
        accept(visitor);
    } catch (final CoreException e) {
        throw new RuntimeException("Error while visiting resource." + this, e);
    }
}
项目:n4js    文件:ExternalProject.java   
@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);
            }
        }
    }
}
项目:n4js    文件:ExternalProject.java   
private void acceptUnsafe(IResourceVisitor visitor) {
    try {
        accept(visitor);
    } catch (CoreException e) {
        throw new RuntimeException("Error while visiting resource." + this, e);
    }
}
项目:n4js    文件:EclipseBasedN4JSWorkspace.java   
@Override
public UnmodifiableIterator<URI> getFolderIterator(URI folderLocation) {
    final IContainer container;
    if (DIRECT_RESOURCE_IN_PROJECT_SEGMENTCOUNT == folderLocation.segmentCount()) {
        container = workspace.getProject(folderLocation.lastSegment());
    } else {
        container = workspace.getFolder(new Path(folderLocation.toPlatformString(true)));
    }
    if (container != null && container.exists()) {
        final List<URI> result = Lists.newLinkedList();
        try {
            container.accept(new IResourceVisitor() {
                @Override
                public boolean visit(IResource resource) throws CoreException {
                    if (resource.getType() == IResource.FILE) {
                        result.add(URI.createPlatformResourceURI(resource.getFullPath().toString(), true));
                    }
                    return true;
                }
            });
            return Iterators.unmodifiableIterator(result.iterator());
        } catch (CoreException e) {
            return Iterators.unmodifiableIterator(result.iterator());
        }
    }
    return Iterators.emptyIterator();
}
项目:gw4e.project    文件:JDTManager.java   
public static IPath guessPackageRootFragment(IProject project, boolean main)
        throws CoreException, FileNotFoundException {
    IPath folder = project.getFullPath()
            .append(GraphWalkerContextManager.getTargetFolderForTestInterface(project.getName(), main));

    IResource interfaceFolder = ResourceManager.toResource(folder);
    List<IPath> paths = new ArrayList<IPath>();
    if (interfaceFolder != null) {
        interfaceFolder.accept(new IResourceVisitor() {
            @Override
            public boolean visit(IResource resource) throws CoreException {
                IJavaElement element = JavaCore.create(resource);
                if (element != null && element instanceof ICompilationUnit) {
                    try {
                        ICompilationUnit cu = (ICompilationUnit) element;
                        CompilationUnit ast = parse(cu);
                        ast.accept(new ASTVisitor() {
                            public boolean visit(PackageDeclaration node) {
                                PackageDeclaration decl = (PackageDeclaration) node;
                                String pkgname = decl.getName().getFullyQualifiedName();
                                int sizePath = pkgname.split("\\.").length;
                                paths.add(resource.getParent().getFullPath().removeLastSegments(sizePath));
                                return false;
                            }
                        });
                    } catch (Exception e) {
                        ResourceManager.logException(e);
                    }
                }
                return true;
            }
        });
    }
    if (paths.size() == 0)
        return null;
    return paths.get(0);
}
项目:gw4e.project    文件:JDTManager.java   
/**
 * @param project
 * @return
 * @throws CoreException
 * @throws FileNotFoundException
 */
public static ICompilationUnit[] getExistingGeneratedTestInterfaces(IProject project, boolean main)
        throws CoreException, FileNotFoundException {
    IPath folder = project.getFullPath()
            .append(GraphWalkerContextManager.getTargetFolderForTestInterface(project.getName(), main));
    List<ICompilationUnit> units = new ArrayList<ICompilationUnit>();
    IResource interfaceFolder = ResourceManager.toResource(folder);
    if (interfaceFolder != null) {
        interfaceFolder.accept(new IResourceVisitor() {
            @Override
            public boolean visit(IResource resource) throws CoreException {
                IJavaElement element = JavaCore.create(resource);
                if (element != null && element instanceof ICompilationUnit) {
                    try {
                        ICompilationUnit cu = (ICompilationUnit) element;
                        IType interf = cu.findPrimaryType();
                        if (interf != null && interf.isInterface()) {
                            units.add(cu);
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                return true;
            }
        });
    }
    ICompilationUnit[] ret = new ICompilationUnit[units.size()];
    units.toArray(ret);
    return ret;
}
项目:gw4e.project    文件:ResourceManagerTest.java   
@Test
public void testCreateFileDeleteIfExistsStringStringStringIProgressMonitor() throws Exception {
    IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true, true);
    IFile impl = (IFile) ResourceManager
            .getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());
    int[] count = new int[1];

    count[0] = 0;
    IResourceVisitor visitor = new IResourceVisitor() {
        @Override
        public boolean visit(IResource resource) throws CoreException {
            if (resource.getFileExtension() != null && resource.getFileExtension().equalsIgnoreCase("java")) {
                count[0] = count[0] + 1;
            }
            return true;
        }
    };
    impl.getParent().accept(visitor);
    assertTrue(count[0] == 1);

    ResourceManager.createFileDeleteIfExists(impl.getParent().getFullPath().toString(), "SimpleImpl.java", "",
            new NullProgressMonitor());
    String s = IOHelper.getContent(impl);
    assertTrue(s.length() == 0);

    count[0] = 0;
    impl.getParent().accept(visitor);
    assertTrue(count[0] == 2);
}
项目:visuflow-plugin    文件:Visuflow.java   
@Override
public void start(BundleContext context) {

    Visuflow.context = context;
    plugin = this;
    logger = new Logger(getLog());
    logger.info("Visuflow plug-in starting...");
    JimpleBreakpointManager.getInstance();

    // iterate over all projects in the workspace to find projects with the
    // visuflow nature. for these projects we trigger a full build to fill
    // the data model directly after the launch. there is also the ProjectListener,
    // which triggers a build for newly opened projects (e.g. opening a closed one or
    // importing a project etc.)
    // the builds are only executed, if the workspace is set to auto build
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    workspace.addResourceChangeListener(projectListener, IResourceChangeEvent.POST_CHANGE);
    if(workspace.isAutoBuilding()) {
        IWorkspaceRoot root = workspace.getRoot();
        try {
            root.accept(new IResourceVisitor() {
                @Override
                public boolean visit(IResource resource) throws CoreException {
                    if(resource.getType() == IResource.PROJECT) {
                        IProject project = (IProject) resource;
                        projectListener.triggerBuild(project);
                        return false;
                    }
                    return true;
                }
            });
        } catch (CoreException e) {
            logger.error("Error while trying to build visuflow projects", e);
        }
    }
}
项目:subclipse    文件:StatusCacheManager.java   
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;
  }
项目:subclipse    文件:SVNLightweightDecorator.java   
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());
    }
}
项目:dsl-devkit    文件:DeployJob.java   
/**
 * 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.equals(((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;
}
项目:bts    文件:AbstractProjectCreator.java   
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() {
        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];
}
项目:che    文件:Resource.java   
@Override
public void accept(final IResourceVisitor visitor, int depth, int memberFlags)
    throws CoreException {
  // use the fast visitor if visiting to infinite depth
  if (depth == IResource.DEPTH_INFINITE) {
    accept(
        new IResourceProxyVisitor() {
          public boolean visit(IResourceProxy proxy) throws CoreException {
            return visitor.visit(proxy.requestResource());
          }
        },
        memberFlags);
    return;
  }
  // it is invalid to call accept on a phantom when INCLUDE_PHANTOMS is not specified
  final boolean includePhantoms = (memberFlags & IContainer.INCLUDE_PHANTOMS) != 0;
  ResourceInfo info = getResourceInfo(includePhantoms, false);
  int flags = getFlags(info);
  if ((memberFlags & IContainer.DO_NOT_CHECK_EXISTENCE) == 0) checkAccessible(flags);

  // check that this resource matches the member flags
  if (!isMember(flags, memberFlags)) return;
  // visit this resource
  if (!visitor.visit(this) || depth == DEPTH_ZERO) return;
  // get the info again because it might have been changed by the visitor
  info = getResourceInfo(includePhantoms, false);
  if (info == null) return;
  // thread safety: (cache the type to avoid changes -- we might not be inside an operation)
  int type = info.getType();
  if (type == FILE) return;
  // if we had a gender change we need to fix up the resource before asking for its members
  IContainer resource =
      getType() != type
          ? (IContainer) workspace.newResource(getFullPath(), type)
          : (IContainer) this;
  IResource[] members = resource.members(memberFlags);
  for (int i = 0; i < members.length; i++)
    members[i].accept(visitor, DEPTH_ZERO, memberFlags | IContainer.DO_NOT_CHECK_EXISTENCE);
}