Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 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.refactoring.impl;
 
import static com.google.common.collect.Maps.*;
import static org.eclipse.xtext.util.Strings.*;
import  org.eclipse.core.runtime.IProgressMonitor;
import  org.eclipse.core.runtime.OperationCanceledException;
Renames an element without loosing track of the element and dependent elements.

Author(s):
Jan Koehnlein - Initial contribution and API
public class RenamedElementTracker implements IRenamedElementTracker {
	public Map<URIURIrenameAndTrack(Iterable<URIrenamedElementURIsString newNameResourceSet resourceSetIRenameStrategy renameStrategy, IProgressMonitor monitor) {
		Map<EObjectURIrenamedElement2oldURI = resolveRenamedElements(renamedElementURIsresourceSet);
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		renameStrategy.applyDeclarationChange(newNameresourceSet);
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		Map<URIURIold2newURI = relocateRenamedElements(renamedElement2oldURI);
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		renameStrategy.revertDeclarationChange(resourceSet);
		return old2newURI;
	}
	protected Map<EObjectURIresolveRenamedElements(Iterable<URIrenamedElementURIsResourceSet resourceSet) {
		Map<EObjectURIrenamedElement2oldURI = newHashMap();
		for (URI renamedElementURI : renamedElementURIs) {
			EObject renamedElement = resourceSet.getEObject(renamedElementURItrue);
			if (renamedElement == null)
				throw new RefactoringException("Cannot resolve dependent element " + notNull(renamedElementURI));
			renamedElement2oldURI.put(renamedElementrenamedElementURI);
		}
		return renamedElement2oldURI;
	}
	protected Map<URIURIrelocateRenamedElements(Map<EObjectURIrenamedElement2oldURI) {
		Map<URIURIold2newURI = newHashMap();
		for (Map.Entry<EObjectURIentry : renamedElement2oldURI.entrySet()) {
			URI newURI = EcoreUtil.getURI(entry.getKey());
			old2newURI.put(entry.getValue(), newURI);
		}
		return old2newURI;
	}
New to GrepCode? Check out our FAQ X