Java Code Examples for org.eclipse.core.resources.IResource#accept()

The following examples show how to use org.eclipse.core.resources.IResource#accept() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@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 2
public IFile[] process() {
	fFiles= new ArrayList<>();
	try {
		IResource[] roots= fScope.getRoots();
		for (IResource resource : roots) {
			try {
				if (resource.isAccessible()) {
					resource.accept(this, 0);
				}
			} catch (CoreException ex) {
				// report and ignore
				fStatus.add(ex.getStatus());
			}
		}
		return fFiles.toArray(new IFile[fFiles.size()]);
	} finally {
		fFiles= null;
	}
}
 
Example 3
/**
 * 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 4
Source Project: cppcheclipse   File: Builder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param resource
 * @param monitor
 *            , new monitor, not yet initialized with beginTask
 * @throws CoreException
 */
public void processResource(IResource resource, IProgressMonitor monitor)
		throws CoreException {
	IProject project = resource.getProject();
	if (project == null)
		return;

	// open project if necessary
	if (!project.isOpen()) {
		project.open(new NullProgressMonitor());
	}
	// first count all relevant resources including and below resource
	ResourceVisitorCounter visitorCounter = new ResourceVisitorCounter();
	resource.accept(visitorCounter);

	// setup monitor (this is a subProgressMonitor, therefore text not
	// visible)
	monitor.beginTask(Messages.bind(Messages.Builder_ResouceVisitorTask,
			resource.getName()), visitorCounter.getCount());
	ResourceVisitor resorceVisitor = new ResourceVisitor(monitor);
	resource.accept(resorceVisitor);

	// run checker (a last time)
	resorceVisitor.runChecker();
	monitor.done();
}
 
Example 5
Source Project: n4js   File: ExternalFolder.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@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 6
Source Project: n4js   File: ExternalProject.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@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 7
public void testGetAllJavaPackagesReturnsPackageWhenItsThere() throws Exception {
  IPackageFragmentRoot[] roots = new IPackageFragmentRoot[1];
  IPackageFragmentRoot root = control.createMock(IPackageFragmentRoot.class);
  IResource resource = control.createMock(IResource.class);
  expect(resource.getFullPath()).andReturn(new Path("SomePath"));
  resource.accept(EasyMock.isA(JavaPackageVisitor.class), EasyMock.anyInt());
  
  expect(root.isArchive()).andReturn(false);
  expect(root.getCorrespondingResource()).andReturn(resource);
  roots[0] = root;
  expect(javaProject.getPackageFragmentRoots()).andReturn(roots);
  control.replay();
  javaProjectHelper.getAllJavaPackages(javaProject);
  control.verify();
}
 
Example 8
public List<String> getAllJavaPackages(IJavaProject javaProject) throws JavaModelException,
    CoreException {
  List<String> allJavaPackages = new ArrayList<String>();
  IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
  for (IPackageFragmentRoot root : roots) {
    if (!root.isArchive()) {
      IResource rootResource = root.getCorrespondingResource();
      String rootURL = rootResource.getFullPath().toOSString();
      rootResource.accept(new JavaPackageVisitor(allJavaPackages, rootURL), IContainer.NONE);
    }
  }
  return allJavaPackages;
}
 
