Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2015 itemis AG ( 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 /
 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.

Sebastian Zarnekow - Initial contribution and API
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