Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2013 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.editor.findrefs;
import static*;
import  org.eclipse.core.resources.IProject;
import  org.eclipse.core.resources.IStorage;
import  org.eclipse.jdt.core.IJavaProject;

Sven Efftinge - Initial contribution and API
	private Map<IProject,ResourceSetresourceSets = newHashMap();
	public void registerResourceSet(ResourceSet resourceSet) {
		if (resourceSet instanceof XtextResourceSet) {
			Object context = ((XtextResourceSetresourceSet).getClasspathURIContext();
			if (context instanceof IJavaProject) {
				IProject project = ((IJavaProject) context).getProject();
		this. = resourceSet;
	public <R> R readOnly(URI targetURIIUnitOfWork<R, ResourceSetwork) {
		URI resourceURI = targetURI.trimFragment();
		Iterable<Pair<IStorage, IProject>> storages = .getStorages(resourceURI);
		Iterator<Pair<IStorage, IProject>> iterator = storages.iterator();
		ResourceSet resourceSet = 
		while(iterator.hasNext()) {
			Pair<IStorage, IProject> pair =;
			IProject project = pair.getSecond();
			if (project != null) {
				resourceSet = getResourceSet(project);
		if(resourceSet != null) {
			try {
				return work.exec(resourceSet);
catch (Exception e) {
				throw new WrappedException(e);
		return null;
	protected ResourceSet getResourceSet(IProject p) {
		// if the initially registered resource set wasn'T configured with a java project, we aways use the same resourceSet (old behavior)
		if (.isEmpty() &&  != null) {
		if (.containsKey(p)) {
			return .get(p);
		ResourceSet resourceSet = .get(p);
		if (resourceSet == null)
			return null;
		return resourceSet;
New to GrepCode? Check out our FAQ X