Example 9
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 10
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 11
protected synchronized void buildChildren(final IResource root, Predicate<IResource> resourceFilter) {
    if (children == null) {
        makeChildrenContainer();
        try {
            root.accept(new IResourceVisitor() {
                @Override
                public boolean visit(IResource resource) throws CoreException {
                    if (root == resource) return true;
                    
                    // skip resources if they are inside specified skip folders
                    for (String relativeFolderPath : getRelativeFolderPathesToSkip()) {
                        if (ResourceUtils.isInsideFolder(relativeFolderPath, resource)) {
                            return false;
                        }
                    }
                    
                    if (!resourceFilter.test(resource)) {
                    	return false;
                    }
                    
                    if (resource instanceof IContainer) {
                        XdsFolderContainer container = new XdsFolderContainer(getXdsProject(), resource, XdsFolderContainer.this);
                        addChild(container);
                    }
                    else if (XdsFileUtils.isCompilationUnitFile(resource.getFullPath().lastSegment())) {
                    	IXdsWorkspaceCompilationUnit xdsCompilationUnit = new XdsWorkspaceCompilationUnit(getXdsProject(), resource, XdsFolderContainer.this);
                        addChild(xdsCompilationUnit);
                    }
                    else if (XdsFileUtils.isSymbolFile(resource.getFullPath().lastSegment())) {
                        IXdsSymbolFile xdsSymFile = new XdsSymbolFile(getXdsProject(), resource, XdsFolderContainer.this);
                        addChild(xdsSymFile);
                    }
                    else if (XdsFileUtils.isXdsProjectFile(resource.getFullPath()
                            .lastSegment())) {
                        addChild(new XdsProjectDescriptor(getXdsProject(), resource, XdsFolderContainer.this));
                    }
                    else if (XdsFileUtils.isDbgScriptFile(resource.getFullPath().lastSegment())) {
                        addChild(new XdsDdgScriptUnitFile(getXdsProject(), resource, XdsFolderContainer.this));
                    }
                    else if (XdsFileUtils.isDbgScriptBundleFile(resource.getFullPath().lastSegment())) {
                    	addChild(new XdsDbgScriptBundleFile(getXdsProject(), resource, XdsFolderContainer.this));
                    }
                    else {
                    	String fileName = FilenameUtils.getName(ResourceUtils.getAbsolutePath(resource));
                    	if (!SpecialFileNames.getSpecialFileNames().contains(fileName)) {
                    		addChild(new XdsTextFile(getXdsProject(), resource, XdsFolderContainer.this));
                    	}
                    }
                    return true;
                }
            }, IResource.DEPTH_ONE, true);
        } catch (CoreException e) {
            LogHelper.logError(e);
        }
    }
}
 
Example 12
Source Project: birt   File: NewLibraryWizard.java    License: Eclipse Public License 1.0 4 votes vote down vote up
private boolean validDuplicate( String prefix, String ext, int count,
		IResource res )
{
	if ( res != null && res.isAccessible( ) )
	{
		final String name;
		if ( count == 0 )
		{
			name = prefix + ext;
		}
		else
		{
			name = prefix + "_" + count + ext; //$NON-NLS-1$
		}

		try
		{
			tmpList.clear( );

			res.accept( new IResourceVisitor( ) {

				public boolean visit( IResource resource )
						throws CoreException
				{
					if ( resource.getType( ) == IResource.FILE )
					{
						if ( !Platform.getOS( ).equals( Platform.OS_WIN32 ) )
						{
							if ( name.equals( ( (IFile) resource ).getName( ) ) )
							{
								tmpList.add( Boolean.TRUE );
							}
						}
						else if(name.equalsIgnoreCase( ( (IFile) resource ).getName( ) )){
							tmpList.add( Boolean.TRUE );
						}
					}

					return true;
				}
			},
					IResource.DEPTH_INFINITE,
					true );

			if ( tmpList.size( ) > 0 )
			{
				return false;
			}
		}
		catch ( CoreException e )
		{
			ExceptionUtil.handle( e );
		}
	}

	return true;
}
 
Example 13
Source Project: birt   File: NewReportWizard.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Judge whether the name new report has been used
 * 
 * @param prefix
 * @param ext
 * @param count
 * @param res
 * @return
 */
boolean validDuplicate( String prefix, String ext, int count, IResource res )
{
	if ( res != null && res.isAccessible( ) )
	{
		final String name;
		if ( count == 0 )
		{
			name = prefix + ext;
		}
		else
		{
			name = prefix + "_" + count + ext; //$NON-NLS-1$
		}

		try
		{
			tmpList.clear( );

			res.accept( new IResourceVisitor( ) {

				public boolean visit( IResource resource )
						throws CoreException
				{
					if ( resource.getType( ) == IResource.FILE )
					{
						if ( !Platform.getOS( ).equals( Platform.OS_WIN32 ) )
						{
							if ( name.equals( ( (IFile) resource ).getName( ) ) )
							{
								tmpList.add( Boolean.TRUE );
							}
						}
						else if ( name.equalsIgnoreCase( ( (IFile) resource ).getName( ) ) )
						{
							tmpList.add( Boolean.TRUE );
						}
					}

					return true;
				}
			},
					IResource.DEPTH_INFINITE,
					true );

			if ( tmpList.size( ) > 0 )
			{
				return false;
			}
		}
		catch ( CoreException e )
		{
			ExceptionUtil.handle( e );
		}
	}

	return true;
}