Start line:  
End line:  

Snippet Preview

Snippet HTML Code

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

Author(s):
Sven Efftinge - Initial contribution and API
Since:
2.4
	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();
				.put(projectresourceSet);
			}
		}
		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 = iterator.next();
			IProject project = pair.getSecond();
			if (project != null) {
				resourceSet = getResourceSet(project);
				break;
			}
		}
		if(resourceSet != null) {
			resourceSet.getResource(resourceURItrue);
			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;
		.put(presourceSet);
		return resourceSet;
	}
New to GrepCode? Check out our FAQ X