Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
 
 package org.eclipse.xtext.ui.resource;
 
import  org.eclipse.core.resources.IProject;
import  org.eclipse.core.resources.IWorkspace;
Utility to extract the project context for the given resource. By default it will succeed for resource with platform:/resource URIs.

Author(s):
Sebastian Zarnekow - Initial contribution and API
Since:
2.8
public class ProjectByResourceProvider {
	private IWorkspace workspace;

Return the project context for the given resource.
	public IProject getProjectContext(Resource resource) {
		if (resource.getURI().isPlatformResource()) {
			String projectName = URI.decode(resource.getURI().segment(1));
			IProject project = .getRoot().getProject(projectName);
			if (project.exists() && project.isAccessible()) {
				return project;
		}
		return null;
	}
	protected IWorkspace getWorkspace() {
		return ;
	}
New to GrepCode? Check out our FAQ X