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

The following are Jave code examples for showing how to use accept() of the org.eclipse.core.resources.IResource class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: eclipse-plugin-commander   File: EclipseWorkbench.java   View Source Code Vote up 6 votes
public static List<ResourceItem> collectAllWorkspaceFiles(IWorkspaceRoot workspace) {
	List<ResourceItem> files = new ArrayList<>();
	
	IResourceProxyVisitor visitor = new IResourceProxyVisitor() {
		public boolean visit(IResourceProxy proxy) throws CoreException {
			if (proxy.getType() != IResource.FILE) return true;
			if (proxy.isDerived()) return false;
			if (proxy.isPhantom()) return false;
			if (proxy.isHidden()) return false;
			IFile file = (IFile) proxy.requestResource();
			files.add(makeResourceItem(file));
			return false;
		}
	};
	
	try {
		IResource[] resources = workspace.members();
		for(IResource resource : resources) {
			if (!resource.getProject().isOpen()) continue;
			resource.accept(visitor, 0);
		}
	} catch (CoreException e) {
		throw new RuntimeException(e);
	}
	return files;
}
 
Example 2
Project: gemoc-studio   File: SelectPluginIProjectWithFileExtensionDialog.java   View Source Code Vote up 6 votes
@Override
protected boolean select(IResource resource) {
	boolean result = super.select(resource);
	if(resource instanceof IProject){
		boolean hasFileWithExtension = false;
		
		try {
			resource.accept(projectVisitor);
			hasFileWithExtension = projectVisitor.getFile() != null;
		} catch (CoreException e) {
			Activator.error(e.getMessage(), e);
		}
		result = result && hasFileWithExtension;
	}
	return result;
}
 
Example 3
Project: n4js   File: ExternalFolder.java   View Source Code Vote up 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 4
Project: n4js   File: ExternalProject.java   View Source Code Vote up 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 5
Project: gw4e.project   File: JDTManager.java   View Source Code Vote up 5 votes
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);
}
 
Example 6
Project: gw4e.project   File: JDTManager.java   View Source Code Vote up 5 votes
/**
 * @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;
}
 
Example 7
Project: gemoc-studio   File: SelectSpecificFileDialog.java   View Source Code Vote up 5 votes
@Override
protected boolean select(IResource resource) {
	boolean result = super.select(resource);
	if(resource instanceof IFile) {			
		FileFinderVisitor finder = instanciateFinder();
		try {
			resource.accept(finder);
			result = finder.getFile() != null;				
		} catch (CoreException e) {
			Activator.error(e.getMessage(), e);
		}	
	} 
	return result;
}
 
Example 8
Project: gw4e.project   File: GraphWalkerContextManager.java   View Source Code Vote up 4 votes
/**
 * @param selectedResource
 * @return
 * @throws CoreException
 * @throws InterruptedException
 */
public static void synchronizeBuildPolicies(final IResource selectedResource, IWorkbenchWindow aww)
		throws CoreException, InterruptedException {
	List<ICompilationUnit> executionContexts = new ArrayList<ICompilationUnit>();

	Job job = new WorkspaceJob("GW4E Synchronization Job") {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			try {
				SubMonitor subMonitor = SubMonitor.convert(monitor, 120);
				selectedResource.accept(new IResourceVisitor() {
					@Override
					public boolean visit(IResource resource) throws CoreException {
						if (resource instanceof IFile) {
							IFile file = (IFile) resource;
							if ("java".equals(file.getFileExtension())) {
								ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file);
								if (cu != null) {
									if (JDTManager.isGraphWalkerExecutionContextClass(cu)) {
										executionContexts.add(cu);
									}
								}
							}
						}
						return true;
					}
				});
				subMonitor.split(20);

				int max = executionContexts.size();
				int index = 1;
				subMonitor.setWorkRemaining(max);
				for (ICompilationUnit executionContext : executionContexts) {
					if (monitor.isCanceled())
						return Status.CANCEL_STATUS;
					subMonitor.subTask("Processing file #" + index++);
					SubMonitor child = subMonitor.split(1);
					ResourceManager.updateBuildPolicyFileForCompilatioUnit(executionContext);
				}
			} catch (Exception e) {
				ResourceManager.logException(e);
			}
			return Status.OK_STATUS;
		}
	};
	job.setRule(selectedResource.getProject());
	job.setUser(true);
	job.schedule();
}